@@ -346,26 +346,29 @@ static const struct inode_operations proc_dir_inode_operations = {
346346 .setattr = proc_notify_change ,
347347};
348348
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 )
350352{
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 ;
356355
357356 write_lock (& proc_subdir_lock );
358357 dp -> parent = dir ;
359358 if (pde_subdir_insert (dir , dp ) == false) {
360359 WARN (1 , "proc_dir_entry '%s/%s' already registered\n" ,
361360 dir -> name , dp -> name );
362361 write_unlock (& proc_subdir_lock );
363- proc_free_inum (dp -> low_ino );
364- return - EEXIST ;
362+ goto out_free_inum ;
365363 }
366364 write_unlock (& proc_subdir_lock );
367365
368- return 0 ;
366+ return dp ;
367+ out_free_inum :
368+ proc_free_inum (dp -> low_ino );
369+ out_free_entry :
370+ pde_free (dp );
371+ return NULL ;
369372}
370373
371374static struct proc_dir_entry * __proc_create (struct proc_dir_entry * * parent ,
@@ -443,10 +446,7 @@ struct proc_dir_entry *proc_symlink(const char *name,
443446 if (ent -> data ) {
444447 strcpy ((char * )ent -> data ,dest );
445448 ent -> proc_iops = & proc_link_inode_operations ;
446- if (proc_register (parent , ent ) < 0 ) {
447- pde_free (ent );
448- ent = NULL ;
449- }
449+ ent = proc_register (parent , ent );
450450 } else {
451451 pde_free (ent );
452452 ent = NULL ;
@@ -470,11 +470,9 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
470470 ent -> proc_fops = & proc_dir_operations ;
471471 ent -> proc_iops = & proc_dir_inode_operations ;
472472 parent -> nlink ++ ;
473- if ( proc_register (parent , ent ) < 0 ) {
474- pde_free ( ent );
473+ ent = proc_register (parent , ent );
474+ if (! ent )
475475 parent -> nlink -- ;
476- ent = NULL ;
477- }
478476 }
479477 return ent ;
480478}
@@ -505,11 +503,9 @@ struct proc_dir_entry *proc_create_mount_point(const char *name)
505503 ent -> proc_fops = NULL ;
506504 ent -> proc_iops = NULL ;
507505 parent -> nlink ++ ;
508- if ( proc_register (parent , ent ) < 0 ) {
509- pde_free ( ent );
506+ ent = proc_register (parent , ent );
507+ if (! ent )
510508 parent -> nlink -- ;
511- ent = NULL ;
512- }
513509 }
514510 return ent ;
515511}
@@ -539,11 +535,7 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
539535 pde -> proc_fops = proc_fops ;
540536 pde -> data = data ;
541537 pde -> proc_iops = & proc_file_inode_operations ;
542- if (proc_register (parent , pde ) < 0 )
543- goto out_free ;
544- return pde ;
545- out_free :
546- pde_free (pde );
538+ return proc_register (parent , pde );
547539out :
548540 return NULL ;
549541}
0 commit comments