aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2006-09-26 02:33:00 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-26 11:49:05 -0400
commit91b165c0594ab78c64f26d26e3174e6dfd60ed9d (patch)
tree0730eefa9d4ce786f7f561e3b40700418d6d0970
parent13c06be399902c9ebda08e092edb1614bb4a3761 (diff)
[PATCH] uml: Use ARRAY_SIZE more assiduously
There were a bunch of missed ARRAY_SIZE opportunities. Also, some formatting fixes in the affected areas of code. Signed-off-by: Jeff Dike <jdike@addtoit.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--arch/um/drivers/chan_kern.c2
-rw-r--r--arch/um/drivers/mconsole_kern.c2
-rw-r--r--arch/um/drivers/mconsole_user.c7
-rw-r--r--arch/um/drivers/pcap_kern.c2
-rw-r--r--arch/um/kernel/mem.c3
-rw-r--r--arch/um/kernel/reboot.c13
-rw-r--r--arch/um/kernel/tlb.c5
-rw-r--r--arch/um/os-Linux/mem.c6
-rw-r--r--arch/um/sys-i386/bugs.c9
-rw-r--r--arch/um/sys-i386/ldt.c3
-rw-r--r--arch/um/sys-i386/ptrace_user.c5
11 files changed, 25 insertions, 32 deletions
diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c
index 7218c754505b..e82764f75e7f 100644
--- a/arch/um/drivers/chan_kern.c
+++ b/arch/um/drivers/chan_kern.c
@@ -544,7 +544,7 @@ static struct chan *parse_chan(struct line *line, char *str, int device,
544 544
545 ops = NULL; 545 ops = NULL;
546 data = NULL; 546 data = NULL;
547 for(i = 0; i < sizeof(chan_table)/sizeof(chan_table[0]); i++){ 547 for(i = 0; i < ARRAY_SIZE(chan_table); i++){
548 entry = &chan_table[i]; 548 entry = &chan_table[i];
549 if(!strncmp(str, entry->key, strlen(entry->key))){ 549 if(!strncmp(str, entry->key, strlen(entry->key))){
550 ops = entry->ops; 550 ops = entry->ops;
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index b414522f7686..79610b5ce67e 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -497,7 +497,7 @@ static void mconsole_get_config(int (*get_config)(char *, char *, int,
497 } 497 }
498 498
499 error = NULL; 499 error = NULL;
500 size = sizeof(default_buf)/sizeof(default_buf[0]); 500 size = ARRAY_SIZE(default_buf);
501 buf = default_buf; 501 buf = default_buf;
502 502
503 while(1){ 503 while(1){
diff --git a/arch/um/drivers/mconsole_user.c b/arch/um/drivers/mconsole_user.c
index 9bfd405c3bd8..5b2f5fe9e426 100644
--- a/arch/um/drivers/mconsole_user.c
+++ b/arch/um/drivers/mconsole_user.c
@@ -16,6 +16,7 @@
16#include "user.h" 16#include "user.h"
17#include "mconsole.h" 17#include "mconsole.h"
18#include "umid.h" 18#include "umid.h"
19#include "user_util.h"
19 20
20static struct mconsole_command commands[] = { 21static struct mconsole_command commands[] = {
21 /* With uts namespaces, uts information becomes process-specific, so 22 /* With uts namespaces, uts information becomes process-specific, so
@@ -65,14 +66,14 @@ static struct mconsole_command *mconsole_parse(struct mc_request *req)
65 struct mconsole_command *cmd; 66 struct mconsole_command *cmd;
66 int i; 67 int i;
67 68
68 for(i=0;i<sizeof(commands)/sizeof(commands[0]);i++){ 69 for(i = 0; i < ARRAY_SIZE(commands); i++){
69 cmd = &commands[i]; 70 cmd = &commands[i];
70 if(!strncmp(req->request.data, cmd->command, 71 if(!strncmp(req->request.data, cmd->command,
71 strlen(cmd->command))){ 72 strlen(cmd->command))){
72 return(cmd); 73 return cmd;
73 } 74 }
74 } 75 }
75 return(NULL); 76 return NULL;
76} 77}
77 78
78#define MIN(a,b) ((a)<(b) ? (a):(b)) 79#define MIN(a,b) ((a)<(b) ? (a):(b))
diff --git a/arch/um/drivers/pcap_kern.c b/arch/um/drivers/pcap_kern.c
index 466ff2c2f918..4c767c7adb96 100644
--- a/arch/um/drivers/pcap_kern.c
+++ b/arch/um/drivers/pcap_kern.c
@@ -76,7 +76,7 @@ int pcap_setup(char *str, char **mac_out, void *data)
76 if(host_if != NULL) 76 if(host_if != NULL)
77 init->host_if = host_if; 77 init->host_if = host_if;
78 78
79 for(i = 0; i < sizeof(options)/sizeof(options[0]); i++){ 79 for(i = 0; i < ARRAY_SIZE(options); i++){
80 if(options[i] == NULL) 80 if(options[i] == NULL)
81 continue; 81 continue;
82 if(!strcmp(options[i], "promisc")) 82 if(!strcmp(options[i], "promisc"))
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index b1cd5c6e468b..93121c6d26e5 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -223,8 +223,9 @@ void paging_init(void)
223 223
224 empty_zero_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE); 224 empty_zero_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE);
225 empty_bad_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE); 225 empty_bad_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE);
226 for(i=0;i<sizeof(zones_size)/sizeof(zones_size[0]);i++) 226 for(i = 0; i < ARRAY_SIZE(zones_size); i++)
227 zones_size[i] = 0; 227 zones_size[i] = 0;
228
228 zones_size[ZONE_DMA] = (end_iomem >> PAGE_SHIFT) - (uml_physmem >> PAGE_SHIFT); 229 zones_size[ZONE_DMA] = (end_iomem >> PAGE_SHIFT) - (uml_physmem >> PAGE_SHIFT);
229#ifdef CONFIG_HIGHMEM 230#ifdef CONFIG_HIGHMEM
230 zones_size[ZONE_HIGHMEM] = highmem >> PAGE_SHIFT; 231 zones_size[ZONE_HIGHMEM] = highmem >> PAGE_SHIFT;
diff --git a/arch/um/kernel/reboot.c b/arch/um/kernel/reboot.c
index 3ef73bf2e781..f602623644aa 100644
--- a/arch/um/kernel/reboot.c
+++ b/arch/um/kernel/reboot.c
@@ -22,7 +22,7 @@ static void kill_idlers(int me)
22 struct task_struct *p; 22 struct task_struct *p;
23 int i; 23 int i;
24 24
25 for(i = 0; i < sizeof(idle_threads)/sizeof(idle_threads[0]); i++){ 25 for(i = 0; i < ARRAY_SIZE(idle_threads); i++){
26 p = idle_threads[i]; 26 p = idle_threads[i];
27 if((p != NULL) && (p->thread.mode.tt.extern_pid != me)) 27 if((p != NULL) && (p->thread.mode.tt.extern_pid != me))
28 os_kill_process(p->thread.mode.tt.extern_pid, 0); 28 os_kill_process(p->thread.mode.tt.extern_pid, 0);
@@ -62,14 +62,3 @@ void machine_halt(void)
62{ 62{
63 machine_power_off(); 63 machine_power_off();
64} 64}
65
66/*
67 * Overrides for Emacs so that we follow Linus's tabbing style.
68 * Emacs will notice this stuff at the end of the file and automatically
69 * adjust the settings for this buffer only. This must remain at the end
70 * of the file.
71 * ---------------------------------------------------------------------------
72 * Local variables:
73 * c-file-style: "linux"
74 * End:
75 */
diff --git a/arch/um/kernel/tlb.c b/arch/um/kernel/tlb.c
index f5b0636f9ad7..cca330edf717 100644
--- a/arch/um/kernel/tlb.c
+++ b/arch/um/kernel/tlb.c
@@ -137,10 +137,11 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
137 int r, w, x; 137 int r, w, x;
138 struct host_vm_op ops[1]; 138 struct host_vm_op ops[1];
139 void *flush = NULL; 139 void *flush = NULL;
140 int op_index = -1, last_op = sizeof(ops) / sizeof(ops[0]) - 1; 140 int op_index = -1, last_op = ARRAY_SIZE(ops) - 1;
141 int ret = 0; 141 int ret = 0;
142 142
143 if(mm == NULL) return; 143 if(mm == NULL)
144 return;
144 145
145 ops[0].type = NONE; 146 ops[0].type = NONE;
146 for(addr = start_addr; addr < end_addr && !ret;){ 147 for(addr = start_addr; addr < end_addr && !ret;){
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c
index 560c8063c77c..b170b4704dc4 100644
--- a/arch/um/os-Linux/mem.c
+++ b/arch/um/os-Linux/mem.c
@@ -114,14 +114,14 @@ static void which_tmpdir(void)
114 } 114 }
115 115
116 while(1){ 116 while(1){
117 found = next(fd, buf, sizeof(buf) / sizeof(buf[0]), ' '); 117 found = next(fd, buf, ARRAY_SIZE(buf), ' ');
118 if(found != 1) 118 if(found != 1)
119 break; 119 break;
120 120
121 if(!strncmp(buf, "/dev/shm", strlen("/dev/shm"))) 121 if(!strncmp(buf, "/dev/shm", strlen("/dev/shm")))
122 goto found; 122 goto found;
123 123
124 found = next(fd, buf, sizeof(buf) / sizeof(buf[0]), '\n'); 124 found = next(fd, buf, ARRAY_SIZE(buf), '\n');
125 if(found != 1) 125 if(found != 1)
126 break; 126 break;
127 } 127 }
@@ -135,7 +135,7 @@ err:
135 return; 135 return;
136 136
137found: 137found:
138 found = next(fd, buf, sizeof(buf) / sizeof(buf[0]), ' '); 138 found = next(fd, buf, ARRAY_SIZE(buf), ' ');
139 if(found != 1) 139 if(found != 1)
140 goto err; 140 goto err;
141 141
diff --git a/arch/um/sys-i386/bugs.c b/arch/um/sys-i386/bugs.c
index 41b0ab2fe830..f1bcd399ac90 100644
--- a/arch/um/sys-i386/bugs.c
+++ b/arch/um/sys-i386/bugs.c
@@ -13,6 +13,7 @@
13#include "sysdep/ptrace.h" 13#include "sysdep/ptrace.h"
14#include "task.h" 14#include "task.h"
15#include "os.h" 15#include "os.h"
16#include "user_util.h"
16 17
17#define MAXTOKEN 64 18#define MAXTOKEN 64
18 19
@@ -104,17 +105,17 @@ int cpu_feature(char *what, char *buf, int len)
104static int check_cpu_flag(char *feature, int *have_it) 105static int check_cpu_flag(char *feature, int *have_it)
105{ 106{
106 char buf[MAXTOKEN], c; 107 char buf[MAXTOKEN], c;
107 int fd, len = sizeof(buf)/sizeof(buf[0]); 108 int fd, len = ARRAY_SIZE(buf);
108 109
109 printk("Checking for host processor %s support...", feature); 110 printk("Checking for host processor %s support...", feature);
110 fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0); 111 fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
111 if(fd < 0){ 112 if(fd < 0){
112 printk("Couldn't open /proc/cpuinfo, err = %d\n", -fd); 113 printk("Couldn't open /proc/cpuinfo, err = %d\n", -fd);
113 return(0); 114 return 0;
114 } 115 }
115 116
116 *have_it = 0; 117 *have_it = 0;
117 if(!find_cpuinfo_line(fd, "flags", buf, sizeof(buf) / sizeof(buf[0]))) 118 if(!find_cpuinfo_line(fd, "flags", buf, ARRAY_SIZE(buf)))
118 goto out; 119 goto out;
119 120
120 c = token(fd, buf, len - 1, ' '); 121 c = token(fd, buf, len - 1, ' ');
@@ -138,7 +139,7 @@ static int check_cpu_flag(char *feature, int *have_it)
138 if(*have_it == 0) printk("No\n"); 139 if(*have_it == 0) printk("No\n");
139 else if(*have_it == 1) printk("Yes\n"); 140 else if(*have_it == 1) printk("Yes\n");
140 os_close_file(fd); 141 os_close_file(fd);
141 return(1); 142 return 1;
142} 143}
143 144
144#if 0 /* This doesn't work in tt mode, plus it's causing compilation problems 145#if 0 /* This doesn't work in tt mode, plus it's causing compilation problems
diff --git a/arch/um/sys-i386/ldt.c b/arch/um/sys-i386/ldt.c
index fe0877b3509c..69971b78beaf 100644
--- a/arch/um/sys-i386/ldt.c
+++ b/arch/um/sys-i386/ldt.c
@@ -424,9 +424,8 @@ void ldt_get_host_info(void)
424 size++; 424 size++;
425 } 425 }
426 426
427 if(size < sizeof(dummy_list)/sizeof(dummy_list[0])) { 427 if(size < ARRAY_SIZE(dummy_list))
428 host_ldt_entries = dummy_list; 428 host_ldt_entries = dummy_list;
429 }
430 else { 429 else {
431 size = (size + 1) * sizeof(dummy_list[0]); 430 size = (size + 1) * sizeof(dummy_list[0]);
432 host_ldt_entries = (short *)kmalloc(size, GFP_KERNEL); 431 host_ldt_entries = (short *)kmalloc(size, GFP_KERNEL);
diff --git a/arch/um/sys-i386/ptrace_user.c b/arch/um/sys-i386/ptrace_user.c
index 40aa88531446..5f3cc6685820 100644
--- a/arch/um/sys-i386/ptrace_user.c
+++ b/arch/um/sys-i386/ptrace_user.c
@@ -15,6 +15,7 @@
15#include "user.h" 15#include "user.h"
16#include "os.h" 16#include "os.h"
17#include "uml-config.h" 17#include "uml-config.h"
18#include "user_util.h"
18 19
19int ptrace_getregs(long pid, unsigned long *regs_out) 20int ptrace_getregs(long pid, unsigned long *regs_out)
20{ 21{
@@ -51,7 +52,7 @@ static void write_debugregs(int pid, unsigned long *regs)
51 int nregs, i; 52 int nregs, i;
52 53
53 dummy = NULL; 54 dummy = NULL;
54 nregs = sizeof(dummy->u_debugreg)/sizeof(dummy->u_debugreg[0]); 55 nregs = ARRAY_SIZE(dummy->u_debugreg);
55 for(i = 0; i < nregs; i++){ 56 for(i = 0; i < nregs; i++){
56 if((i == 4) || (i == 5)) continue; 57 if((i == 4) || (i == 5)) continue;
57 if(ptrace(PTRACE_POKEUSR, pid, &dummy->u_debugreg[i], 58 if(ptrace(PTRACE_POKEUSR, pid, &dummy->u_debugreg[i],
@@ -68,7 +69,7 @@ static void read_debugregs(int pid, unsigned long *regs)
68 int nregs, i; 69 int nregs, i;
69 70
70 dummy = NULL; 71 dummy = NULL;
71 nregs = sizeof(dummy->u_debugreg)/sizeof(dummy->u_debugreg[0]); 72 nregs = ARRAY_SIZE(dummy->u_debugreg);
72 for(i = 0; i < nregs; i++){ 73 for(i = 0; i < nregs; i++){
73 regs[i] = ptrace(PTRACE_PEEKUSR, pid, 74 regs[i] = ptrace(PTRACE_PEEKUSR, pid,
74 &dummy->u_debugreg[i], 0); 75 &dummy->u_debugreg[i], 0);