diff options
author | Michal Nazarewicz <m.nazarewicz@samsung.com> | 2009-10-28 11:57:21 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-12-11 14:55:19 -0500 |
commit | 606206c271722d613b99c737ce150f58f4485f41 (patch) | |
tree | a3db1e8291005b1bd76e260296d9fe815d232420 | |
parent | a41ae4180e5403a68469420806c318e1a0c32248 (diff) |
USB: g_mass_storage: constant length buffers used
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 run-time it is
not required for the field to be a pointer to void and allocating
space dynamically.
Signed-off-by: Michal Nazarewicz <m.nazarewicz@samsung.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/usb/gadget/f_mass_storage.c | 31 | ||||
-rw-r--r-- | drivers/usb/gadget/storage_common.c | 10 |
2 files changed, 21 insertions, 20 deletions
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 7750346b696c..b4ec76a3e37d 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -258,6 +258,7 @@ static const char fsg_string_interface[] = "Mass Storage"; | |||
258 | 258 | ||
259 | 259 | ||
260 | #define FSG_NO_INTR_EP 1 | 260 | #define FSG_NO_INTR_EP 1 |
261 | #define FSG_BUFFHD_STATIC_BUFFER 1 | ||
261 | 262 | ||
262 | #include "storage_common.c" | 263 | #include "storage_common.c" |
263 | 264 | ||
@@ -1894,9 +1895,8 @@ static int send_status(struct fsg_dev *fsg) | |||
1894 | SK(sd), ASC(sd), ASCQ(sd), sdinfo); | 1895 | SK(sd), ASC(sd), ASCQ(sd), sdinfo); |
1895 | } | 1896 | } |
1896 | 1897 | ||
1897 | |||
1898 | /* Store and send the Bulk-only CSW */ | 1898 | /* Store and send the Bulk-only CSW */ |
1899 | csw = bh->buf; | 1899 | csw = (void*)bh->buf; |
1900 | 1900 | ||
1901 | csw->Signature = cpu_to_le32(USB_BULK_CS_SIG); | 1901 | csw->Signature = cpu_to_le32(USB_BULK_CS_SIG); |
1902 | csw->Tag = fsg->tag; | 1902 | csw->Tag = fsg->tag; |
@@ -2808,10 +2808,6 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget) | |||
2808 | complete(&fsg->thread_notifier); | 2808 | complete(&fsg->thread_notifier); |
2809 | } | 2809 | } |
2810 | 2810 | ||
2811 | /* Free the data buffers */ | ||
2812 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) | ||
2813 | kfree(fsg->common->buffhds[i].buf); | ||
2814 | |||
2815 | /* Free the request and buffer for endpoint 0 */ | 2811 | /* Free the request and buffer for endpoint 0 */ |
2816 | if (req) { | 2812 | if (req) { |
2817 | kfree(req->buf); | 2813 | kfree(req->buf); |
@@ -2978,20 +2974,6 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
2978 | goto out; | 2974 | goto out; |
2979 | req->complete = ep0_complete; | 2975 | req->complete = ep0_complete; |
2980 | 2976 | ||
2981 | /* Allocate the data buffers */ | ||
2982 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | ||
2983 | struct fsg_buffhd *bh = &fsg->common->buffhds[i]; | ||
2984 | |||
2985 | /* Allocate for the bulk-in endpoint. We assume that | ||
2986 | * the buffer will also work with the bulk-out (and | ||
2987 | * interrupt-in) endpoint. */ | ||
2988 | bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL); | ||
2989 | if (!bh->buf) | ||
2990 | goto out; | ||
2991 | bh->next = bh + 1; | ||
2992 | } | ||
2993 | fsg->common->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->common->buffhds[0]; | ||
2994 | |||
2995 | /* This should reflect the actual gadget power source */ | 2977 | /* This should reflect the actual gadget power source */ |
2996 | usb_gadget_set_selfpowered(gadget); | 2978 | usb_gadget_set_selfpowered(gadget); |
2997 | 2979 | ||
@@ -3087,6 +3069,8 @@ static struct usb_gadget_driver fsg_driver = { | |||
3087 | static int __init fsg_alloc(void) | 3069 | static int __init fsg_alloc(void) |
3088 | { | 3070 | { |
3089 | struct fsg_dev *fsg; | 3071 | struct fsg_dev *fsg; |
3072 | struct fsg_buffhd *bh; | ||
3073 | unsigned i; | ||
3090 | 3074 | ||
3091 | fsg = kzalloc(sizeof *fsg, GFP_KERNEL); | 3075 | fsg = kzalloc(sizeof *fsg, GFP_KERNEL); |
3092 | if (!fsg) | 3076 | if (!fsg) |
@@ -3098,6 +3082,13 @@ static int __init fsg_alloc(void) | |||
3098 | return -ENOMEM; | 3082 | return -ENOMEM; |
3099 | } | 3083 | } |
3100 | 3084 | ||
3085 | bh = fsg->common->buffhds; | ||
3086 | i = FSG_NUM_BUFFERS - 1; | ||
3087 | do { | ||
3088 | bh->next = bh + 1; | ||
3089 | } while (++bh, --i); | ||
3090 | bh->next = fsg->common->buffhds; | ||
3091 | |||
3101 | spin_lock_init(&fsg->lock); | 3092 | spin_lock_init(&fsg->lock); |
3102 | init_rwsem(&fsg->common->filesem); | 3093 | init_rwsem(&fsg->common->filesem); |
3103 | init_completion(&fsg->thread_notifier); | 3094 | init_completion(&fsg->thread_notifier); |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index e76c8ced41e2..60bc696778c9 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -47,6 +47,12 @@ | |||
47 | * When FSG_NO_OTG is defined fsg_otg_desc won't be defined. | 47 | * When FSG_NO_OTG is defined fsg_otg_desc won't be defined. |
48 | */ | 48 | */ |
49 | 49 | ||
50 | /* | ||
51 | * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included | ||
52 | * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN | ||
53 | * characters rather then a pointer to void. | ||
54 | */ | ||
55 | |||
50 | 56 | ||
51 | #include <asm/unaligned.h> | 57 | #include <asm/unaligned.h> |
52 | 58 | ||
@@ -290,7 +296,11 @@ enum fsg_buffer_state { | |||
290 | }; | 296 | }; |
291 | 297 | ||
292 | struct fsg_buffhd { | 298 | struct fsg_buffhd { |
299 | #ifdef FSG_BUFFHD_STATIC_BUFFER | ||
300 | char buf[FSG_BUFLEN]; | ||
301 | #else | ||
293 | void *buf; | 302 | void *buf; |
303 | #endif | ||
294 | enum fsg_buffer_state state; | 304 | enum fsg_buffer_state state; |
295 | struct fsg_buffhd *next; | 305 | struct fsg_buffhd *next; |
296 | 306 | ||