All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio_scsi: check on resp->sense_len instead of 'sense_buffer'
@ 2014-07-18 14:57 Ming Lei
  2014-07-18 15:00 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Ming Lei @ 2014-07-18 14:57 UTC (permalink / raw)
  To: James E.J. Bottomley, Paolo Bonzini
  Cc: linux-scsi, Christoph Hellwig, Ming Lei

The 'sense_buffer' of 'struct scsi_cmnd' is always true, but
resp->sense_len is only set if there is sense available.

Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
 drivers/scsi/virtio_scsi.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index eee1bc0..4d2d3b2 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -194,11 +194,10 @@ static void virtscsi_complete_cmd(struct virtio_scsi *vscsi, void *buf)
 	}
 
 	WARN_ON(resp->sense_len > VIRTIO_SCSI_SENSE_SIZE);
-	if (sc->sense_buffer) {
+	if (resp->sense_len) {
 		memcpy(sc->sense_buffer, resp->sense,
 		       min_t(u32, resp->sense_len, VIRTIO_SCSI_SENSE_SIZE));
-		if (resp->sense_len)
-			set_driver_byte(sc, DRIVER_SENSE);
+		set_driver_byte(sc, DRIVER_SENSE);
 	}
 
 	sc->scsi_done(sc);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] virtio_scsi: check on resp->sense_len instead of 'sense_buffer'
  2014-07-18 14:57 [PATCH] virtio_scsi: check on resp->sense_len instead of 'sense_buffer' Ming Lei
@ 2014-07-18 15:00 ` Paolo Bonzini
  2014-07-18 15:09   ` Ming Lei
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2014-07-18 15:00 UTC (permalink / raw)
  To: Ming Lei, James E.J. Bottomley; +Cc: linux-scsi, Christoph Hellwig

Il 18/07/2014 16:57, Ming Lei ha scritto:
> -	if (sc->sense_buffer) {
> +	if (resp->sense_len) {

In the (unlikely) case that sc->sense_buffer == NULL, you'd pass a NULL
to memcpy.

If you want, you can change this if to

	if (sc->sense_buffer && resp->sense_len)

but frankly it seems like slightly pointless churn to me.

Paolo

>  		memcpy(sc->sense_buffer, resp->sense,
>  		       min_t(u32, resp->sense_len, VIRTIO_SCSI_SENSE_SIZE));
> -		if (resp->sense_len)
> -			set_driver_byte(sc, DRIVER_SENSE);
> +		set_driver_byte(sc, DRIVER_SENSE);
>  	}



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] virtio_scsi: check on resp->sense_len instead of 'sense_buffer'
  2014-07-18 15:00 ` Paolo Bonzini
@ 2014-07-18 15:09   ` Ming Lei
  0 siblings, 0 replies; 3+ messages in thread
From: Ming Lei @ 2014-07-18 15:09 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: James E.J. Bottomley, Linux SCSI List, Christoph Hellwig

On Fri, Jul 18, 2014 at 11:00 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 18/07/2014 16:57, Ming Lei ha scritto:
>> -     if (sc->sense_buffer) {
>> +     if (resp->sense_len) {
>
> In the (unlikely) case that sc->sense_buffer == NULL, you'd pass a NULL
> to memcpy.

Every valid scsi_cmnd should have non NULL sc->sense_buffer, please
see scsi_host_alloc_command().

Thanks,
--
Ming Lei

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-18 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-18 14:57 [PATCH] virtio_scsi: check on resp->sense_len instead of 'sense_buffer' Ming Lei
2014-07-18 15:00 ` Paolo Bonzini
2014-07-18 15:09   ` Ming Lei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.