Patchwork [1/3] Revert "usb-storage: Drop useless null test in usb_msd_handle_data()"

login
register
mail settings
Submitter Gerd Hoffmann
Date Jan. 22, 2013, 10:20 a.m.
Message ID <1358850010-3215-2-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/214495/
State New
Headers show

Comments

Gerd Hoffmann - Jan. 22, 2013, 10:20 a.m.
This reverts commit a1cbfd554e11bb8af38c2f3e1f1574bf4c563cd2.

Test isn't useless.  scsi_req_enqueue() may finish the request (will
actually happen for requests which don't trigger any I/O such as
INQUIRY), then call usb_msd_command_complete() which in turn will
set s->req to NULL after unref'ing it.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/dev-storage.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Markus Armbruster - Jan. 22, 2013, 11:57 a.m.
Gerd Hoffmann <kraxel@redhat.com> writes:

> This reverts commit a1cbfd554e11bb8af38c2f3e1f1574bf4c563cd2.
>
> Test isn't useless.  scsi_req_enqueue() may finish the request (will
> actually happen for requests which don't trigger any I/O such as
> INQUIRY), then call usb_msd_command_complete() which in turn will
> set s->req to NULL after unref'ing it.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/usb/dev-storage.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
> index b839798..1b87352 100644
> --- a/hw/usb/dev-storage.c
> +++ b/hw/usb/dev-storage.c
> @@ -427,7 +427,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
>              scsi_req_print(s->req);
>  #endif
>              scsi_req_enqueue(s->req);
> -            if (s->req->cmd.xfer != SCSI_XFER_NONE) {
> +            if (s->req && s->req->cmd.xfer != SCSI_XFER_NONE) {
>                  scsi_req_continue(s->req);
>              }
>              break;

No objection to the revert, and sorry for screwing this up.

However, we generally use scsi_req_enqueue() like this:

    n = scsi_req_enqueue(req);
    if (n) {
        [...]
        scsi_req_continue(req);
    }

Any particular reason to do it differently here?

Patch

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index b839798..1b87352 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -427,7 +427,7 @@  static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
             scsi_req_print(s->req);
 #endif
             scsi_req_enqueue(s->req);
-            if (s->req->cmd.xfer != SCSI_XFER_NONE) {
+            if (s->req && s->req->cmd.xfer != SCSI_XFER_NONE) {
                 scsi_req_continue(s->req);
             }
             break;