Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

proc: simplify proc_register calling conventions

Return registered entry on success, return NULL on failure and free the
passed in entry. Also expose it in internal.h as we'll start using it
in proc_net.c soon.

Signed-off-by: Christoph Hellwig <hch@lst.de>

+20 -26
+18 -26
fs/proc/generic.c
··· 346 346 .setattr = proc_notify_change, 347 347 }; 348 348 349 - static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp) 349 + /* returns the registered entry, or frees dp and returns NULL on failure */ 350 + struct proc_dir_entry *proc_register(struct proc_dir_entry *dir, 351 + struct proc_dir_entry *dp) 350 352 { 351 - int ret; 352 - 353 - ret = proc_alloc_inum(&dp->low_ino); 354 - if (ret) 355 - return ret; 353 + if (proc_alloc_inum(&dp->low_ino)) 354 + goto out_free_entry; 356 355 357 356 write_lock(&proc_subdir_lock); 358 357 dp->parent = dir; ··· 359 360 WARN(1, "proc_dir_entry '%s/%s' already registered\n", 360 361 dir->name, dp->name); 361 362 write_unlock(&proc_subdir_lock); 362 - proc_free_inum(dp->low_ino); 363 - return -EEXIST; 363 + goto out_free_inum; 364 364 } 365 365 write_unlock(&proc_subdir_lock); 366 366 367 - return 0; 367 + return dp; 368 + out_free_inum: 369 + proc_free_inum(dp->low_ino); 370 + out_free_entry: 371 + pde_free(dp); 372 + return NULL; 368 373 } 369 374 370 375 static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, ··· 446 443 if (ent->data) { 447 444 strcpy((char*)ent->data,dest); 448 445 ent->proc_iops = &proc_link_inode_operations; 449 - if (proc_register(parent, ent) < 0) { 450 - pde_free(ent); 451 - ent = NULL; 452 - } 446 + ent = proc_register(parent, ent); 453 447 } else { 454 448 pde_free(ent); 455 449 ent = NULL; ··· 470 470 ent->proc_fops = &proc_dir_operations; 471 471 ent->proc_iops = &proc_dir_inode_operations; 472 472 parent->nlink++; 473 - if (proc_register(parent, ent) < 0) { 474 - pde_free(ent); 473 + ent = proc_register(parent, ent); 474 + if (!ent) 475 475 parent->nlink--; 476 - ent = NULL; 477 - } 478 476 } 479 477 return ent; 480 478 } ··· 503 505 ent->proc_fops = NULL; 504 506 ent->proc_iops = NULL; 505 507 parent->nlink++; 506 - if (proc_register(parent, ent) < 0) { 507 - pde_free(ent); 508 + ent = proc_register(parent, ent); 509 + if (!ent) 508 510 parent->nlink--; 509 - ent = NULL; 510 - } 511 511 } 512 512 return ent; 513 513 } ··· 535 539 pde->proc_fops = proc_fops; 536 540 pde->data = data; 537 541 pde->proc_iops = &proc_file_inode_operations; 538 - if (proc_register(parent, pde) < 0) 539 - goto out_free; 540 - return pde; 541 - out_free: 542 - pde_free(pde); 542 + return proc_register(parent, pde); 543 543 out: 544 544 return NULL; 545 545 }
+2
fs/proc/internal.h
··· 162 162 /* 163 163 * generic.c 164 164 */ 165 + struct proc_dir_entry *proc_register(struct proc_dir_entry *dir, 166 + struct proc_dir_entry *dp); 165 167 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int); 166 168 struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *); 167 169 extern int proc_readdir(struct file *, struct dir_context *);