@@ -346,26 +346,29 @@ static const struct inode_operations proc_dir_inode_operations = {
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
358
if (pde_subdir_insert (dir , dp ) == false) {
360
359
WARN (1 , "proc_dir_entry '%s/%s' already registered\n" ,
361
360
dir -> name , dp -> name );
362
361
write_unlock (& proc_subdir_lock );
363
- proc_free_inum (dp -> low_ino );
364
- return - EEXIST ;
362
+ goto out_free_inum ;
365
363
}
366
364
write_unlock (& proc_subdir_lock );
367
365
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 ;
369
372
}
370
373
371
374
static struct proc_dir_entry * __proc_create (struct proc_dir_entry * * parent ,
@@ -443,10 +446,7 @@ struct proc_dir_entry *proc_symlink(const char *name,
443
446
if (ent -> data ) {
444
447
strcpy ((char * )ent -> data ,dest );
445
448
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 );
450
450
} else {
451
451
pde_free (ent );
452
452
ent = NULL ;
@@ -470,11 +470,9 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
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
}
@@ -505,11 +503,9 @@ struct proc_dir_entry *proc_create_mount_point(const char *name)
505
503
ent -> proc_fops = NULL ;
506
504
ent -> proc_iops = NULL ;
507
505
parent -> nlink ++ ;
508
- if ( proc_register (parent , ent ) < 0 ) {
509
- pde_free ( ent );
506
+ ent = proc_register (parent , ent );
507
+ if (! ent )
510
508
parent -> nlink -- ;
511
- ent = NULL ;
512
- }
513
509
}
514
510
return ent ;
515
511
}
@@ -539,11 +535,7 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
539
535
pde -> proc_fops = proc_fops ;
540
536
pde -> data = data ;
541
537
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 );
547
539
out :
548
540
return NULL ;
549
541
}
0 commit comments