@@ -250,8 +250,8 @@ EXPORT_SYMBOL_GPL(ffs_lock);
250250static  struct  ffs_dev  * _ffs_find_dev (const  char  * name );
251251static  struct  ffs_dev  * _ffs_alloc_dev (void );
252252static  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 );
255255static  int  ffs_ready (struct  ffs_data  * ffs );
256256static  void  ffs_closed (struct  ffs_data  * ffs );
257257
@@ -1554,8 +1554,8 @@ static int ffs_fs_parse_param(struct fs_context *fc, struct fs_parameter *param)
15541554static  int  ffs_fs_get_tree (struct  fs_context  * fc )
15551555{
15561556	struct  ffs_sb_fill_data  * ctx  =  fc -> fs_private ;
1557- 	void  * ffs_dev ;
15581557	struct  ffs_data 	* ffs ;
1558+ 	int  ret ;
15591559
15601560	ENTER ();
15611561
@@ -1574,13 +1574,12 @@ static int ffs_fs_get_tree(struct fs_context *fc)
15741574		return  - ENOMEM ;
15751575	}
15761576
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 ) {
15791579		ffs_data_put (ffs );
1580- 		return  PTR_ERR ( ffs_dev ) ;
1580+ 		return  ret ;
15811581	}
15821582
1583- 	ffs -> private_data  =  ffs_dev ;
15841583	ctx -> ffs_data  =  ffs ;
15851584	return  get_tree_nodev (fc , ffs_sb_fill );
15861585}
@@ -1591,7 +1590,6 @@ static void ffs_fs_free_fc(struct fs_context *fc)
15911590
15921591	if  (ctx ) {
15931592		if  (ctx -> ffs_data ) {
1594- 			ffs_release_dev (ctx -> ffs_data );
15951593			ffs_data_put (ctx -> ffs_data );
15961594		}
15971595
@@ -1630,10 +1628,8 @@ ffs_fs_kill_sb(struct super_block *sb)
16301628	ENTER ();
16311629
16321630	kill_litter_super (sb );
1633- 	if  (sb -> s_fs_info ) {
1634- 		ffs_release_dev (sb -> s_fs_info );
1631+ 	if  (sb -> s_fs_info )
16351632		ffs_data_closed (sb -> s_fs_info );
1636- 	}
16371633}
16381634
16391635static  struct  file_system_type  ffs_fs_type  =  {
@@ -1703,6 +1699,7 @@ static void ffs_data_put(struct ffs_data *ffs)
17031699	if  (refcount_dec_and_test (& ffs -> ref )) {
17041700		pr_info ("%s(): freeing\n" , __func__ );
17051701		ffs_data_clear (ffs );
1702+ 		ffs_release_dev (ffs -> private_data );
17061703		BUG_ON (waitqueue_active (& ffs -> ev .waitq ) || 
17071704		       swait_active (& ffs -> ep0req_completion .wait ) || 
17081705		       waitqueue_active (& ffs -> wait ));
@@ -3032,6 +3029,7 @@ static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f,
30323029	struct  ffs_function  * func  =  ffs_func_from_usb (f );
30333030	struct  f_fs_opts  * ffs_opts  = 
30343031		container_of (f -> fi , struct  f_fs_opts , func_inst );
3032+ 	struct  ffs_data  * ffs_data ;
30353033	int  ret ;
30363034
30373035	ENTER ();
@@ -3046,12 +3044,13 @@ static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f,
30463044	if  (!ffs_opts -> no_configfs )
30473045		ffs_dev_lock ();
30483046	ret  =  ffs_opts -> dev -> desc_ready  ? 0  : - ENODEV ;
3049- 	func -> ffs  =  ffs_opts -> dev -> ffs_data ;
3047+ 	ffs_data  =  ffs_opts -> dev -> ffs_data ;
30503048	if  (!ffs_opts -> no_configfs )
30513049		ffs_dev_unlock ();
30523050	if  (ret )
30533051		return  ERR_PTR (ret );
30543052
3053+ 	func -> ffs  =  ffs_data ;
30553054	func -> conf  =  c ;
30563055	func -> gadget  =  c -> cdev -> gadget ;
30573056
@@ -3506,6 +3505,7 @@ static void ffs_free_inst(struct usb_function_instance *f)
35063505	struct  f_fs_opts  * opts ;
35073506
35083507	opts  =  to_f_fs_opts (f );
3508+ 	ffs_release_dev (opts -> dev );
35093509	ffs_dev_lock ();
35103510	_ffs_free_dev (opts -> dev );
35113511	ffs_dev_unlock ();
@@ -3690,47 +3690,48 @@ static void _ffs_free_dev(struct ffs_dev *dev)
36903690{
36913691	list_del (& dev -> entry );
36923692
3693- 	/* Clear the private_data pointer to stop incorrect dev access */ 
3694- 	if  (dev -> ffs_data )
3695- 		dev -> ffs_data -> private_data  =  NULL ;
3696- 
36973693	kfree (dev );
36983694	if  (list_empty (& ffs_devices ))
36993695		functionfs_cleanup ();
37003696}
37013697
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 )
37033699{
3700+ 	int  ret  =  0 ;
37043701	struct  ffs_dev  * ffs_dev ;
37053702
37063703	ENTER ();
37073704	ffs_dev_lock ();
37083705
37093706	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  { 
37183715		ffs_dev -> mounted  =  true;
3716+ 		ffs_dev -> ffs_data  =  ffs_data ;
3717+ 		ffs_data -> private_data  =  ffs_dev ;
3718+ 	}
37193719
37203720	ffs_dev_unlock ();
3721- 	return  ffs_dev ;
3721+ 	return  ret ;
37223722}
37233723
3724- static  void  ffs_release_dev (struct  ffs_data   * ffs_data )
3724+ static  void  ffs_release_dev (struct  ffs_dev   * ffs_dev )
37253725{
3726- 	struct  ffs_dev  * ffs_dev ;
3727- 
37283726	ENTER ();
37293727	ffs_dev_lock ();
37303728
3731- 	ffs_dev  =  ffs_data -> private_data ;
3732- 	if  (ffs_dev ) {
3729+ 	if  (ffs_dev  &&  ffs_dev -> mounted ) {
37333730		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+ 		}
37343735
37353736		if  (ffs_dev -> ffs_release_dev_callback )
37363737			ffs_dev -> ffs_release_dev_callback (ffs_dev );
@@ -3758,7 +3759,6 @@ static int ffs_ready(struct ffs_data *ffs)
37583759	}
37593760
37603761	ffs_obj -> desc_ready  =  true;
3761- 	ffs_obj -> ffs_data  =  ffs ;
37623762
37633763	if  (ffs_obj -> ffs_ready_callback ) {
37643764		ret  =  ffs_obj -> ffs_ready_callback (ffs );
@@ -3786,7 +3786,6 @@ static void ffs_closed(struct ffs_data *ffs)
37863786		goto done ;
37873787
37883788	ffs_obj -> desc_ready  =  false;
3789- 	ffs_obj -> ffs_data  =  NULL ;
37903789
37913790	if  (test_and_clear_bit (FFS_FL_CALL_CLOSED_CALLBACK , & ffs -> flags ) && 
37923791	    ffs_obj -> ffs_closed_callback )
0 commit comments