[PATCH 14/24] [Storage] Using constant length buffers

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

 



Using version of fsg_buffhd structure with buf field being an
array of characters with predefined size.  Since mass storage
function does not define changing buffer size on runtime it is
not required for the field to be a pointer to void and allocating
space dynamically.

Signed-off-by: Michal Nazarewicz <m.nazarewicz@xxxxxxxxxxx>
---
 drivers/usb/gadget/f_mass_storage.c |   32 ++++++++++++--------------------
 drivers/usb/gadget/storage_common.c |   10 ++++++++++
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 9896f57..120e891 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -265,6 +265,8 @@ static const char fsg_string_config[] = "Self-powered";
 static const char fsg_string_interface[] = "Mass Storage";
 
 
+#define FSG_BUFFHD_STATIC_BUFFER 1
+
 #include "storage_common.c"
 
 
@@ -1873,9 +1875,8 @@ static int send_status(struct fsg_dev *fsg)
 				SK(sd), ASC(sd), ASCQ(sd), sdinfo);
 	}
 
-
 	/* Store and send the Bulk-only CSW */
-	csw = bh->buf;
+	csw = (void*)bh->buf;
 
 	csw->Signature = cpu_to_le32(USB_BULK_CS_SIG);
 	csw->Tag = fsg->tag;
@@ -2794,10 +2795,6 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
 		complete(&fsg->thread_notifier);
 	}
 
-	/* Free the data buffers */
-	for (i = 0; i < FSG_NUM_BUFFERS; ++i)
-		kfree(fsg->common->buffhds[i].buf);
-
 	/* Free the request and buffer for endpoint 0 */
 	if (req) {
 		kfree(req->buf);
@@ -2965,20 +2962,6 @@ static int __init fsg_bind(struct usb_gadget *gadget)
 		goto out;
 	req->complete = ep0_complete;
 
-	/* Allocate the data buffers */
-	for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
-		struct fsg_buffhd	*bh = &fsg->common->buffhds[i];
-
-		/* Allocate for the bulk-in endpoint.  We assume that
-		 * the buffer will also work with the bulk-out (and
-		 * interrupt-in) endpoint. */
-		bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
-		if (!bh->buf)
-			goto out;
-		bh->next = bh + 1;
-	}
-	fsg->common->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->common->buffhds[0];
-
 	/* This should reflect the actual gadget power source */
 	usb_gadget_set_selfpowered(gadget);
 
@@ -3074,6 +3057,8 @@ static struct usb_gadget_driver		fsg_driver = {
 static int __init fsg_alloc(void)
 {
 	struct fsg_dev		*fsg;
+	struct fsg_buffhd	*bh;
+	unsigned		i;
 
 	fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
 	if (!fsg)
@@ -3085,6 +3070,13 @@ static int __init fsg_alloc(void)
 		return -ENOMEM;
 	}
 
+	bh = fsg->common->buffhds;
+	i = FSG_NUM_BUFFERS - 1;
+	do {
+		bh->next = bh + 1;
+	} while (++bh, --i);
+	bh->next = fsg->common->buffhds;
+
 	spin_lock_init(&fsg->lock);
 	init_rwsem(&fsg->common->filesem);
 	kref_init(&fsg->ref);
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 533ca6f..2b3ac40 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -33,6 +33,12 @@
  * macro is defined prior to including this file.
  */
 
+/*
+ * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included
+ * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN
+ * characters rather then a pointer to void.
+ */
+
 
 #include <asm/unaligned.h>
 
@@ -260,7 +266,11 @@ enum fsg_buffer_state {
 };
 
 struct fsg_buffhd {
+#ifdef FSG_BUFFHD_STATIC_BUFFER
+	char				buf[FSG_BUFLEN];
+#else
 	void				*buf;
+#endif
 	enum fsg_buffer_state		state;
 	struct fsg_buffhd		*next;
 
-- 
1.6.3.3


--
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