Skip to content

Commit 91b165c

Browse files
cfd-36Linus Torvalds
authored andcommitted
[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>
1 parent 13c06be commit 91b165c

11 files changed

Lines changed: 25 additions & 32 deletions

File tree

‎arch/um/drivers/chan_kern.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static struct chan *parse_chan(struct line *line, char *str, int device,
544544

545545
ops = NULL;
546546
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++){
548548
entry = &chan_table[i];
549549
if(!strncmp(str, entry->key, strlen(entry->key))){
550550
ops = entry->ops;

‎arch/um/drivers/mconsole_kern.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static void mconsole_get_config(int (*get_config)(char *, char *, int,
497497
}
498498

499499
error = NULL;
500-
size = sizeof(default_buf)/sizeof(default_buf[0]);
500+
size = ARRAY_SIZE(default_buf);
501501
buf = default_buf;
502502

503503
while(1){

‎arch/um/drivers/mconsole_user.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "user.h"
1717
#include "mconsole.h"
1818
#include "umid.h"
19+
#include "user_util.h"
1920

2021
static struct mconsole_command commands[] = {
2122
/* With uts namespaces, uts information becomes process-specific, so
@@ -65,14 +66,14 @@ static struct mconsole_command *mconsole_parse(struct mc_request *req)
6566
struct mconsole_command *cmd;
6667
int i;
6768

68-
for(i=0;i<sizeof(commands)/sizeof(commands[0]);i++){
69+
for(i = 0; i < ARRAY_SIZE(commands); i++){
6970
cmd = &commands[i];
7071
if(!strncmp(req->request.data, cmd->command,
7172
strlen(cmd->command))){
72-
return(cmd);
73+
return cmd;
7374
}
7475
}
75-
return(NULL);
76+
return NULL;
7677
}
7778

7879
#define MIN(a,b) ((a)<(b) ? (a):(b))

‎arch/um/drivers/pcap_kern.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int pcap_setup(char *str, char **mac_out, void *data)
7676
if(host_if != NULL)
7777
init->host_if = host_if;
7878

79-
for(i = 0; i < sizeof(options)/sizeof(options[0]); i++){
79+
for(i = 0; i < ARRAY_SIZE(options); i++){
8080
if(options[i] == NULL)
8181
continue;
8282
if(!strcmp(options[i], "promisc"))

‎arch/um/kernel/mem.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ void paging_init(void)
223223

224224
empty_zero_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE);
225225
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++)
227227
zones_size[i] = 0;
228+
228229
zones_size[ZONE_DMA] = (end_iomem >> PAGE_SHIFT) - (uml_physmem >> PAGE_SHIFT);
229230
#ifdef CONFIG_HIGHMEM
230231
zones_size[ZONE_HIGHMEM] = highmem >> PAGE_SHIFT;

‎arch/um/kernel/reboot.c‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void kill_idlers(int me)
2222
struct task_struct *p;
2323
int i;
2424

25-
for(i = 0; i < sizeof(idle_threads)/sizeof(idle_threads[0]); i++){
25+
for(i = 0; i < ARRAY_SIZE(idle_threads); i++){
2626
p = idle_threads[i];
2727
if((p != NULL) && (p->thread.mode.tt.extern_pid != me))
2828
os_kill_process(p->thread.mode.tt.extern_pid, 0);
@@ -62,14 +62,3 @@ void machine_halt(void)
6262
{
6363
machine_power_off();
6464
}
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-
*/

‎arch/um/kernel/tlb.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
137137
int r, w, x;
138138
struct host_vm_op ops[1];
139139
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;
141141
int ret = 0;
142142

143-
if(mm == NULL) return;
143+
if(mm == NULL)
144+
return;
144145

145146
ops[0].type = NONE;
146147
for(addr = start_addr; addr < end_addr && !ret;){

‎arch/um/os-Linux/mem.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ static void which_tmpdir(void)
114114
}
115115

116116
while(1){
117-
found = next(fd, buf, sizeof(buf) / sizeof(buf[0]), ' ');
117+
found = next(fd, buf, ARRAY_SIZE(buf), ' ');
118118
if(found != 1)
119119
break;
120120

121121
if(!strncmp(buf, "/dev/shm", strlen("/dev/shm")))
122122
goto found;
123123

124-
found = next(fd, buf, sizeof(buf) / sizeof(buf[0]), '\n');
124+
found = next(fd, buf, ARRAY_SIZE(buf), '\n');
125125
if(found != 1)
126126
break;
127127
}
@@ -135,7 +135,7 @@ static void which_tmpdir(void)
135135
return;
136136

137137
found:
138-
found = next(fd, buf, sizeof(buf) / sizeof(buf[0]), ' ');
138+
found = next(fd, buf, ARRAY_SIZE(buf), ' ');
139139
if(found != 1)
140140
goto err;
141141

‎arch/um/sys-i386/bugs.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "sysdep/ptrace.h"
1414
#include "task.h"
1515
#include "os.h"
16+
#include "user_util.h"
1617

1718
#define MAXTOKEN 64
1819

@@ -104,17 +105,17 @@ int cpu_feature(char *what, char *buf, int len)
104105
static int check_cpu_flag(char *feature, int *have_it)
105106
{
106107
char buf[MAXTOKEN], c;
107-
int fd, len = sizeof(buf)/sizeof(buf[0]);
108+
int fd, len = ARRAY_SIZE(buf);
108109

109110
printk("Checking for host processor %s support...", feature);
110111
fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
111112
if(fd < 0){
112113
printk("Couldn't open /proc/cpuinfo, err = %d\n", -fd);
113-
return(0);
114+
return 0;
114115
}
115116

116117
*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)))
118119
goto out;
119120

120121
c = token(fd, buf, len - 1, ' ');
@@ -138,7 +139,7 @@ static int check_cpu_flag(char *feature, int *have_it)
138139
if(*have_it == 0) printk("No\n");
139140
else if(*have_it == 1) printk("Yes\n");
140141
os_close_file(fd);
141-
return(1);
142+
return 1;
142143
}
143144

144145
#if 0 /* This doesn't work in tt mode, plus it's causing compilation problems

‎arch/um/sys-i386/ldt.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,8 @@ void ldt_get_host_info(void)
424424
size++;
425425
}
426426

427-
if(size < sizeof(dummy_list)/sizeof(dummy_list[0])) {
427+
if(size < ARRAY_SIZE(dummy_list))
428428
host_ldt_entries = dummy_list;
429-
}
430429
else {
431430
size = (size + 1) * sizeof(dummy_list[0]);
432431
host_ldt_entries = (short *)kmalloc(size, GFP_KERNEL);

0 commit comments

Comments
 (0)