diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2010-09-03 11:15:41 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-10-22 13:21:28 -0400 |
commit | d8087427ccefc0b3364735b96274375246fd452c (patch) | |
tree | dcdb0485977e21799e9d101a501cfb885a4fe8d6 /drivers/usb/gadget/file_storage.c | |
parent | 10f47168721c0143f23e94eac2fc797aa643de39 (diff) |
USB: g_file_storage: don't generate automatic serial string
This patch (as1413) changes g_file_storage to avoid generating a bogus
automatic serial-number string descriptor. If the user doesn't provide
a valid serial number via a module parameter then a warning is logged
and the gadget won't have any serial string descriptor at all.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: David Brownell <david-b@pacbell.net>
CC: Michal Nazarewicz <m.nazarewicz@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget/file_storage.c')
-rw-r--r-- | drivers/usb/gadget/file_storage.c | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 132a1c0877bd..ce437f5dd674 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -89,6 +89,7 @@ | |||
89 | * Required if "removable" is not set, names of | 89 | * Required if "removable" is not set, names of |
90 | * the files or block devices used for | 90 | * the files or block devices used for |
91 | * backing storage | 91 | * backing storage |
92 | * serial=HHHH... Required serial number (string of hex chars) | ||
92 | * ro=b[,b...] Default false, booleans for read-only access | 93 | * ro=b[,b...] Default false, booleans for read-only access |
93 | * removable Default false, boolean for removable media | 94 | * removable Default false, boolean for removable media |
94 | * luns=N Default N = number of filenames, number of | 95 | * luns=N Default N = number of filenames, number of |
@@ -108,12 +109,11 @@ | |||
108 | * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID | 109 | * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID |
109 | * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID | 110 | * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID |
110 | * release=0xRRRR Override the USB release number (bcdDevice) | 111 | * release=0xRRRR Override the USB release number (bcdDevice) |
111 | * serial=HHHH... Override serial number (string of hex chars) | ||
112 | * buflen=N Default N=16384, buffer size used (will be | 112 | * buflen=N Default N=16384, buffer size used (will be |
113 | * rounded down to a multiple of | 113 | * rounded down to a multiple of |
114 | * PAGE_CACHE_SIZE) | 114 | * PAGE_CACHE_SIZE) |
115 | * | 115 | * |
116 | * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", | 116 | * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro", |
117 | * "removable", "luns", "nofua", "stall", and "cdrom" options are available; | 117 | * "removable", "luns", "nofua", "stall", and "cdrom" options are available; |
118 | * default values are used for everything else. | 118 | * default values are used for everything else. |
119 | * | 119 | * |
@@ -273,13 +273,10 @@ | |||
273 | 273 | ||
274 | #define DRIVER_DESC "File-backed Storage Gadget" | 274 | #define DRIVER_DESC "File-backed Storage Gadget" |
275 | #define DRIVER_NAME "g_file_storage" | 275 | #define DRIVER_NAME "g_file_storage" |
276 | /* DRIVER_VERSION must be at least 6 characters long, as it is used | 276 | #define DRIVER_VERSION "1 September 2010" |
277 | * to generate a fallback serial number. */ | ||
278 | #define DRIVER_VERSION "20 November 2008" | ||
279 | 277 | ||
280 | static char fsg_string_manufacturer[64]; | 278 | static char fsg_string_manufacturer[64]; |
281 | static const char fsg_string_product[] = DRIVER_DESC; | 279 | static const char fsg_string_product[] = DRIVER_DESC; |
282 | static char fsg_string_serial[13]; | ||
283 | static const char fsg_string_config[] = "Self-powered"; | 280 | static const char fsg_string_config[] = "Self-powered"; |
284 | static const char fsg_string_interface[] = "Mass Storage"; | 281 | static const char fsg_string_interface[] = "Mass Storage"; |
285 | 282 | ||
@@ -305,6 +302,7 @@ MODULE_LICENSE("Dual BSD/GPL"); | |||
305 | 302 | ||
306 | static struct { | 303 | static struct { |
307 | char *file[FSG_MAX_LUNS]; | 304 | char *file[FSG_MAX_LUNS]; |
305 | char *serial; | ||
308 | int ro[FSG_MAX_LUNS]; | 306 | int ro[FSG_MAX_LUNS]; |
309 | int nofua[FSG_MAX_LUNS]; | 307 | int nofua[FSG_MAX_LUNS]; |
310 | unsigned int num_filenames; | 308 | unsigned int num_filenames; |
@@ -321,7 +319,6 @@ static struct { | |||
321 | unsigned short vendor; | 319 | unsigned short vendor; |
322 | unsigned short product; | 320 | unsigned short product; |
323 | unsigned short release; | 321 | unsigned short release; |
324 | char *serial; | ||
325 | unsigned int buflen; | 322 | unsigned int buflen; |
326 | 323 | ||
327 | int transport_type; | 324 | int transport_type; |
@@ -346,6 +343,9 @@ module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames, | |||
346 | S_IRUGO); | 343 | S_IRUGO); |
347 | MODULE_PARM_DESC(file, "names of backing files or devices"); | 344 | MODULE_PARM_DESC(file, "names of backing files or devices"); |
348 | 345 | ||
346 | module_param_named(serial, mod_data.serial, charp, S_IRUGO); | ||
347 | MODULE_PARM_DESC(serial, "USB serial number"); | ||
348 | |||
349 | module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); | 349 | module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); |
350 | MODULE_PARM_DESC(ro, "true to force read-only"); | 350 | MODULE_PARM_DESC(ro, "true to force read-only"); |
351 | 351 | ||
@@ -365,9 +365,6 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); | |||
365 | module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); | 365 | module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); |
366 | MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); | 366 | MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); |
367 | 367 | ||
368 | module_param_named(serial, mod_data.serial, charp, S_IRUGO); | ||
369 | MODULE_PARM_DESC(serial, "USB serial number"); | ||
370 | |||
371 | /* In the non-TEST version, only the module parameters listed above | 368 | /* In the non-TEST version, only the module parameters listed above |
372 | * are available. */ | 369 | * are available. */ |
373 | #ifdef CONFIG_USB_FILE_STORAGE_TEST | 370 | #ifdef CONFIG_USB_FILE_STORAGE_TEST |
@@ -3214,7 +3211,6 @@ static int __init check_parameters(struct fsg_dev *fsg) | |||
3214 | { | 3211 | { |
3215 | int prot; | 3212 | int prot; |
3216 | int gcnum; | 3213 | int gcnum; |
3217 | int i; | ||
3218 | 3214 | ||
3219 | /* Store the default values */ | 3215 | /* Store the default values */ |
3220 | mod_data.transport_type = USB_PR_BULK; | 3216 | mod_data.transport_type = USB_PR_BULK; |
@@ -3310,38 +3306,22 @@ static int __init check_parameters(struct fsg_dev *fsg) | |||
3310 | if ((*ch < '0' || *ch > '9') && | 3306 | if ((*ch < '0' || *ch > '9') && |
3311 | (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ | 3307 | (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ |
3312 | WARNING(fsg, | 3308 | WARNING(fsg, |
3313 | "Invalid serial string character: %c; " | 3309 | "Invalid serial string character: %c\n", |
3314 | "Failing back to default\n", | ||
3315 | *ch); | 3310 | *ch); |
3316 | goto fill_serial; | 3311 | goto no_serial; |
3317 | } | 3312 | } |
3318 | } | 3313 | } |
3319 | if (len > 126 || | 3314 | if (len > 126 || |
3320 | (mod_data.transport_type == USB_PR_BULK && len < 12) || | 3315 | (mod_data.transport_type == USB_PR_BULK && len < 12) || |
3321 | (mod_data.transport_type != USB_PR_BULK && len > 12)) { | 3316 | (mod_data.transport_type != USB_PR_BULK && len > 12)) { |
3322 | WARNING(fsg, | 3317 | WARNING(fsg, "Invalid serial string length!\n"); |
3323 | "Invalid serial string length; " | 3318 | goto no_serial; |
3324 | "Failing back to default\n"); | ||
3325 | goto fill_serial; | ||
3326 | } | 3319 | } |
3327 | fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; | 3320 | fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; |
3328 | } else { | 3321 | } else { |
3329 | WARNING(fsg, | 3322 | WARNING(fsg, "No serial-number string provided!\n"); |
3330 | "Userspace failed to provide serial number; " | 3323 | no_serial: |
3331 | "Failing back to default\n"); | 3324 | device_desc.iSerialNumber = 0; |
3332 | fill_serial: | ||
3333 | /* Serial number not specified or invalid, make our own. | ||
3334 | * We just encode it from the driver version string, | ||
3335 | * 12 characters to comply with both CB[I] and BBB spec. | ||
3336 | * Warning : Two devices running the same kernel will have | ||
3337 | * the same fallback serial number. */ | ||
3338 | for (i = 0; i < 12; i += 2) { | ||
3339 | unsigned char c = DRIVER_VERSION[i / 2]; | ||
3340 | |||
3341 | if (!c) | ||
3342 | break; | ||
3343 | sprintf(&fsg_string_serial[i], "%02X", c); | ||
3344 | } | ||
3345 | } | 3325 | } |
3346 | 3326 | ||
3347 | return 0; | 3327 | return 0; |