Skip to contentSkip to conversation

usb: gadget: f_mass_storage: common->curlun could be NULL

PATCH In review Christoph Fritz 2 participants 2 messages Nov 29, 2011 – Nov 30, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: f_mass_storage: common->curlun could be NULL

This patch adds a NULL check for common->curlun in case of an unknown_cmnd in do_scsi_command().

---
 drivers/usb/gadget/f_mass_storage.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/usb/gadget/f_mass_storage.c +2 -1
index c39d588..0e42027 100644
@@ -2184,7 +2184,8 @@ unknown_cmnd:
 		reply = check_command(common, common->cmnd_size,
 				      DATA_DIR_UNKNOWN, 0xff, 0, unknown);
 		if (reply = 0) {
-			common->curlun->sense_data = SS_INVALID_COMMAND;
+			if (common->curlun)
+				common->curlun->sense_data = SS_INVALID_COMMAND;
 			reply = -EINVAL;
 		}
 		break;
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 2 lines · Christoph Fritz

This patch adds a NULL check for common->curlun in case of an unknown_cmnd in do_scsi_command().

Did you actually encountered it? check_command() should set curlun, shouldn't it?

After calling check_command() curlun may be NULL only in two situations:
1. check_command() returned negative error code, or
2. we're dealing with INQUIRY or REQUEST_SENSE command.

In the first case, the line in question is not executed at all because of “if (reply = 0)” check.

In the second case, we won't reach “unknown_cmnd” label because the two commands have their own case labels and do not perform a goto.

So as far as I can see, common->curlun cannot be NULL in the place this patch is fixing.

Quoted 19 lines
---
 drivers/usb/gadget/f_mass_storage.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/usb/gadget/f_mass_storage.c +2 -1
index c39d588..0e42027 100644
@@ -2184,7 +2184,8 @@ unknown_cmnd:
 		reply = check_command(common, common->cmnd_size,
 				      DATA_DIR_UNKNOWN, 0xff, 0, unknown);
 		if (reply = 0) {
-			common->curlun->sense_data = SS_INVALID_COMMAND;
+			if (common->curlun)
+				common->curlun->sense_data = SS_INVALID_COMMAND;
 			reply = -EINVAL;
 		}
 		break;
Signature · 4 lines
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--