From 06a8a7d33a9dc9e8059a02c2baf66ccddca2284e Mon Sep 17 00:00:00 2001 From: Mayank Rana Date: Wed, 2 Mar 2016 14:56:23 -0800 Subject: [PATCH] usb: gadget: f_diag: Fix check to update dload cookie This change update dload cookie if cdev->desc.iSerialNumber is already available instead of trying to get string descriptors. It also adds check against possibility of string descriptors being NULL to avoid device crash. Signed-off-by: Mayank Rana --- drivers/usb/gadget/function/f_diag.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_diag.c b/drivers/usb/gadget/function/f_diag.c index f89f81b4dfc9..4210f77a6245 100644 --- a/drivers/usb/gadget/function/f_diag.c +++ b/drivers/usb/gadget/function/f_diag.c @@ -225,13 +225,17 @@ static void diag_update_pid_and_serial_num(struct diag_context *ctxt) local_diag_dload.pid = cdev->desc.idProduct; /* pass on product id and serial number to dload */ - if (cdev->desc.iSerialNumber) { + if (!cdev->desc.iSerialNumber) { /* * Serial number is filled by the composite driver. So * it is fair enough to assume that it will always be * found at first table of strings. */ table = *(cdev->driver->strings); + if (!table) { + pr_err("%s: can't update dload cookie\n", __func__); + return; + } for (s = table->strings; s && s->s; s++) { if (s->id == cdev->desc.iSerialNumber) { local_diag_dload.magic_struct.serial_num =