From: Alan Stern Date: Fri, 3 Sep 2010 15:15:41 +0000 (-0400) Subject: USB: g_file_storage: don't generate automatic serial string X-Git-Tag: MMI-PSA29.97-13-9~22001^2~114 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d8087427ccefc0b3364735b96274375246fd452c;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git 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 Acked-by: David Brownell CC: Michal Nazarewicz Signed-off-by: Greg Kroah-Hartman --- 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 @@ * Required if "removable" is not set, names of * the files or block devices used for * backing storage + * serial=HHHH... Required serial number (string of hex chars) * ro=b[,b...] Default false, booleans for read-only access * removable Default false, boolean for removable media * luns=N Default N = number of filenames, number of @@ -108,12 +109,11 @@ * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID * 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 * rounded down to a multiple of * 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; * default values are used for everything else. * @@ -273,13 +273,10 @@ #define DRIVER_DESC "File-backed Storage Gadget" #define DRIVER_NAME "g_file_storage" -/* DRIVER_VERSION must be at least 6 characters long, as it is used - * to generate a fallback serial number. */ -#define DRIVER_VERSION "20 November 2008" +#define DRIVER_VERSION "1 September 2010" static char fsg_string_manufacturer[64]; 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_interface[] = "Mass Storage"; @@ -305,6 +302,7 @@ MODULE_LICENSE("Dual BSD/GPL"); static struct { char *file[FSG_MAX_LUNS]; + char *serial; int ro[FSG_MAX_LUNS]; int nofua[FSG_MAX_LUNS]; unsigned int num_filenames; @@ -321,7 +319,6 @@ static struct { unsigned short vendor; unsigned short product; unsigned short release; - char *serial; unsigned int buflen; int transport_type; @@ -346,6 +343,9 @@ module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames, S_IRUGO); 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_PARM_DESC(ro, "true to force read-only"); @@ -365,9 +365,6 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); 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 * are available. */ #ifdef CONFIG_USB_FILE_STORAGE_TEST @@ -3214,7 +3211,6 @@ static int __init check_parameters(struct fsg_dev *fsg) { int prot; int gcnum; - int i; /* Store the default values */ mod_data.transport_type = USB_PR_BULK; @@ -3310,38 +3306,22 @@ static int __init check_parameters(struct fsg_dev *fsg) if ((*ch < '0' || *ch > '9') && (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ WARNING(fsg, - "Invalid serial string character: %c; " - "Failing back to default\n", + "Invalid serial string character: %c\n", *ch); - goto fill_serial; + goto no_serial; } } if (len > 126 || (mod_data.transport_type == USB_PR_BULK && len < 12) || (mod_data.transport_type != USB_PR_BULK && len > 12)) { - WARNING(fsg, - "Invalid serial string length; " - "Failing back to default\n"); - goto fill_serial; + WARNING(fsg, "Invalid serial string length!\n"); + goto no_serial; } fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; } else { - WARNING(fsg, - "Userspace failed to provide serial number; " - "Failing back to default\n"); -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); - } + WARNING(fsg, "No serial-number string provided!\n"); + no_serial: + device_desc.iSerialNumber = 0; } return 0; diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 484acfb1a7c5..d7856c599d5a 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -26,7 +26,6 @@ * be defined (each of type pointer to char): * - fsg_string_manufacturer -- name of the manufacturer * - fsg_string_product -- name of the product - * - fsg_string_serial -- product's serial * - fsg_string_config -- name of the configuration * - fsg_string_interface -- name of the interface * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS @@ -552,7 +551,7 @@ static struct usb_string fsg_strings[] = { #ifndef FSG_NO_DEVICE_STRINGS {FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, {FSG_STRING_PRODUCT, fsg_string_product}, - {FSG_STRING_SERIAL, fsg_string_serial}, + {FSG_STRING_SERIAL, ""}, {FSG_STRING_CONFIG, fsg_string_config}, #endif {FSG_STRING_INTERFACE, fsg_string_interface},