storvsc: be more picky about scmnd->sc_data_direction
authorVitaly Kuznetsov <vkuznets@redhat.com>
Thu, 25 Jun 2015 16:12:11 +0000 (18:12 +0200)
committerJames Bottomley <JBottomley@Odin.com>
Wed, 12 Aug 2015 22:55:59 +0000 (15:55 -0700)
Under the 'default' case in scmnd->sc_data_direction we have 3 options:
- DMA_NONE which we handle correctly.
- DMA_BIDIRECTIONAL which is never supposed to be set by SCSI stack.
- Garbage value.

Do WARN() and return -EINVAL in the last two cases. virtio_scsi does
BUG_ON() here but it looks like an overkill.

Reported-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Acked-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
drivers/scsi/storvsc_drv.c

index 3c6584ff65c1979b6119c4edce15e6d35eb3957f..61f485532543c17bb6f8db9be0af6e662a5c5ed3 100644 (file)
@@ -1598,10 +1598,18 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
                vm_srb->data_in = READ_TYPE;
                vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
                break;
-       default:
+       case DMA_NONE:
                vm_srb->data_in = UNKNOWN_TYPE;
                vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
                break;
+       default:
+               /*
+                * This is DMA_BIDIRECTIONAL or something else we are never
+                * supposed to see here.
+                */
+               WARN(1, "Unexpected data direction: %d\n",
+                    scmnd->sc_data_direction);
+               return -EINVAL;
        }