@@ -255,7 +255,7 @@ getname_kernel(const char * filename)
255
255
256
256
void putname (struct filename * name )
257
257
{
258
- if (IS_ERR_OR_NULL (name ))
258
+ if (IS_ERR (name ))
259
259
return ;
260
260
261
261
BUG_ON (name -> refcnt <= 0 );
@@ -2467,7 +2467,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path
2467
2467
return err ;
2468
2468
}
2469
2469
2470
- static int __filename_lookup (int dfd , struct filename * name , unsigned flags ,
2470
+ int filename_lookup (int dfd , struct filename * name , unsigned flags ,
2471
2471
struct path * path , struct path * root )
2472
2472
{
2473
2473
int retval ;
@@ -2488,15 +2488,6 @@ static int __filename_lookup(int dfd, struct filename *name, unsigned flags,
2488
2488
return retval ;
2489
2489
}
2490
2490
2491
- int filename_lookup (int dfd , struct filename * name , unsigned flags ,
2492
- struct path * path , struct path * root )
2493
- {
2494
- int retval = __filename_lookup (dfd , name , flags , path , root );
2495
-
2496
- putname (name );
2497
- return retval ;
2498
- }
2499
-
2500
2491
/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
2501
2492
static int path_parentat (struct nameidata * nd , unsigned flags ,
2502
2493
struct path * parent )
@@ -2514,9 +2505,10 @@ static int path_parentat(struct nameidata *nd, unsigned flags,
2514
2505
return err ;
2515
2506
}
2516
2507
2517
- static int __filename_parentat (int dfd , struct filename * name ,
2518
- unsigned int flags , struct path * parent ,
2519
- struct qstr * last , int * type )
2508
+ /* Note: this does not consume "name" */
2509
+ static int filename_parentat (int dfd , struct filename * name ,
2510
+ unsigned int flags , struct path * parent ,
2511
+ struct qstr * last , int * type )
2520
2512
{
2521
2513
int retval ;
2522
2514
struct nameidata nd ;
@@ -2538,25 +2530,14 @@ static int __filename_parentat(int dfd, struct filename *name,
2538
2530
return retval ;
2539
2531
}
2540
2532
2541
- static int filename_parentat (int dfd , struct filename * name ,
2542
- unsigned int flags , struct path * parent ,
2543
- struct qstr * last , int * type )
2544
- {
2545
- int retval = __filename_parentat (dfd , name , flags , parent , last , type );
2546
-
2547
- putname (name );
2548
- return retval ;
2549
- }
2550
-
2551
2533
/* does lookup, returns the object with parent locked */
2552
- struct dentry * kern_path_locked ( const char * name , struct path * path )
2534
+ static struct dentry * __kern_path_locked ( struct filename * name , struct path * path )
2553
2535
{
2554
2536
struct dentry * d ;
2555
2537
struct qstr last ;
2556
2538
int type , error ;
2557
2539
2558
- error = filename_parentat (AT_FDCWD , getname_kernel (name ), 0 , path ,
2559
- & last , & type );
2540
+ error = filename_parentat (AT_FDCWD , name , 0 , path , & last , & type );
2560
2541
if (error )
2561
2542
return ERR_PTR (error );
2562
2543
if (unlikely (type != LAST_NORM )) {
@@ -2572,10 +2553,23 @@ struct dentry *kern_path_locked(const char *name, struct path *path)
2572
2553
return d ;
2573
2554
}
2574
2555
2556
+ struct dentry * kern_path_locked (const char * name , struct path * path )
2557
+ {
2558
+ struct filename * filename = getname_kernel (name );
2559
+ struct dentry * res = __kern_path_locked (filename , path );
2560
+
2561
+ putname (filename );
2562
+ return res ;
2563
+ }
2564
+
2575
2565
int kern_path (const char * name , unsigned int flags , struct path * path )
2576
2566
{
2577
- return filename_lookup (AT_FDCWD , getname_kernel (name ),
2578
- flags , path , NULL );
2567
+ struct filename * filename = getname_kernel (name );
2568
+ int ret = filename_lookup (AT_FDCWD , filename , flags , path , NULL );
2569
+
2570
+ putname (filename );
2571
+ return ret ;
2572
+
2579
2573
}
2580
2574
EXPORT_SYMBOL (kern_path );
2581
2575
@@ -2591,10 +2585,15 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
2591
2585
const char * name , unsigned int flags ,
2592
2586
struct path * path )
2593
2587
{
2588
+ struct filename * filename ;
2594
2589
struct path root = {.mnt = mnt , .dentry = dentry };
2590
+ int ret ;
2591
+
2592
+ filename = getname_kernel (name );
2595
2593
/* the first argument of filename_lookup() is ignored with root */
2596
- return filename_lookup (AT_FDCWD , getname_kernel (name ),
2597
- flags , path , & root );
2594
+ ret = filename_lookup (AT_FDCWD , filename , flags , path , & root );
2595
+ putname (filename );
2596
+ return ret ;
2598
2597
}
2599
2598
EXPORT_SYMBOL (vfs_path_lookup );
2600
2599
@@ -2798,8 +2797,11 @@ int path_pts(struct path *path)
2798
2797
int user_path_at_empty (int dfd , const char __user * name , unsigned flags ,
2799
2798
struct path * path , int * empty )
2800
2799
{
2801
- return filename_lookup (dfd , getname_flags (name , flags , empty ),
2802
- flags , path , NULL );
2800
+ struct filename * filename = getname_flags (name , flags , empty );
2801
+ int ret = filename_lookup (dfd , filename , flags , path , NULL );
2802
+
2803
+ putname (filename );
2804
+ return ret ;
2803
2805
}
2804
2806
EXPORT_SYMBOL (user_path_at_empty );
2805
2807
@@ -3618,8 +3620,8 @@ struct file *do_file_open_root(const struct path *root,
3618
3620
return file ;
3619
3621
}
3620
3622
3621
- static struct dentry * __filename_create (int dfd , struct filename * name ,
3622
- struct path * path , unsigned int lookup_flags )
3623
+ static struct dentry * filename_create (int dfd , struct filename * name ,
3624
+ struct path * path , unsigned int lookup_flags )
3623
3625
{
3624
3626
struct dentry * dentry = ERR_PTR (- EEXIST );
3625
3627
struct qstr last ;
@@ -3634,7 +3636,7 @@ static struct dentry *__filename_create(int dfd, struct filename *name,
3634
3636
*/
3635
3637
lookup_flags &= LOOKUP_REVAL ;
3636
3638
3637
- error = __filename_parentat (dfd , name , lookup_flags , path , & last , & type );
3639
+ error = filename_parentat (dfd , name , lookup_flags , path , & last , & type );
3638
3640
if (error )
3639
3641
return ERR_PTR (error );
3640
3642
@@ -3687,21 +3689,15 @@ static struct dentry *__filename_create(int dfd, struct filename *name,
3687
3689
return dentry ;
3688
3690
}
3689
3691
3690
- static inline struct dentry * filename_create (int dfd , struct filename * name ,
3692
+ struct dentry * kern_path_create (int dfd , const char * pathname ,
3691
3693
struct path * path , unsigned int lookup_flags )
3692
3694
{
3693
- struct dentry * res = __filename_create (dfd , name , path , lookup_flags );
3695
+ struct filename * filename = getname_kernel (pathname );
3696
+ struct dentry * res = filename_create (dfd , filename , path , lookup_flags );
3694
3697
3695
- putname (name );
3698
+ putname (filename );
3696
3699
return res ;
3697
3700
}
3698
-
3699
- struct dentry * kern_path_create (int dfd , const char * pathname ,
3700
- struct path * path , unsigned int lookup_flags )
3701
- {
3702
- return filename_create (dfd , getname_kernel (pathname ),
3703
- path , lookup_flags );
3704
- }
3705
3701
EXPORT_SYMBOL (kern_path_create );
3706
3702
3707
3703
void done_path_create (struct path * path , struct dentry * dentry )
@@ -3716,7 +3712,11 @@ EXPORT_SYMBOL(done_path_create);
3716
3712
inline struct dentry * user_path_create (int dfd , const char __user * pathname ,
3717
3713
struct path * path , unsigned int lookup_flags )
3718
3714
{
3719
- return filename_create (dfd , getname (pathname ), path , lookup_flags );
3715
+ struct filename * filename = getname (pathname );
3716
+ struct dentry * res = filename_create (dfd , filename , path , lookup_flags );
3717
+
3718
+ putname (filename );
3719
+ return res ;
3720
3720
}
3721
3721
EXPORT_SYMBOL (user_path_create );
3722
3722
@@ -3797,7 +3797,7 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
3797
3797
if (error )
3798
3798
goto out1 ;
3799
3799
retry :
3800
- dentry = __filename_create (dfd , name , & path , lookup_flags );
3800
+ dentry = filename_create (dfd , name , & path , lookup_flags );
3801
3801
error = PTR_ERR (dentry );
3802
3802
if (IS_ERR (dentry ))
3803
3803
goto out1 ;
@@ -3897,7 +3897,7 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode)
3897
3897
unsigned int lookup_flags = LOOKUP_DIRECTORY ;
3898
3898
3899
3899
retry :
3900
- dentry = __filename_create (dfd , name , & path , lookup_flags );
3900
+ dentry = filename_create (dfd , name , & path , lookup_flags );
3901
3901
error = PTR_ERR (dentry );
3902
3902
if (IS_ERR (dentry ))
3903
3903
goto out_putname ;
@@ -3996,7 +3996,7 @@ int do_rmdir(int dfd, struct filename *name)
3996
3996
int type ;
3997
3997
unsigned int lookup_flags = 0 ;
3998
3998
retry :
3999
- error = __filename_parentat (dfd , name , lookup_flags , & path , & last , & type );
3999
+ error = filename_parentat (dfd , name , lookup_flags , & path , & last , & type );
4000
4000
if (error )
4001
4001
goto exit1 ;
4002
4002
@@ -4137,7 +4137,7 @@ int do_unlinkat(int dfd, struct filename *name)
4137
4137
struct inode * delegated_inode = NULL ;
4138
4138
unsigned int lookup_flags = 0 ;
4139
4139
retry :
4140
- error = __filename_parentat (dfd , name , lookup_flags , & path , & last , & type );
4140
+ error = filename_parentat (dfd , name , lookup_flags , & path , & last , & type );
4141
4141
if (error )
4142
4142
goto exit1 ;
4143
4143
@@ -4266,7 +4266,7 @@ int do_symlinkat(struct filename *from, int newdfd, struct filename *to)
4266
4266
goto out_putnames ;
4267
4267
}
4268
4268
retry :
4269
- dentry = __filename_create (newdfd , to , & path , lookup_flags );
4269
+ dentry = filename_create (newdfd , to , & path , lookup_flags );
4270
4270
error = PTR_ERR (dentry );
4271
4271
if (IS_ERR (dentry ))
4272
4272
goto out_putnames ;
@@ -4426,11 +4426,11 @@ int do_linkat(int olddfd, struct filename *old, int newdfd,
4426
4426
if (flags & AT_SYMLINK_FOLLOW )
4427
4427
how |= LOOKUP_FOLLOW ;
4428
4428
retry :
4429
- error = __filename_lookup (olddfd , old , how , & old_path , NULL );
4429
+ error = filename_lookup (olddfd , old , how , & old_path , NULL );
4430
4430
if (error )
4431
4431
goto out_putnames ;
4432
4432
4433
- new_dentry = __filename_create (newdfd , new , & new_path ,
4433
+ new_dentry = filename_create (newdfd , new , & new_path ,
4434
4434
(how & LOOKUP_REVAL ));
4435
4435
error = PTR_ERR (new_dentry );
4436
4436
if (IS_ERR (new_dentry ))
@@ -4689,13 +4689,13 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd,
4689
4689
target_flags = 0 ;
4690
4690
4691
4691
retry :
4692
- error = __filename_parentat (olddfd , from , lookup_flags , & old_path ,
4693
- & old_last , & old_type );
4692
+ error = filename_parentat (olddfd , from , lookup_flags , & old_path ,
4693
+ & old_last , & old_type );
4694
4694
if (error )
4695
4695
goto put_names ;
4696
4696
4697
- error = __filename_parentat (newdfd , to , lookup_flags , & new_path , & new_last ,
4698
- & new_type );
4697
+ error = filename_parentat (newdfd , to , lookup_flags , & new_path , & new_last ,
4698
+ & new_type );
4699
4699
if (error )
4700
4700
goto exit1 ;
4701
4701
0 commit comments