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