All of lore.kernel.org
 help / color / mirror / Atom feed
* [V2,2/2] usb: gadget: storage: Remove reference counting
@ 2018-07-04  4:51 Jaejoong Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Jaejoong Kim @ 2018-07-04  4:51 UTC (permalink / raw)
  To: Michał Nazarewicz, Alan Stern, Felipe Balbi, Greg KH,
	Krzysztof Opasiak
  Cc: USB list

The kref used to be needed because sharing of fsg_common among multiple USB
function instances was handled by fsg. Now this is managed by configfs, we
don't need it anymore. So let's eliminate kref from this driver.

Signed-off-by: Jaejoong Kim <climbbb.kim@gmail.com>
---
Changes in V2:
  - Rewrite commit title & message.
  - Remove kref instead of removing unused kref EXPORT_SYMBOL (Alan and Michal)

V1 patches
  https://patchwork.kernel.org/patch/10463709/
  https://patchwork.kernel.org/patch/10463713/

 drivers/usb/gadget/function/f_mass_storage.c | 27 +++++----------------------
 drivers/usb/gadget/function/f_mass_storage.h |  4 ----
 2 files changed, 5 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 1b580eb..ca8a4b5 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -206,7 +206,6 @@
 #include <linux/fcntl.h>
 #include <linux/file.h>
 #include <linux/fs.h>
-#include <linux/kref.h>
 #include <linux/kthread.h>
 #include <linux/sched/signal.h>
 #include <linux/limits.h>
@@ -312,8 +311,6 @@ struct fsg_common {
 	void			*private_data;
 
 	char inquiry_string[INQUIRY_STRING_LEN];
-
-	struct kref		ref;
 };
 
 struct fsg_dev {
@@ -2551,25 +2548,11 @@ static DEVICE_ATTR(file, 0, file_show, file_store);
 
 /****************************** FSG COMMON ******************************/
 
-static void fsg_common_release(struct kref *ref);
-
 static void fsg_lun_release(struct device *dev)
 {
 	/* Nothing needs to be done */
 }
 
-void fsg_common_get(struct fsg_common *common)
-{
-	kref_get(&common->ref);
-}
-EXPORT_SYMBOL_GPL(fsg_common_get);
-
-void fsg_common_put(struct fsg_common *common)
-{
-	kref_put(&common->ref, fsg_common_release);
-}
-EXPORT_SYMBOL_GPL(fsg_common_put);
-
 static struct fsg_common *fsg_common_setup(struct fsg_common *common)
 {
 	if (!common) {
@@ -2582,7 +2565,6 @@ static struct fsg_common *fsg_common_setup(struct fsg_common *common)
 	}
 	init_rwsem(&common->filesem);
 	spin_lock_init(&common->lock);
-	kref_init(&common->ref);
 	init_completion(&common->thread_notifier);
 	init_waitqueue_head(&common->io_wait);
 	init_waitqueue_head(&common->fsg_wait);
@@ -2870,9 +2852,8 @@ void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
 }
 EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string);
 
-static void fsg_common_release(struct kref *ref)
+static void fsg_common_release(struct fsg_common *common)
 {
-	struct fsg_common *common = container_of(ref, struct fsg_common, ref);
 	int i;
 
 	/* If the thread isn't already dead, tell it to exit now */
@@ -3346,7 +3327,7 @@ static void fsg_free_inst(struct usb_function_instance *fi)
 	struct fsg_opts *opts;
 
 	opts = fsg_opts_from_func_inst(fi);
-	fsg_common_put(opts->common);
+	fsg_common_release(opts->common);
 	kfree(opts);
 }
 
@@ -3370,7 +3351,7 @@ static struct usb_function_instance *fsg_alloc_inst(void)
 	rc = fsg_common_set_num_buffers(opts->common,
 					CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS);
 	if (rc)
-		goto release_opts;
+		goto release_common;
 
 	pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
 
@@ -3393,6 +3374,8 @@ static struct usb_function_instance *fsg_alloc_inst(void)
 
 release_buffers:
 	fsg_common_free_buffers(opts->common);
+release_common:
+	kfree(opts->common);
 release_opts:
 	kfree(opts);
 	return ERR_PTR(rc);
diff --git a/drivers/usb/gadget/function/f_mass_storage.h b/drivers/usb/gadget/function/f_mass_storage.h
index 58857fc..3b8c4ce 100644
--- a/drivers/usb/gadget/function/f_mass_storage.h
+++ b/drivers/usb/gadget/function/f_mass_storage.h
@@ -115,10 +115,6 @@ fsg_opts_from_func_inst(const struct usb_function_instance *fi)
 	return container_of(fi, struct fsg_opts, func_inst);
 }
 
-void fsg_common_get(struct fsg_common *common);
-
-void fsg_common_put(struct fsg_common *common);
-
 void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
 
 int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [V2,2/2] usb: gadget: storage: Remove reference counting
@ 2018-07-05 14:09 Alan Stern
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Stern @ 2018-07-05 14:09 UTC (permalink / raw)
  To: Jaejoong Kim
  Cc: Michał Nazarewicz, Felipe Balbi, Greg KH, Krzysztof Opasiak,
	USB list

On Wed, 4 Jul 2018, Jaejoong Kim wrote:

> The kref used to be needed because sharing of fsg_common among multiple USB
> function instances was handled by fsg. Now this is managed by configfs, we
> don't need it anymore. So let's eliminate kref from this driver.
> 
> Signed-off-by: Jaejoong Kim <climbbb.kim@gmail.com>

Acked-by: Alan Stern <stern@rowland.harvard.edu>

> ---
> Changes in V2:
>   - Rewrite commit title & message.
>   - Remove kref instead of removing unused kref EXPORT_SYMBOL (Alan and Michal)
> 
> V1 patches
>   https://patchwork.kernel.org/patch/10463709/
>   https://patchwork.kernel.org/patch/10463713/
> 
>  drivers/usb/gadget/function/f_mass_storage.c | 27 +++++----------------------
>  drivers/usb/gadget/function/f_mass_storage.h |  4 ----
>  2 files changed, 5 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
> index 1b580eb..ca8a4b5 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.c
> +++ b/drivers/usb/gadget/function/f_mass_storage.c
> @@ -206,7 +206,6 @@
>  #include <linux/fcntl.h>
>  #include <linux/file.h>
>  #include <linux/fs.h>
> -#include <linux/kref.h>
>  #include <linux/kthread.h>
>  #include <linux/sched/signal.h>
>  #include <linux/limits.h>
> @@ -312,8 +311,6 @@ struct fsg_common {
>  	void			*private_data;
>  
>  	char inquiry_string[INQUIRY_STRING_LEN];
> -
> -	struct kref		ref;
>  };
>  
>  struct fsg_dev {
> @@ -2551,25 +2548,11 @@ static DEVICE_ATTR(file, 0, file_show, file_store);
>  
>  /****************************** FSG COMMON ******************************/
>  
> -static void fsg_common_release(struct kref *ref);
> -
>  static void fsg_lun_release(struct device *dev)
>  {
>  	/* Nothing needs to be done */
>  }
>  
> -void fsg_common_get(struct fsg_common *common)
> -{
> -	kref_get(&common->ref);
> -}
> -EXPORT_SYMBOL_GPL(fsg_common_get);
> -
> -void fsg_common_put(struct fsg_common *common)
> -{
> -	kref_put(&common->ref, fsg_common_release);
> -}
> -EXPORT_SYMBOL_GPL(fsg_common_put);
> -
>  static struct fsg_common *fsg_common_setup(struct fsg_common *common)
>  {
>  	if (!common) {
> @@ -2582,7 +2565,6 @@ static struct fsg_common *fsg_common_setup(struct fsg_common *common)
>  	}
>  	init_rwsem(&common->filesem);
>  	spin_lock_init(&common->lock);
> -	kref_init(&common->ref);
>  	init_completion(&common->thread_notifier);
>  	init_waitqueue_head(&common->io_wait);
>  	init_waitqueue_head(&common->fsg_wait);
> @@ -2870,9 +2852,8 @@ void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
>  }
>  EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string);
>  
> -static void fsg_common_release(struct kref *ref)
> +static void fsg_common_release(struct fsg_common *common)
>  {
> -	struct fsg_common *common = container_of(ref, struct fsg_common, ref);
>  	int i;
>  
>  	/* If the thread isn't already dead, tell it to exit now */
> @@ -3346,7 +3327,7 @@ static void fsg_free_inst(struct usb_function_instance *fi)
>  	struct fsg_opts *opts;
>  
>  	opts = fsg_opts_from_func_inst(fi);
> -	fsg_common_put(opts->common);
> +	fsg_common_release(opts->common);
>  	kfree(opts);
>  }
>  
> @@ -3370,7 +3351,7 @@ static struct usb_function_instance *fsg_alloc_inst(void)
>  	rc = fsg_common_set_num_buffers(opts->common,
>  					CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS);
>  	if (rc)
> -		goto release_opts;
> +		goto release_common;
>  
>  	pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
>  
> @@ -3393,6 +3374,8 @@ static struct usb_function_instance *fsg_alloc_inst(void)
>  
>  release_buffers:
>  	fsg_common_free_buffers(opts->common);
> +release_common:
> +	kfree(opts->common);
>  release_opts:
>  	kfree(opts);
>  	return ERR_PTR(rc);
> diff --git a/drivers/usb/gadget/function/f_mass_storage.h b/drivers/usb/gadget/function/f_mass_storage.h
> index 58857fc..3b8c4ce 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.h
> +++ b/drivers/usb/gadget/function/f_mass_storage.h
> @@ -115,10 +115,6 @@ fsg_opts_from_func_inst(const struct usb_function_instance *fi)
>  	return container_of(fi, struct fsg_opts, func_inst);
>  }
>  
> -void fsg_common_get(struct fsg_common *common);
> -
> -void fsg_common_put(struct fsg_common *common);
> -
>  void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
>  
>  int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [V2,2/2] usb: gadget: storage: Remove reference counting
@ 2018-07-05  7:33 Michał Nazarewicz
  0 siblings, 0 replies; 3+ messages in thread
From: Michał Nazarewicz @ 2018-07-05  7:33 UTC (permalink / raw)
  To: Jaejoong Kim
  Cc: Alan Stern, Felipe Balbi, Greg KH, Krzysztof Opasiak, USB list

Acked-by: Michal Nazarewicz <mina86@mina86.com>

2018-07-04 5:51 GMT+01:00 Jaejoong Kim <climbbb.kim@gmail.com>:
> The kref used to be needed because sharing of fsg_common among multiple USB
> function instances was handled by fsg. Now this is managed by configfs, we
> don't need it anymore. So let's eliminate kref from this driver.
>
> Signed-off-by: Jaejoong Kim <climbbb.kim@gmail.com>
> ---
> Changes in V2:
>   - Rewrite commit title & message.
>   - Remove kref instead of removing unused kref EXPORT_SYMBOL (Alan and Michal)
>
> V1 patches
>   https://patchwork.kernel.org/patch/10463709/
>   https://patchwork.kernel.org/patch/10463713/
>
>  drivers/usb/gadget/function/f_mass_storage.c | 27 +++++----------------------
>  drivers/usb/gadget/function/f_mass_storage.h |  4 ----
>  2 files changed, 5 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
> index 1b580eb..ca8a4b5 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.c
> +++ b/drivers/usb/gadget/function/f_mass_storage.c
> @@ -206,7 +206,6 @@
>  #include <linux/fcntl.h>
>  #include <linux/file.h>
>  #include <linux/fs.h>
> -#include <linux/kref.h>
>  #include <linux/kthread.h>
>  #include <linux/sched/signal.h>
>  #include <linux/limits.h>
> @@ -312,8 +311,6 @@ struct fsg_common {
>         void                    *private_data;
>
>         char inquiry_string[INQUIRY_STRING_LEN];
> -
> -       struct kref             ref;
>  };
>
>  struct fsg_dev {
> @@ -2551,25 +2548,11 @@ static DEVICE_ATTR(file, 0, file_show, file_store);
>
>  /****************************** FSG COMMON ******************************/
>
> -static void fsg_common_release(struct kref *ref);
> -
>  static void fsg_lun_release(struct device *dev)
>  {
>         /* Nothing needs to be done */
>  }
>
> -void fsg_common_get(struct fsg_common *common)
> -{
> -       kref_get(&common->ref);
> -}
> -EXPORT_SYMBOL_GPL(fsg_common_get);
> -
> -void fsg_common_put(struct fsg_common *common)
> -{
> -       kref_put(&common->ref, fsg_common_release);
> -}
> -EXPORT_SYMBOL_GPL(fsg_common_put);
> -
>  static struct fsg_common *fsg_common_setup(struct fsg_common *common)
>  {
>         if (!common) {
> @@ -2582,7 +2565,6 @@ static struct fsg_common *fsg_common_setup(struct fsg_common *common)
>         }
>         init_rwsem(&common->filesem);
>         spin_lock_init(&common->lock);
> -       kref_init(&common->ref);
>         init_completion(&common->thread_notifier);
>         init_waitqueue_head(&common->io_wait);
>         init_waitqueue_head(&common->fsg_wait);
> @@ -2870,9 +2852,8 @@ void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
>  }
>  EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string);
>
> -static void fsg_common_release(struct kref *ref)
> +static void fsg_common_release(struct fsg_common *common)
>  {
> -       struct fsg_common *common = container_of(ref, struct fsg_common, ref);
>         int i;
>
>         /* If the thread isn't already dead, tell it to exit now */
> @@ -3346,7 +3327,7 @@ static void fsg_free_inst(struct usb_function_instance *fi)
>         struct fsg_opts *opts;
>
>         opts = fsg_opts_from_func_inst(fi);
> -       fsg_common_put(opts->common);
> +       fsg_common_release(opts->common);
>         kfree(opts);
>  }
>
> @@ -3370,7 +3351,7 @@ static struct usb_function_instance *fsg_alloc_inst(void)
>         rc = fsg_common_set_num_buffers(opts->common,
>                                         CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS);
>         if (rc)
> -               goto release_opts;
> +               goto release_common;
>
>         pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
>
> @@ -3393,6 +3374,8 @@ static struct usb_function_instance *fsg_alloc_inst(void)
>
>  release_buffers:
>         fsg_common_free_buffers(opts->common);
> +release_common:
> +       kfree(opts->common);
>  release_opts:
>         kfree(opts);
>         return ERR_PTR(rc);
> diff --git a/drivers/usb/gadget/function/f_mass_storage.h b/drivers/usb/gadget/function/f_mass_storage.h
> index 58857fc..3b8c4ce 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.h
> +++ b/drivers/usb/gadget/function/f_mass_storage.h
> @@ -115,10 +115,6 @@ fsg_opts_from_func_inst(const struct usb_function_instance *fi)
>         return container_of(fi, struct fsg_opts, func_inst);
>  }
>
> -void fsg_common_get(struct fsg_common *common);
> -
> -void fsg_common_put(struct fsg_common *common);
> -
>  void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
>
>  int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
> --
> 2.7.4
>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-05 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-04  4:51 [V2,2/2] usb: gadget: storage: Remove reference counting Jaejoong Kim
2018-07-05  7:33 Michał Nazarewicz
2018-07-05 14:09 Alan Stern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.