Re: [PATCH] gadget/file_storage.c : Add a serial number parameter.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 25 May 2010 22:51:27 +0200, Yann Cantin <yann.cantin@xxxxxxxxxxx> wrote:
Signed-off-by: Yann Cantin <yann.cantin@xxxxxxxxxxx>

Be sure you understand the legal binding of the Sidned-off-by by which you acknowledge
that you have the right to release the patch as GPLv2 (see
Documentation/SubmittingPatches).

@@ -330,6 +332,7 @@ static struct {
 	.vendor			= FSG_VENDOR_ID,
 	.product		= FSG_PRODUCT_ID,
 	.release		= 0xffff,	// Use controller chip type
+	.serial_parm		= NULL,
 	.buflen			= 16384,
 	};


This is no needed.  Check out scripts/checkpatch.pl Greg mentioned.

@@ -3197,6 +3203,7 @@ 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;
@@ -3272,6 +3279,56 @@ static int __init check_parameters(struct fsg_dev *fsg)
 		ERROR(fsg, "invalid buflen\n");
 		return -ETOOSMALL;
 	}
+
+	/* Serial string handling.
+	 * On a real device, fsg_string_serial[] would be loaded
+	 * from permanent storage. */
+	memset(&fsg_string_serial, 0, sizeof fsg_string_serial);
+	if (mod_data.serial_parm) {
+		const char *ch;
+		unsigned len = 0;
+
+		/* Sanity check :
+		 * The CB[I] specification limits the serial string to
+		 * 12 uppercase hexadecimal characters.
+		 * BBB need *at least* 12 uppercase hexadecimal characters.
+		 * (Usb sticks use 24 uppercase hexadecimal characters). */
+		len = strlen(mod_data.serial_parm);
+		if (len >= sizeof fsg_string_serial ||
+		    (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;
+		}
+		len = 0;
+		for (ch = mod_data.serial_parm; *ch; ++ch) {
+			++len;
+			if ((*ch < '0' || *ch > '9') &&
+			    (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
+				WARNING(fsg,
+					"Invalid serial string character: %c; "
+					"Failing back to default\n",
+					*ch);
+				goto fill_serial;
+			}
+		}
+		memcpy(fsg_string_serial, mod_data.serial_parm, len + 1);
+	} else {
+fill_serial:
+		/* Serial number not specified or invalid, make our own.
+		 * We just encode it from the driver version string,
+		 * 12 characters long to comply both CB[I] and BBB spec. */
+		for (i = 0; i < 12; i += 2) {
+			unsigned char	c = DRIVER_VERSION[i / 2];
+
+			if (!c)
+				break;
+			sprintf(&fsg_string_serial[i], "%02X", c);
+		}
+	}
+
 #endif /* CONFIG_USB_FILE_STORAGE_TEST */
	return 0;

You traverse the serial twice, I'd go with first checking the letters and
getting the length so then it can be validated without strlen().  Also, following
Alan's comment, instead of copying setting fsg_strings[FSG_STRING_SERIAL - 1] should
work:

	if (mod_data.serial_parm) {
		const char *ch;
		unsigned len = 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux