[PATCH 07/11] [Storage] Using constant length buffers

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

 



Using version of stor_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 <mnazarewicz@xxxxxxxxxxx>
---
 drivers/usb/gadget/f_mass_storage.c |   34 +++++++++++++---------------------
 1 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 2a6d754..374b1cb 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -281,10 +281,11 @@ MODULE_LICENSE("Dual BSD/GPL");
 #include "epautoconf.c"

 #define STOR_DESCRIPTORS_DEVICE_STRINGS 1
+#define STOR_BUFFHD_STATIC_BUFFER       1
+#define STORAGE_BUFLEN ((u32)16384)

 #include "storage_common.c"

-#define STORAGE_BUFLEN ((u32)16384)

 /* Encapsulate the module parameter settings */

@@ -1931,7 +1932,7 @@ static int msf_send_status(struct msf *msf)
 		      SK(sd), ASC(sd), ASCQ(sd), sdinfo);
 	}

-	csw = bh->buf;
+	csw = (void*)bh->buf;

 	/* Store and send the Bulk-only CSW */
 	csw->Signature = cpu_to_le32(USB_BULK_CS_SIG);
@@ -2942,10 +2943,6 @@ static void /* __init_or_exit */ msf_unbind(struct usb_gadget *gadget)
 		complete(&msf->thread_notifier);
 	}

-	/* Free the data buffers */
-	for (i = 0; i < STORAGE_NUM_BUFFERS; ++i)
-		kfree(msf->common->buffhds[i].buf);
-
 	/* Free the request and buffer for endpoint 0 */
 	if (req) {
 		kfree(req->buf);
@@ -2991,7 +2988,7 @@ static int __init msf_bind(struct usb_gadget *gadget)
 	struct msf		*msf = the_msf;
 	int			rc;
 	int			i;
-	struct storage_lun		*curlun;
+	struct storage_lun	*curlun;
 	struct usb_ep		*ep;
 	struct usb_request	*req;
 	char			*pathbuf, *p;
@@ -3114,20 +3111,6 @@ static int __init msf_bind(struct usb_gadget *gadget)
 		goto out;
 	req->complete = msf_ep0_complete;

-	/* Allocate the data buffers */
-	for (i = 0; i < STORAGE_NUM_BUFFERS; ++i) {
-		struct stor_buffhd	*bh = &msf->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(STORAGE_BUFLEN, GFP_KERNEL);
-		if (!bh->buf)
-			goto out;
-		bh->next = bh + 1;
-	}
-	msf->common->buffhds[STORAGE_NUM_BUFFERS - 1].next = &msf->common->buffhds[0];
-
 	/* This should reflect the actual gadget power source */
 	usb_gadget_set_selfpowered(gadget);

@@ -3225,6 +3208,8 @@ static struct usb_gadget_driver		msf_driver = {
 static int __init msf_alloc(void)
 {
 	struct msf		*msf;
+	struct stor_buffhd	*bh;
+	unsigned		i;

 	msf = kzalloc(sizeof *msf, GFP_KERNEL);
 	if (!msf)
@@ -3236,6 +3221,13 @@ static int __init msf_alloc(void)
 		return -ENOMEM;
 	}

+	bh = msf->common->buffhds;
+	i = STORAGE_NUM_BUFFERS - 1;
+	do {
+		bh->next = bh + 1;
+	} while (++bh, --i);
+	bh->next = msf->common->buffhds;
+
 	spin_lock_init(&msf->lock);
 	init_rwsem(&msf->common->filesem);
 	kref_init(&msf->ref);

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