Re: [PATCH v4 2/3] scsi: sd: send REQUEST SENSE for BLIST_MEDIA_CHANGE devices in runtime_resume()

From: Bart Van Assche
Date: Wed Jun 30 2021 - 00:19:23 EST


On 6/28/21 6:34 AM, Martin Kepplinger wrote:
> +static int sd_resume_runtime(struct device *dev)
> +{
> + struct scsi_disk *sdkp = dev_get_drvdata(dev);
> + struct scsi_device *sdp;
> + int timeout, retries, res;
> + struct scsi_sense_hdr my_sshdr;

Since the sense data is ignored, consider removing the "my_sshdr"
declaration and passing NULL as sense pointer to scsi_execute().

> + if (!sdkp) /* E.g.: runtime resume at the start of sd_probe() */
> + return 0;

Are you sure that this code is necessary? There is an
scsi_autopm_get_device(sdp) call at the start of sd_probe() and
scsi_autopm_put_device(sdp) call at the end of sd_probe(). In other
words, no runtime suspend will happen between the
device_initialize(&sdkp->dev) call in sd_probe() and the
dev_set_drvdata(dev, sdkp) call in the same function.

> + if (sdp->sdev_bflags & BLIST_MEDIA_CHANGE) {
> + for (retries = 3; retries > 0; --retries) {
> + unsigned char cmd[10] = { 0 };
> +
> + cmd[0] = REQUEST_SENSE;

Please define the CDB as follows:

static const u8 cmd[10] = { REQUEST_SENSE };

> + /*
> + * Leave the rest of the command zero to indicate
> + * flush everything.
> + */

Shouldn't this comment appear above the CDB definition? Also, what does
"flush everything" mean? According to SPC sense data is discarded from
the device while processing REQUEST SENSE, no matter what the value of
the ALLOCATION LENGTH parameter in that command is. From SPC-6: "the
REQUEST SENSE command with any allocation length clears the sense data."

> + res = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL,
> + &my_sshdr, timeout,
> + sdkp->max_retries, 0, RQF_PM, NULL);

Only one level of retries please. Can sdkp->max_retries be changed into 1?

Thanks,

Bart.