The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] USB: f_mass_storage: dynamic buffers for better alignment
@ 2010-03-15 10:09 Michal Nazarewicz
  2010-03-15 18:10 ` Felipe Balbi
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Nazarewicz @ 2010-03-15 10:09 UTC (permalink / raw)
  To: linux-usb, David Brownell
  Cc: gregkh, linux-kernel, Marek Szyprowski, Michal Nazarewicz,
	Kyungmin Park

"Static" buffers in fsg_buffhd structure (ie. fields which are arrays
rather then pointers to dynamically allocated memory) are not aligned
to any "big" power of two which may lead to poor DMA performance
(copying "by hand" of head or tail) or no DMA at all even if otherwise
hardware supports it.

Therefore, this patch makes mass storage function use kmalloc()ed
buffers which are (because of their size) page aligned (which should
be enough for any hardware).

Signed-off-by: Michal Nazarewicz <m.nazarewicz@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/usb/gadget/f_mass_storage.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 84f6491..8945573 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -302,7 +302,6 @@ static const char fsg_string_interface[] = "Mass Storage";
 
 
 #define FSG_NO_INTR_EP 1
-#define FSG_BUFFHD_STATIC_BUFFER 1
 #define FSG_NO_DEVICE_STRINGS    1
 #define FSG_NO_OTG               1
 #define FSG_NO_INTR_EP           1
@@ -2747,13 +2746,18 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
 
 
 	/* Data buffers cyclic list */
-	/* Buffers in buffhds are static -- no need for additional
-	 * allocation. */
 	bh = common->buffhds;
-	i = FSG_NUM_BUFFERS - 1;
-	do {
+	i = FSG_NUM_BUFFERS;
+	for (i = FSG_NUM_BUFFERS;; ++bh) {
+		bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
+		if (!bh->buf) {
+			rc = -ENOMEM;
+			goto error_release;
+		}
+		if (!--i)
+			break;
 		bh->next = bh + 1;
-	} while (++bh, --i);
+	}
 	bh->next = common->buffhds;
 
 
@@ -2861,6 +2865,7 @@ static void fsg_common_release(struct kref *ref)
 		container_of(ref, struct fsg_common, ref);
 	unsigned i = common->nluns;
 	struct fsg_lun *lun = common->luns;
+	struct fsg_buffhd *bh;
 
 	/* If the thread isn't already dead, tell it to exit now */
 	if (common->state != FSG_STATE_TERMINATED) {
@@ -2882,6 +2887,13 @@ static void fsg_common_release(struct kref *ref)
 	}
 
 	kfree(common->luns);
+
+	i = FSG_NUM_BUFFERS;
+	bh = common->buffhds;
+	do {
+		kfree(bh->buf);
+	} while (++bh, --i);
+
 	if (common->free_storage_on_release)
 		kfree(common);
 }
-- 
1.6.5


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

end of thread, other threads:[~2010-03-15 20:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-15 10:09 [PATCH] USB: f_mass_storage: dynamic buffers for better alignment Michal Nazarewicz
2010-03-15 18:10 ` Felipe Balbi
2010-03-15 19:20   ` Michał Nazarewicz
2010-03-15 19:28     ` Felipe Balbi
2010-03-15 19:43       ` Michał Nazarewicz
2010-03-15 20:28         ` Michal Nazarewicz
2010-03-15 20:38         ` [PATCHv3] " Michal Nazarewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox