@@ -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
@@ -1562,8 +1562,8 @@ static int ffs_fs_parse_param(struct fs_context *fc, struct fs_parameter *param)
1562
1562
static int ffs_fs_get_tree (struct fs_context * fc )
1563
1563
{
1564
1564
struct ffs_sb_fill_data * ctx = fc -> fs_private ;
1565
- void * ffs_dev ;
1566
1565
struct ffs_data * ffs ;
1566
+ int ret ;
1567
1567
1568
1568
ENTER ();
1569
1569
@@ -1582,13 +1582,12 @@ static int ffs_fs_get_tree(struct fs_context *fc)
1582
1582
return - ENOMEM ;
1583
1583
}
1584
1584
1585
- ffs_dev = ffs_acquire_dev (ffs -> dev_name );
1586
- if (IS_ERR ( ffs_dev ) ) {
1585
+ ret = ffs_acquire_dev (ffs -> dev_name , ffs );
1586
+ if (ret ) {
1587
1587
ffs_data_put (ffs );
1588
- return PTR_ERR ( ffs_dev ) ;
1588
+ return ret ;
1589
1589
}
1590
1590
1591
- ffs -> private_data = ffs_dev ;
1592
1591
ctx -> ffs_data = ffs ;
1593
1592
return get_tree_nodev (fc , ffs_sb_fill );
1594
1593
}
@@ -1599,7 +1598,6 @@ static void ffs_fs_free_fc(struct fs_context *fc)
1599
1598
1600
1599
if (ctx ) {
1601
1600
if (ctx -> ffs_data ) {
1602
- ffs_release_dev (ctx -> ffs_data );
1603
1601
ffs_data_put (ctx -> ffs_data );
1604
1602
}
1605
1603
@@ -1638,10 +1636,8 @@ ffs_fs_kill_sb(struct super_block *sb)
1638
1636
ENTER ();
1639
1637
1640
1638
kill_litter_super (sb );
1641
- if (sb -> s_fs_info ) {
1642
- ffs_release_dev (sb -> s_fs_info );
1639
+ if (sb -> s_fs_info )
1643
1640
ffs_data_closed (sb -> s_fs_info );
1644
- }
1645
1641
}
1646
1642
1647
1643
static struct file_system_type ffs_fs_type = {
@@ -1711,6 +1707,7 @@ static void ffs_data_put(struct ffs_data *ffs)
1711
1707
if (unlikely (refcount_dec_and_test (& ffs -> ref ))) {
1712
1708
pr_info ("%s(): freeing\n" , __func__ );
1713
1709
ffs_data_clear (ffs );
1710
+ ffs_release_dev (ffs -> private_data );
1714
1711
BUG_ON (waitqueue_active (& ffs -> ev .waitq ) ||
1715
1712
waitqueue_active (& ffs -> ep0req_completion .wait ) ||
1716
1713
waitqueue_active (& ffs -> wait ));
@@ -3040,6 +3037,7 @@ static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f,
3040
3037
struct ffs_function * func = ffs_func_from_usb (f );
3041
3038
struct f_fs_opts * ffs_opts =
3042
3039
container_of (f -> fi , struct f_fs_opts , func_inst );
3040
+ struct ffs_data * ffs_data ;
3043
3041
int ret ;
3044
3042
3045
3043
ENTER ();
@@ -3054,12 +3052,13 @@ static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f,
3054
3052
if (!ffs_opts -> no_configfs )
3055
3053
ffs_dev_lock ();
3056
3054
ret = ffs_opts -> dev -> desc_ready ? 0 : - ENODEV ;
3057
- func -> ffs = ffs_opts -> dev -> ffs_data ;
3055
+ ffs_data = ffs_opts -> dev -> ffs_data ;
3058
3056
if (!ffs_opts -> no_configfs )
3059
3057
ffs_dev_unlock ();
3060
3058
if (ret )
3061
3059
return ERR_PTR (ret );
3062
3060
3061
+ func -> ffs = ffs_data ;
3063
3062
func -> conf = c ;
3064
3063
func -> gadget = c -> cdev -> gadget ;
3065
3064
@@ -3514,6 +3513,7 @@ static void ffs_free_inst(struct usb_function_instance *f)
3514
3513
struct f_fs_opts * opts ;
3515
3514
3516
3515
opts = to_f_fs_opts (f );
3516
+ ffs_release_dev (opts -> dev );
3517
3517
ffs_dev_lock ();
3518
3518
_ffs_free_dev (opts -> dev );
3519
3519
ffs_dev_unlock ();
@@ -3701,47 +3701,48 @@ static void _ffs_free_dev(struct ffs_dev *dev)
3701
3701
{
3702
3702
list_del (& dev -> entry );
3703
3703
3704
- /* Clear the private_data pointer to stop incorrect dev access */
3705
- if (dev -> ffs_data )
3706
- dev -> ffs_data -> private_data = NULL ;
3707
-
3708
3704
kfree (dev );
3709
3705
if (list_empty (& ffs_devices ))
3710
3706
functionfs_cleanup ();
3711
3707
}
3712
3708
3713
- static void * ffs_acquire_dev (const char * dev_name )
3709
+ static int ffs_acquire_dev (const char * dev_name , struct ffs_data * ffs_data )
3714
3710
{
3711
+ int ret = 0 ;
3715
3712
struct ffs_dev * ffs_dev ;
3716
3713
3717
3714
ENTER ();
3718
3715
ffs_dev_lock ();
3719
3716
3720
3717
ffs_dev = _ffs_find_dev (dev_name );
3721
- if (!ffs_dev )
3722
- ffs_dev = ERR_PTR ( - ENOENT ) ;
3723
- else if (ffs_dev -> mounted )
3724
- ffs_dev = ERR_PTR ( - EBUSY ) ;
3725
- else if (ffs_dev -> ffs_acquire_dev_callback &&
3726
- ffs_dev -> ffs_acquire_dev_callback (ffs_dev ))
3727
- ffs_dev = ERR_PTR ( - ENOENT ) ;
3728
- else
3718
+ if (!ffs_dev ) {
3719
+ ret = - ENOENT ;
3720
+ } else if (ffs_dev -> mounted ) {
3721
+ ret = - EBUSY ;
3722
+ } else if (ffs_dev -> ffs_acquire_dev_callback &&
3723
+ ffs_dev -> ffs_acquire_dev_callback (ffs_dev )) {
3724
+ ret = - ENOENT ;
3725
+ } else {
3729
3726
ffs_dev -> mounted = true;
3727
+ ffs_dev -> ffs_data = ffs_data ;
3728
+ ffs_data -> private_data = ffs_dev ;
3729
+ }
3730
3730
3731
3731
ffs_dev_unlock ();
3732
- return ffs_dev ;
3732
+ return ret ;
3733
3733
}
3734
3734
3735
- static void ffs_release_dev (struct ffs_data * ffs_data )
3735
+ static void ffs_release_dev (struct ffs_dev * ffs_dev )
3736
3736
{
3737
- struct ffs_dev * ffs_dev ;
3738
-
3739
3737
ENTER ();
3740
3738
ffs_dev_lock ();
3741
3739
3742
- ffs_dev = ffs_data -> private_data ;
3743
- if (ffs_dev ) {
3740
+ if (ffs_dev && ffs_dev -> mounted ) {
3744
3741
ffs_dev -> mounted = false;
3742
+ if (ffs_dev -> ffs_data ) {
3743
+ ffs_dev -> ffs_data -> private_data = NULL ;
3744
+ ffs_dev -> ffs_data = NULL ;
3745
+ }
3745
3746
3746
3747
if (ffs_dev -> ffs_release_dev_callback )
3747
3748
ffs_dev -> ffs_release_dev_callback (ffs_dev );
@@ -3769,7 +3770,6 @@ static int ffs_ready(struct ffs_data *ffs)
3769
3770
}
3770
3771
3771
3772
ffs_obj -> desc_ready = true;
3772
- ffs_obj -> ffs_data = ffs ;
3773
3773
3774
3774
if (ffs_obj -> ffs_ready_callback ) {
3775
3775
ret = ffs_obj -> ffs_ready_callback (ffs );
@@ -3797,7 +3797,6 @@ static void ffs_closed(struct ffs_data *ffs)
3797
3797
goto done ;
3798
3798
3799
3799
ffs_obj -> desc_ready = false;
3800
- ffs_obj -> ffs_data = NULL ;
3801
3800
3802
3801
if (test_and_clear_bit (FFS_FL_CALL_CLOSED_CALLBACK , & ffs -> flags ) &&
3803
3802
ffs_obj -> ffs_closed_callback )
0 commit comments