[PATCH v3 03/42] usb/gadget: allow not clearing the memory for struct fsg_common

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch is needed to prepare for using the new function interface.

The memory for struct fsg_common can either be provided
by the mass storage user, or it can be allocated by mass storage.
With the new function interface it will be provided by the mass storage user.
The new function interface uses "function instances" and "functions"
(@Sebastian: I really don't like this naming scheme because it means a
function instance IS NOT an instance of struct usb_function).
The "function instance" is allocated by the function code (e.g. f_mass_storage)
which in fact can allocate a greater structure containing a struct
usb_function_instance and return the pointer to the said component.
It is the well known "container_of" technique: when using the new
function interface, after the struct usb_function_instance is obtained
with usb_get_function_instance("mass_storage"), the struct fsg_common
is reached with container_of. Later, fsg_common_init needs to be called,
and it used to clear the entire struct with memset. Now it is no good,
since it clears the component struct usb_function_instance which already
contains important data. This patch adds an option not to clear
the struct, which in this case has been allocated with kzalloc anyway.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
 drivers/usb/gadget/f_mass_storage.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index e86042a..1cf480f 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2640,9 +2640,9 @@ static inline int fsg_num_buffers_validate(void)
 	return -EINVAL;
 }
 
-static struct fsg_common *fsg_common_init(struct fsg_common *common,
+static struct fsg_common *fsg_common_init_memset(struct fsg_common *common,
 					  struct usb_composite_dev *cdev,
-					  struct fsg_config *cfg)
+					  struct fsg_config *cfg, bool zero)
 {
 	struct usb_gadget *gadget = cdev->gadget;
 	struct fsg_buffhd *bh;
@@ -2669,7 +2669,8 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
 			return ERR_PTR(-ENOMEM);
 		common->free_storage_on_release = 1;
 	} else {
-		memset(common, 0, sizeof *common);
+		if (zero)
+			memset(common, 0, sizeof *common);
 		common->free_storage_on_release = 0;
 	}
 
@@ -2846,6 +2847,13 @@ error_release:
 	return ERR_PTR(rc);
 }
 
+static struct fsg_common *fsg_common_init(struct fsg_common *common,
+					  struct usb_composite_dev *cdev,
+					  struct fsg_config *cfg)
+{
+	return fsg_common_init_memset(common, cdev, cfg, true);
+}
+
 static void fsg_common_release(struct kref *ref)
 {
 	struct fsg_common *common = container_of(ref, struct fsg_common, ref);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux