Commit d8087427 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

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: default avatarAlan Stern <stern@rowland.harvard.edu>
Acked-by: default avatarDavid Brownell <david-b@pacbell.net>
CC: Michal Nazarewicz <m.nazarewicz@samsung.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 10f47168
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
* Required if "removable" is not set, names of * Required if "removable" is not set, names of
* the files or block devices used for * the files or block devices used for
* backing storage * backing storage
* serial=HHHH... Required serial number (string of hex chars)
* ro=b[,b...] Default false, booleans for read-only access * ro=b[,b...] Default false, booleans for read-only access
* removable Default false, boolean for removable media * removable Default false, boolean for removable media
* luns=N Default N = number of filenames, number of * luns=N Default N = number of filenames, number of
...@@ -108,12 +109,11 @@ ...@@ -108,12 +109,11 @@
* vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
* product=0xPPPP Default 0xa4a5 (FSG), USB Product ID * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
* release=0xRRRR Override the USB release number (bcdDevice) * release=0xRRRR Override the USB release number (bcdDevice)
* serial=HHHH... Override serial number (string of hex chars)
* buflen=N Default N=16384, buffer size used (will be * buflen=N Default N=16384, buffer size used (will be
* rounded down to a multiple of * rounded down to a multiple of
* PAGE_CACHE_SIZE) * PAGE_CACHE_SIZE)
* *
* If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
* "removable", "luns", "nofua", "stall", and "cdrom" options are available; * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
* default values are used for everything else. * default values are used for everything else.
* *
...@@ -273,13 +273,10 @@ ...@@ -273,13 +273,10 @@
#define DRIVER_DESC "File-backed Storage Gadget" #define DRIVER_DESC "File-backed Storage Gadget"
#define DRIVER_NAME "g_file_storage" #define DRIVER_NAME "g_file_storage"
/* DRIVER_VERSION must be at least 6 characters long, as it is used #define DRIVER_VERSION "1 September 2010"
* to generate a fallback serial number. */
#define DRIVER_VERSION "20 November 2008"
static char fsg_string_manufacturer[64]; static char fsg_string_manufacturer[64];
static const char fsg_string_product[] = DRIVER_DESC; static const char fsg_string_product[] = DRIVER_DESC;
static char fsg_string_serial[13];
static const char fsg_string_config[] = "Self-powered"; static const char fsg_string_config[] = "Self-powered";
static const char fsg_string_interface[] = "Mass Storage"; static const char fsg_string_interface[] = "Mass Storage";
...@@ -305,6 +302,7 @@ MODULE_LICENSE("Dual BSD/GPL"); ...@@ -305,6 +302,7 @@ MODULE_LICENSE("Dual BSD/GPL");
static struct { static struct {
char *file[FSG_MAX_LUNS]; char *file[FSG_MAX_LUNS];
char *serial;
int ro[FSG_MAX_LUNS]; int ro[FSG_MAX_LUNS];
int nofua[FSG_MAX_LUNS]; int nofua[FSG_MAX_LUNS];
unsigned int num_filenames; unsigned int num_filenames;
...@@ -321,7 +319,6 @@ static struct { ...@@ -321,7 +319,6 @@ static struct {
unsigned short vendor; unsigned short vendor;
unsigned short product; unsigned short product;
unsigned short release; unsigned short release;
char *serial;
unsigned int buflen; unsigned int buflen;
int transport_type; int transport_type;
...@@ -346,6 +343,9 @@ module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames, ...@@ -346,6 +343,9 @@ module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
S_IRUGO); S_IRUGO);
MODULE_PARM_DESC(file, "names of backing files or devices"); MODULE_PARM_DESC(file, "names of backing files or devices");
module_param_named(serial, mod_data.serial, charp, S_IRUGO);
MODULE_PARM_DESC(serial, "USB serial number");
module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
MODULE_PARM_DESC(ro, "true to force read-only"); MODULE_PARM_DESC(ro, "true to force read-only");
...@@ -365,9 +365,6 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); ...@@ -365,9 +365,6 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
module_param_named(serial, mod_data.serial, charp, S_IRUGO);
MODULE_PARM_DESC(serial, "USB serial number");
/* In the non-TEST version, only the module parameters listed above /* In the non-TEST version, only the module parameters listed above
* are available. */ * are available. */
#ifdef CONFIG_USB_FILE_STORAGE_TEST #ifdef CONFIG_USB_FILE_STORAGE_TEST
...@@ -3214,7 +3211,6 @@ static int __init check_parameters(struct fsg_dev *fsg) ...@@ -3214,7 +3211,6 @@ static int __init check_parameters(struct fsg_dev *fsg)
{ {
int prot; int prot;
int gcnum; int gcnum;
int i;
/* Store the default values */ /* Store the default values */
mod_data.transport_type = USB_PR_BULK; mod_data.transport_type = USB_PR_BULK;
...@@ -3310,38 +3306,22 @@ static int __init check_parameters(struct fsg_dev *fsg) ...@@ -3310,38 +3306,22 @@ static int __init check_parameters(struct fsg_dev *fsg)
if ((*ch < '0' || *ch > '9') && if ((*ch < '0' || *ch > '9') &&
(*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
WARNING(fsg, WARNING(fsg,
"Invalid serial string character: %c; " "Invalid serial string character: %c\n",
"Failing back to default\n",
*ch); *ch);
goto fill_serial; goto no_serial;
} }
} }
if (len > 126 || if (len > 126 ||
(mod_data.transport_type == USB_PR_BULK && len < 12) || (mod_data.transport_type == USB_PR_BULK && len < 12) ||
(mod_data.transport_type != USB_PR_BULK && len > 12)) { (mod_data.transport_type != USB_PR_BULK && len > 12)) {
WARNING(fsg, WARNING(fsg, "Invalid serial string length!\n");
"Invalid serial string length; " goto no_serial;
"Failing back to default\n");
goto fill_serial;
} }
fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
} else { } else {
WARNING(fsg, WARNING(fsg, "No serial-number string provided!\n");
"Userspace failed to provide serial number; " no_serial:
"Failing back to default\n"); device_desc.iSerialNumber = 0;
fill_serial:
/* Serial number not specified or invalid, make our own.
* We just encode it from the driver version string,
* 12 characters to comply with both CB[I] and BBB spec.
* Warning : Two devices running the same kernel will have
* the same fallback serial number. */
for (i = 0; i < 12; i += 2) {
unsigned char c = DRIVER_VERSION[i / 2];
if (!c)
break;
sprintf(&fsg_string_serial[i], "%02X", c);
}
} }
return 0; return 0;
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
* be defined (each of type pointer to char): * be defined (each of type pointer to char):
* - fsg_string_manufacturer -- name of the manufacturer * - fsg_string_manufacturer -- name of the manufacturer
* - fsg_string_product -- name of the product * - fsg_string_product -- name of the product
* - fsg_string_serial -- product's serial
* - fsg_string_config -- name of the configuration * - fsg_string_config -- name of the configuration
* - fsg_string_interface -- name of the interface * - fsg_string_interface -- name of the interface
* The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
...@@ -552,7 +551,7 @@ static struct usb_string fsg_strings[] = { ...@@ -552,7 +551,7 @@ static struct usb_string fsg_strings[] = {
#ifndef FSG_NO_DEVICE_STRINGS #ifndef FSG_NO_DEVICE_STRINGS
{FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
{FSG_STRING_PRODUCT, fsg_string_product}, {FSG_STRING_PRODUCT, fsg_string_product},
{FSG_STRING_SERIAL, fsg_string_serial}, {FSG_STRING_SERIAL, ""},
{FSG_STRING_CONFIG, fsg_string_config}, {FSG_STRING_CONFIG, fsg_string_config},
#endif #endif
{FSG_STRING_INTERFACE, fsg_string_interface}, {FSG_STRING_INTERFACE, fsg_string_interface},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment