Commit e6084d4a086b626acb5cf97795a9243062c2f4cd

Authored by Mike Frysinger
Committed by Linus Torvalds
1 parent 6b899c4e9a

binfmt_misc: clean up code style a bit

Clean up various coding style issues that checkpatch complains about.
No functional changes here.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 145 additions and 148 deletions Side-by-side Diff

1 1 /*
2   - * binfmt_misc.c
  2 + * binfmt_misc.c
3 3 *
4   - * Copyright (C) 1997 Richard Günther
  4 + * Copyright (C) 1997 Richard Günther
5 5 *
6   - * binfmt_misc detects binaries via a magic or filename extension and invokes
7   - * a specified wrapper. This should obsolete binfmt_java, binfmt_em86 and
8   - * binfmt_mz.
9   - *
10   - * 1997-04-25 first version
11   - * [...]
12   - * 1997-05-19 cleanup
13   - * 1997-06-26 hpa: pass the real filename rather than argv[0]
14   - * 1997-06-30 minor cleanup
15   - * 1997-08-09 removed extension stripping, locking cleanup
16   - * 2001-02-28 AV: rewritten into something that resembles C. Original didn't.
  6 + * binfmt_misc detects binaries via a magic or filename extension and invokes
  7 + * a specified wrapper. See Documentation/binfmt_misc.txt for more details.
17 8 */
18 9  
19 10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
... ... @@ -48,9 +39,9 @@
48 39 static int enabled = 1;
49 40  
50 41 enum {Enabled, Magic};
51   -#define MISC_FMT_PRESERVE_ARGV0 (1<<31)
52   -#define MISC_FMT_OPEN_BINARY (1<<30)
53   -#define MISC_FMT_CREDENTIALS (1<<29)
  42 +#define MISC_FMT_PRESERVE_ARGV0 (1 << 31)
  43 +#define MISC_FMT_OPEN_BINARY (1 << 30)
  44 +#define MISC_FMT_CREDENTIALS (1 << 29)
54 45  
55 46 typedef struct {
56 47 struct list_head list;
... ... @@ -134,7 +125,7 @@
134 125 static int load_misc_binary(struct linux_binprm *bprm)
135 126 {
136 127 Node *fmt;
137   - struct file * interp_file = NULL;
  128 + struct file *interp_file = NULL;
138 129 char iname[BINPRM_BUF_SIZE];
139 130 const char *iname_addr = iname;
140 131 int retval;
... ... @@ -142,7 +133,7 @@
142 133  
143 134 retval = -ENOEXEC;
144 135 if (!enabled)
145   - goto _ret;
  136 + goto ret;
146 137  
147 138 /* to keep locking time low, we copy the interpreter string */
148 139 read_lock(&entries_lock);
149 140  
150 141  
151 142  
... ... @@ -151,25 +142,26 @@
151 142 strlcpy(iname, fmt->interpreter, BINPRM_BUF_SIZE);
152 143 read_unlock(&entries_lock);
153 144 if (!fmt)
154   - goto _ret;
  145 + goto ret;
155 146  
156 147 if (!(fmt->flags & MISC_FMT_PRESERVE_ARGV0)) {
157 148 retval = remove_arg_zero(bprm);
158 149 if (retval)
159   - goto _ret;
  150 + goto ret;
160 151 }
161 152  
162 153 if (fmt->flags & MISC_FMT_OPEN_BINARY) {
163 154  
164 155 /* if the binary should be opened on behalf of the
165 156 * interpreter than keep it open and assign descriptor
166   - * to it */
  157 + * to it
  158 + */
167 159 fd_binary = get_unused_fd_flags(0);
168   - if (fd_binary < 0) {
169   - retval = fd_binary;
170   - goto _ret;
171   - }
172   - fd_install(fd_binary, bprm->file);
  160 + if (fd_binary < 0) {
  161 + retval = fd_binary;
  162 + goto ret;
  163 + }
  164 + fd_install(fd_binary, bprm->file);
173 165  
174 166 /* if the binary is not readable than enforce mm->dumpable=0
175 167 regardless of the interpreter's permissions */
176 168  
177 169  
178 170  
179 171  
180 172  
181 173  
... ... @@ -182,32 +174,32 @@
182 174 bprm->interp_flags |= BINPRM_FLAGS_EXECFD;
183 175 bprm->interp_data = fd_binary;
184 176  
185   - } else {
186   - allow_write_access(bprm->file);
187   - fput(bprm->file);
188   - bprm->file = NULL;
189   - }
  177 + } else {
  178 + allow_write_access(bprm->file);
  179 + fput(bprm->file);
  180 + bprm->file = NULL;
  181 + }
190 182 /* make argv[1] be the path to the binary */
191   - retval = copy_strings_kernel (1, &bprm->interp, bprm);
  183 + retval = copy_strings_kernel(1, &bprm->interp, bprm);
192 184 if (retval < 0)
193   - goto _error;
  185 + goto error;
194 186 bprm->argc++;
195 187  
196 188 /* add the interp as argv[0] */
197   - retval = copy_strings_kernel (1, &iname_addr, bprm);
  189 + retval = copy_strings_kernel(1, &iname_addr, bprm);
198 190 if (retval < 0)
199   - goto _error;
200   - bprm->argc ++;
  191 + goto error;
  192 + bprm->argc++;
201 193  
202 194 /* Update interp in case binfmt_script needs it. */
203 195 retval = bprm_change_interp(iname, bprm);
204 196 if (retval < 0)
205   - goto _error;
  197 + goto error;
206 198  
207   - interp_file = open_exec (iname);
208   - retval = PTR_ERR (interp_file);
209   - if (IS_ERR (interp_file))
210   - goto _error;
  199 + interp_file = open_exec(iname);
  200 + retval = PTR_ERR(interp_file);
  201 + if (IS_ERR(interp_file))
  202 + goto error;
211 203  
212 204 bprm->file = interp_file;
213 205 if (fmt->flags & MISC_FMT_CREDENTIALS) {
214 206  
215 207  
216 208  
217 209  
218 210  
... ... @@ -218,23 +210,23 @@
218 210 memset(bprm->buf, 0, BINPRM_BUF_SIZE);
219 211 retval = kernel_read(bprm->file, 0, bprm->buf, BINPRM_BUF_SIZE);
220 212 } else
221   - retval = prepare_binprm (bprm);
  213 + retval = prepare_binprm(bprm);
222 214  
223 215 if (retval < 0)
224   - goto _error;
  216 + goto error;
225 217  
226 218 retval = search_binary_handler(bprm);
227 219 if (retval < 0)
228   - goto _error;
  220 + goto error;
229 221  
230   -_ret:
  222 +ret:
231 223 return retval;
232   -_error:
  224 +error:
233 225 if (fd_binary > 0)
234 226 sys_close(fd_binary);
235 227 bprm->interp_flags = 0;
236 228 bprm->interp_data = 0;
237   - goto _ret;
  229 + goto ret;
238 230 }
239 231  
240 232 /* Command parsers */
241 233  
242 234  
243 235  
... ... @@ -261,39 +253,40 @@
261 253 return s;
262 254 }
263 255  
264   -static char * check_special_flags (char * sfs, Node * e)
  256 +static char *check_special_flags(char *sfs, Node *e)
265 257 {
266   - char * p = sfs;
  258 + char *p = sfs;
267 259 int cont = 1;
268 260  
269 261 /* special flags */
270 262 while (cont) {
271 263 switch (*p) {
272   - case 'P':
273   - pr_debug("register: flag: P (preserve argv0)\n");
274   - p++;
275   - e->flags |= MISC_FMT_PRESERVE_ARGV0;
276   - break;
277   - case 'O':
278   - pr_debug("register: flag: O (open binary)\n");
279   - p++;
280   - e->flags |= MISC_FMT_OPEN_BINARY;
281   - break;
282   - case 'C':
283   - pr_debug("register: flag: C (preserve creds)\n");
284   - p++;
285   - /* this flags also implies the
286   - open-binary flag */
287   - e->flags |= (MISC_FMT_CREDENTIALS |
288   - MISC_FMT_OPEN_BINARY);
289   - break;
290   - default:
291   - cont = 0;
  264 + case 'P':
  265 + pr_debug("register: flag: P (preserve argv0)\n");
  266 + p++;
  267 + e->flags |= MISC_FMT_PRESERVE_ARGV0;
  268 + break;
  269 + case 'O':
  270 + pr_debug("register: flag: O (open binary)\n");
  271 + p++;
  272 + e->flags |= MISC_FMT_OPEN_BINARY;
  273 + break;
  274 + case 'C':
  275 + pr_debug("register: flag: C (preserve creds)\n");
  276 + p++;
  277 + /* this flags also implies the
  278 + open-binary flag */
  279 + e->flags |= (MISC_FMT_CREDENTIALS |
  280 + MISC_FMT_OPEN_BINARY);
  281 + break;
  282 + default:
  283 + cont = 0;
292 284 }
293 285 }
294 286  
295 287 return p;
296 288 }
  289 +
297 290 /*
298 291 * This registers a new binary format, it recognises the syntax
299 292 * ':name:type:offset:magic:mask:interpreter:flags'
300 293  
301 294  
302 295  
... ... @@ -323,26 +316,26 @@
323 316  
324 317 memset(e, 0, sizeof(Node));
325 318 if (copy_from_user(buf, buffer, count))
326   - goto Efault;
  319 + goto efault;
327 320  
328 321 del = *p++; /* delimeter */
329 322  
330 323 pr_debug("register: delim: %#x {%c}\n", del, del);
331 324  
332 325 /* Pad the buffer with the delim to simplify parsing below. */
333   - memset(buf+count, del, 8);
  326 + memset(buf + count, del, 8);
334 327  
335 328 /* Parse the 'name' field. */
336 329 e->name = p;
337 330 p = strchr(p, del);
338 331 if (!p)
339   - goto Einval;
  332 + goto einval;
340 333 *p++ = '\0';
341 334 if (!e->name[0] ||
342 335 !strcmp(e->name, ".") ||
343 336 !strcmp(e->name, "..") ||
344 337 strchr(e->name, '/'))
345   - goto Einval;
  338 + goto einval;
346 339  
347 340 pr_debug("register: name: {%s}\n", e->name);
348 341  
349 342  
... ... @@ -357,10 +350,10 @@
357 350 e->flags = (1 << Enabled) | (1 << Magic);
358 351 break;
359 352 default:
360   - goto Einval;
  353 + goto einval;
361 354 }
362 355 if (*p++ != del)
363   - goto Einval;
  356 + goto einval;
364 357  
365 358 if (test_bit(Magic, &e->flags)) {
366 359 /* Handle the 'M' (magic) format. */
367 360  
368 361  
369 362  
... ... @@ -369,21 +362,21 @@
369 362 /* Parse the 'offset' field. */
370 363 s = strchr(p, del);
371 364 if (!s)
372   - goto Einval;
  365 + goto einval;
373 366 *s++ = '\0';
374 367 e->offset = simple_strtoul(p, &p, 10);
375 368 if (*p++)
376   - goto Einval;
  369 + goto einval;
377 370 pr_debug("register: offset: %#x\n", e->offset);
378 371  
379 372 /* Parse the 'magic' field. */
380 373 e->magic = p;
381 374 p = scanarg(p, del);
382 375 if (!p)
383   - goto Einval;
  376 + goto einval;
384 377 p[-1] = '\0';
385 378 if (p == e->magic)
386   - goto Einval;
  379 + goto einval;
387 380 if (USE_DEBUG)
388 381 print_hex_dump_bytes(
389 382 KBUILD_MODNAME ": register: magic[raw]: ",
... ... @@ -393,7 +386,7 @@
393 386 e->mask = p;
394 387 p = scanarg(p, del);
395 388 if (!p)
396   - goto Einval;
  389 + goto einval;
397 390 p[-1] = '\0';
398 391 if (p == e->mask) {
399 392 e->mask = NULL;
400 393  
... ... @@ -412,9 +405,9 @@
412 405 e->size = string_unescape_inplace(e->magic, UNESCAPE_HEX);
413 406 if (e->mask &&
414 407 string_unescape_inplace(e->mask, UNESCAPE_HEX) != e->size)
415   - goto Einval;
  408 + goto einval;
416 409 if (e->size + e->offset > BINPRM_BUF_SIZE)
417   - goto Einval;
  410 + goto einval;
418 411 pr_debug("register: magic/mask length: %i\n", e->size);
419 412 if (USE_DEBUG) {
420 413 print_hex_dump_bytes(
421 414  
422 415  
423 416  
... ... @@ -446,23 +439,23 @@
446 439 /* Skip the 'offset' field. */
447 440 p = strchr(p, del);
448 441 if (!p)
449   - goto Einval;
  442 + goto einval;
450 443 *p++ = '\0';
451 444  
452 445 /* Parse the 'magic' field. */
453 446 e->magic = p;
454 447 p = strchr(p, del);
455 448 if (!p)
456   - goto Einval;
  449 + goto einval;
457 450 *p++ = '\0';
458 451 if (!e->magic[0] || strchr(e->magic, '/'))
459   - goto Einval;
  452 + goto einval;
460 453 pr_debug("register: extension: {%s}\n", e->magic);
461 454  
462 455 /* Skip the 'mask' field. */
463 456 p = strchr(p, del);
464 457 if (!p)
465   - goto Einval;
  458 + goto einval;
466 459 *p++ = '\0';
467 460 }
468 461  
469 462  
470 463  
471 464  
472 465  
473 466  
... ... @@ -470,27 +463,28 @@
470 463 e->interpreter = p;
471 464 p = strchr(p, del);
472 465 if (!p)
473   - goto Einval;
  466 + goto einval;
474 467 *p++ = '\0';
475 468 if (!e->interpreter[0])
476   - goto Einval;
  469 + goto einval;
477 470 pr_debug("register: interpreter: {%s}\n", e->interpreter);
478 471  
479 472 /* Parse the 'flags' field. */
480   - p = check_special_flags (p, e);
  473 + p = check_special_flags(p, e);
481 474 if (*p == '\n')
482 475 p++;
483 476 if (p != buf + count)
484   - goto Einval;
  477 + goto einval;
  478 +
485 479 return e;
486 480  
487 481 out:
488 482 return ERR_PTR(err);
489 483  
490   -Efault:
  484 +efault:
491 485 kfree(e);
492 486 return ERR_PTR(-EFAULT);
493   -Einval:
  487 +einval:
494 488 kfree(e);
495 489 return ERR_PTR(-EINVAL);
496 490 }
... ... @@ -509,7 +503,7 @@
509 503 return -EFAULT;
510 504 if (!count)
511 505 return 0;
512   - if (s[count-1] == '\n')
  506 + if (s[count - 1] == '\n')
513 507 count--;
514 508 if (count == 1 && s[0] == '0')
515 509 return 1;
... ... @@ -526,7 +520,7 @@
526 520 {
527 521 char *dp;
528 522 char *status = "disabled";
529   - const char * flags = "flags: ";
  523 + const char *flags = "flags: ";
530 524  
531 525 if (test_bit(Enabled, &e->flags))
532 526 status = "enabled";
533 527  
... ... @@ -540,20 +534,16 @@
540 534 dp = page + strlen(page);
541 535  
542 536 /* print the special flags */
543   - sprintf (dp, "%s", flags);
544   - dp += strlen (flags);
545   - if (e->flags & MISC_FMT_PRESERVE_ARGV0) {
546   - *dp ++ = 'P';
547   - }
548   - if (e->flags & MISC_FMT_OPEN_BINARY) {
549   - *dp ++ = 'O';
550   - }
551   - if (e->flags & MISC_FMT_CREDENTIALS) {
552   - *dp ++ = 'C';
553   - }
554   - *dp ++ = '\n';
  537 + sprintf(dp, "%s", flags);
  538 + dp += strlen(flags);
  539 + if (e->flags & MISC_FMT_PRESERVE_ARGV0)
  540 + *dp++ = 'P';
  541 + if (e->flags & MISC_FMT_OPEN_BINARY)
  542 + *dp++ = 'O';
  543 + if (e->flags & MISC_FMT_CREDENTIALS)
  544 + *dp++ = 'C';
  545 + *dp++ = '\n';
555 546  
556   -
557 547 if (!test_bit(Magic, &e->flags)) {
558 548 sprintf(dp, "extension .%s\n", e->magic);
559 549 } else {
... ... @@ -580,7 +570,7 @@
580 570  
581 571 static struct inode *bm_get_inode(struct super_block *sb, int mode)
582 572 {
583   - struct inode * inode = new_inode(sb);
  573 + struct inode *inode = new_inode(sb);
584 574  
585 575 if (inode) {
586 576 inode->i_ino = get_next_ino();
587 577  
... ... @@ -620,13 +610,14 @@
620 610 /* /<entry> */
621 611  
622 612 static ssize_t
623   -bm_entry_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
  613 +bm_entry_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
624 614 {
625 615 Node *e = file_inode(file)->i_private;
626 616 ssize_t res;
627 617 char *page;
628 618  
629   - if (!(page = (char*) __get_free_page(GFP_KERNEL)))
  619 + page = (char *) __get_free_page(GFP_KERNEL);
  620 + if (!page)
630 621 return -ENOMEM;
631 622  
632 623 entry_status(e, page);
633 624  
634 625  
635 626  
... ... @@ -645,26 +636,28 @@
645 636 int res = parse_command(buffer, count);
646 637  
647 638 switch (res) {
648   - case 1:
649   - /* Disable this handler. */
650   - clear_bit(Enabled, &e->flags);
651   - break;
652   - case 2:
653   - /* Enable this handler. */
654   - set_bit(Enabled, &e->flags);
655   - break;
656   - case 3:
657   - /* Delete this handler. */
658   - root = dget(file->f_path.dentry->d_sb->s_root);
659   - mutex_lock(&root->d_inode->i_mutex);
  639 + case 1:
  640 + /* Disable this handler. */
  641 + clear_bit(Enabled, &e->flags);
  642 + break;
  643 + case 2:
  644 + /* Enable this handler. */
  645 + set_bit(Enabled, &e->flags);
  646 + break;
  647 + case 3:
  648 + /* Delete this handler. */
  649 + root = dget(file->f_path.dentry->d_sb->s_root);
  650 + mutex_lock(&root->d_inode->i_mutex);
660 651  
661   - kill_node(e);
  652 + kill_node(e);
662 653  
663   - mutex_unlock(&root->d_inode->i_mutex);
664   - dput(root);
665   - break;
666   - default: return res;
  654 + mutex_unlock(&root->d_inode->i_mutex);
  655 + dput(root);
  656 + break;
  657 + default:
  658 + return res;
667 659 }
  660 +
668 661 return count;
669 662 }
670 663  
671 664  
672 665  
673 666  
674 667  
... ... @@ -752,34 +745,36 @@
752 745 return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s));
753 746 }
754 747  
755   -static ssize_t bm_status_write(struct file * file, const char __user * buffer,
  748 +static ssize_t bm_status_write(struct file *file, const char __user *buffer,
756 749 size_t count, loff_t *ppos)
757 750 {
758 751 int res = parse_command(buffer, count);
759 752 struct dentry *root;
760 753  
761 754 switch (res) {
762   - case 1:
763   - /* Disable all handlers. */
764   - enabled = 0;
765   - break;
766   - case 2:
767   - /* Enable all handlers. */
768   - enabled = 1;
769   - break;
770   - case 3:
771   - /* Delete all handlers. */
772   - root = dget(file->f_path.dentry->d_sb->s_root);
773   - mutex_lock(&root->d_inode->i_mutex);
  755 + case 1:
  756 + /* Disable all handlers. */
  757 + enabled = 0;
  758 + break;
  759 + case 2:
  760 + /* Enable all handlers. */
  761 + enabled = 1;
  762 + break;
  763 + case 3:
  764 + /* Delete all handlers. */
  765 + root = dget(file->f_path.dentry->d_sb->s_root);
  766 + mutex_lock(&root->d_inode->i_mutex);
774 767  
775   - while (!list_empty(&entries))
776   - kill_node(list_entry(entries.next, Node, list));
  768 + while (!list_empty(&entries))
  769 + kill_node(list_entry(entries.next, Node, list));
777 770  
778   - mutex_unlock(&root->d_inode->i_mutex);
779   - dput(root);
780   - break;
781   - default: return res;
  771 + mutex_unlock(&root->d_inode->i_mutex);
  772 + dput(root);
  773 + break;
  774 + default:
  775 + return res;
782 776 }
  777 +
783 778 return count;
784 779 }
785 780  
786 781  
787 782  
... ... @@ -796,14 +791,16 @@
796 791 .evict_inode = bm_evict_inode,
797 792 };
798 793  
799   -static int bm_fill_super(struct super_block * sb, void * data, int silent)
  794 +static int bm_fill_super(struct super_block *sb, void *data, int silent)
800 795 {
  796 + int err;
801 797 static struct tree_descr bm_files[] = {
802 798 [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
803 799 [3] = {"register", &bm_register_operations, S_IWUSR},
804 800 /* last one */ {""}
805 801 };
806   - int err = simple_fill_super(sb, BINFMTFS_MAGIC, bm_files);
  802 +
  803 + err = simple_fill_super(sb, BINFMTFS_MAGIC, bm_files);
807 804 if (!err)
808 805 sb->s_op = &s_ops;
809 806 return err;