@@ -250,8 +250,8 @@ EXPORT_SYMBOL_GPL(ffs_lock);
250
250
static struct ffs_dev * _ffs_find_dev (const char * name );
251
251
static struct ffs_dev * _ffs_alloc_dev (void );
252
252
static void _ffs_free_dev (struct ffs_dev * dev );
253
- static void * ffs_acquire_dev (const char * dev_name );
254
- static void ffs_release_dev (struct ffs_data * ffs_data );
253
+ static int ffs_acquire_dev (const char * dev_name , struct ffs_data * ffs_data );
254
+ static void ffs_release_dev (struct ffs_dev * ffs_dev );
255
255
static int ffs_ready (struct ffs_data * ffs );
256
256
static void ffs_closed (struct ffs_data * ffs );
257
257
@@ -1553,8 +1553,8 @@ static int ffs_fs_parse_param(struct fs_context *fc, struct fs_parameter *param)
1553
1553
static int ffs_fs_get_tree (struct fs_context * fc )
1554
1554
{
1555
1555
struct ffs_sb_fill_data * ctx = fc -> fs_private ;
1556
- void * ffs_dev ;
1557
1556
struct ffs_data * ffs ;
1557
+ int ret ;
1558
1558
1559
1559
ENTER ();
1560
1560
@@ -1573,13 +1573,12 @@ static int ffs_fs_get_tree(struct fs_context *fc)
1573
1573
return - ENOMEM ;
1574
1574
}
1575
1575
1576
- ffs_dev = ffs_acquire_dev (ffs -> dev_name );
1577
- if (IS_ERR ( ffs_dev ) ) {
1576
+ ret = ffs_acquire_dev (ffs -> dev_name , ffs );
1577
+ if (ret ) {
1578
1578
ffs_data_put (ffs );
1579
- return PTR_ERR ( ffs_dev ) ;
1579
+ return ret ;
1580
1580
}
1581
1581
1582
- ffs -> private_data = ffs_dev ;
1583
1582
ctx -> ffs_data = ffs ;
1584
1583
return get_tree_nodev (fc , ffs_sb_fill );
1585
1584
}
@@ -1590,7 +1589,6 @@ static void ffs_fs_free_fc(struct fs_context *fc)
1590
1589
1591
1590
if (ctx ) {
1592
1591
if (ctx -> ffs_data ) {
1593
- ffs_release_dev (ctx -> ffs_data );
1594
1592
ffs_data_put (ctx -> ffs_data );
1595
1593
}
1596
1594
@@ -1629,10 +1627,8 @@ ffs_fs_kill_sb(struct super_block *sb)
1629
1627
ENTER ();
1630
1628
1631
1629
kill_litter_super (sb );
1632
- if (sb -> s_fs_info ) {
1633
- ffs_release_dev (sb -> s_fs_info );
1630
+ if (sb -> s_fs_info )
1634
1631
ffs_data_closed (sb -> s_fs_info );
1635
- }
1636
1632
}
1637
1633
1638
1634
static struct file_system_type ffs_fs_type = {
@@ -1702,6 +1698,7 @@ static void ffs_data_put(struct ffs_data *ffs)
1702
1698
if (unlikely (refcount_dec_and_test (& ffs -> ref ))) {
1703
1699
pr_info ("%s(): freeing\n" , __func__ );
1704
1700
ffs_data_clear (ffs );
1701
+ ffs_release_dev (ffs -> private_data );
1705
1702
BUG_ON (waitqueue_active (& ffs -> ev .waitq ) ||
1706
1703
swait_active (& ffs -> ep0req_completion .wait ) ||
1707
1704
waitqueue_active (& ffs -> wait ));
@@ -3031,6 +3028,7 @@ static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f,
3031
3028
struct ffs_function * func = ffs_func_from_usb (f );
3032
3029
struct f_fs_opts * ffs_opts =
3033
3030
container_of (f -> fi , struct f_fs_opts , func_inst );
3031
+ struct ffs_data * ffs_data ;
3034
3032
int ret ;
3035
3033
3036
3034
ENTER ();
@@ -3045,12 +3043,13 @@ static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f,
3045
3043
if (!ffs_opts -> no_configfs )
3046
3044
ffs_dev_lock ();
3047
3045
ret = ffs_opts -> dev -> desc_ready ? 0 : - ENODEV ;
3048
- func -> ffs = ffs_opts -> dev -> ffs_data ;
3046
+ ffs_data = ffs_opts -> dev -> ffs_data ;
3049
3047
if (!ffs_opts -> no_configfs )
3050
3048
ffs_dev_unlock ();
3051
3049
if (ret )
3052
3050
return ERR_PTR (ret );
3053
3051
3052
+ func -> ffs = ffs_data ;
3054
3053
func -> conf = c ;
3055
3054
func -> gadget = c -> cdev -> gadget ;
3056
3055
@@ -3505,6 +3504,7 @@ static void ffs_free_inst(struct usb_function_instance *f)
3505
3504
struct f_fs_opts * opts ;
3506
3505
3507
3506
opts = to_f_fs_opts (f );
3507
+ ffs_release_dev (opts -> dev );
3508
3508
ffs_dev_lock ();
3509
3509
_ffs_free_dev (opts -> dev );
3510
3510
ffs_dev_unlock ();
@@ -3692,47 +3692,48 @@ static void _ffs_free_dev(struct ffs_dev *dev)
3692
3692
{
3693
3693
list_del (& dev -> entry );
3694
3694
3695
- /* Clear the private_data pointer to stop incorrect dev access */
3696
- if (dev -> ffs_data )
3697
- dev -> ffs_data -> private_data = NULL ;
3698
-
3699
3695
kfree (dev );
3700
3696
if (list_empty (& ffs_devices ))
3701
3697
functionfs_cleanup ();
3702
3698
}
3703
3699
3704
- static void * ffs_acquire_dev (const char * dev_name )
3700
+ static int ffs_acquire_dev (const char * dev_name , struct ffs_data * ffs_data )
3705
3701
{
3702
+ int ret = 0 ;
3706
3703
struct ffs_dev * ffs_dev ;
3707
3704
3708
3705
ENTER ();
3709
3706
ffs_dev_lock ();
3710
3707
3711
3708
ffs_dev = _ffs_find_dev (dev_name );
3712
- if (!ffs_dev )
3713
- ffs_dev = ERR_PTR ( - ENOENT ) ;
3714
- else if (ffs_dev -> mounted )
3715
- ffs_dev = ERR_PTR ( - EBUSY ) ;
3716
- else if (ffs_dev -> ffs_acquire_dev_callback &&
3717
- ffs_dev -> ffs_acquire_dev_callback (ffs_dev ))
3718
- ffs_dev = ERR_PTR ( - ENOENT ) ;
3719
- else
3709
+ if (!ffs_dev ) {
3710
+ ret = - ENOENT ;
3711
+ } else if (ffs_dev -> mounted ) {
3712
+ ret = - EBUSY ;
3713
+ } else if (ffs_dev -> ffs_acquire_dev_callback &&
3714
+ ffs_dev -> ffs_acquire_dev_callback (ffs_dev )) {
3715
+ ret = - ENOENT ;
3716
+ } else {
3720
3717
ffs_dev -> mounted = true;
3718
+ ffs_dev -> ffs_data = ffs_data ;
3719
+ ffs_data -> private_data = ffs_dev ;
3720
+ }
3721
3721
3722
3722
ffs_dev_unlock ();
3723
- return ffs_dev ;
3723
+ return ret ;
3724
3724
}
3725
3725
3726
- static void ffs_release_dev (struct ffs_data * ffs_data )
3726
+ static void ffs_release_dev (struct ffs_dev * ffs_dev )
3727
3727
{
3728
- struct ffs_dev * ffs_dev ;
3729
-
3730
3728
ENTER ();
3731
3729
ffs_dev_lock ();
3732
3730
3733
- ffs_dev = ffs_data -> private_data ;
3734
- if (ffs_dev ) {
3731
+ if (ffs_dev && ffs_dev -> mounted ) {
3735
3732
ffs_dev -> mounted = false;
3733
+ if (ffs_dev -> ffs_data ) {
3734
+ ffs_dev -> ffs_data -> private_data = NULL ;
3735
+ ffs_dev -> ffs_data = NULL ;
3736
+ }
3736
3737
3737
3738
if (ffs_dev -> ffs_release_dev_callback )
3738
3739
ffs_dev -> ffs_release_dev_callback (ffs_dev );
@@ -3760,7 +3761,6 @@ static int ffs_ready(struct ffs_data *ffs)
3760
3761
}
3761
3762
3762
3763
ffs_obj -> desc_ready = true;
3763
- ffs_obj -> ffs_data = ffs ;
3764
3764
3765
3765
if (ffs_obj -> ffs_ready_callback ) {
3766
3766
ret = ffs_obj -> ffs_ready_callback (ffs );
@@ -3788,7 +3788,6 @@ static void ffs_closed(struct ffs_data *ffs)
3788
3788
goto done ;
3789
3789
3790
3790
ffs_obj -> desc_ready = false;
3791
- ffs_obj -> ffs_data = NULL ;
3792
3791
3793
3792
if (test_and_clear_bit (FFS_FL_CALL_CLOSED_CALLBACK , & ffs -> flags ) &&
3794
3793
ffs_obj -> ffs_closed_callback )
0 commit comments