public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: damien.lemoal@wdc.com, linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Bart Van Assche <Bart.VanAssche@sandisk.com>,
	Hannes Reinecke <hare@suse.de>, Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH 3/9] sd: Remove unecessary variable in sd_done()
Date: Fri, 21 Apr 2017 11:42:42 -0700	[thread overview]
Message-ID: <1492800162.7079.33.camel@HansenPartnership.com> (raw)
In-Reply-To: <20170421091649.25287-4-damien.lemoal@wdc.com>

On Fri, 2017-04-21 at 18:16 +0900, damien.lemoal@wdc.com wrote:
> From: Damien Le Moal <damien.lemoal@wdc.com>
> 
> The 'sense_deferred' variable in sd_done() is set only if
> 'sense_valid' is true. So it is not necessary and the result of
> scsi_sense_is_deferred() and of scsi_command_normalize_sense() can
> be combined together in 'sense_valid'.
> 
> Also, since scsi_command_normalize_sense() returns a bool, use that
> type for 'sense_valid' declaration.
> 
> No functional change is introduced by this patch.
> 
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
> ---
>  drivers/scsi/sd.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 935ce34..c57084e 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -1808,8 +1808,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
>  	struct scsi_sense_hdr sshdr;
>  	struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk);
>  	struct request *req = SCpnt->request;
> -	int sense_valid = 0;
> -	int sense_deferred = 0;
> +	bool sense_valid = false;
>  	unsigned char op = SCpnt->cmnd[0];
>  	unsigned char unmap = SCpnt->cmnd[1] & 8;
>  
> @@ -1837,15 +1836,12 @@ static int sd_done(struct scsi_cmnd *SCpnt)
>  		break;
>  	}
>  
> -	if (result) {
> -		sense_valid = scsi_command_normalize_sense(SCpnt,
> &sshdr);
> -		if (sense_valid)
> -			sense_deferred =
> scsi_sense_is_deferred(&sshdr);
> -	}
> +	if (result)
> +		sense_valid = scsi_command_normalize_sense(SCpnt,
> &sshdr) &&
> +			!scsi_sense_is_deferred(&sshdr);
>  	sdkp->medium_access_timed_out = 0;
>  
> -	if (driver_byte(result) != DRIVER_SENSE &&
> -	    (!sense_valid || sense_deferred))
> +	if (driver_byte(result) != DRIVER_SENSE && !sense_valid)
>  		goto out;
>  
>  	switch (sshdr.sense_key) {

Really, no, you're making the code less clear for no gain.  I'm fairly
certain the compiler can optimise this without any help and when you're
skimming the code you can easily see that the out jump is taken if you
have a sense code that's either invalid or deferred.  After your change
you have to glance one level deeper to come to the same conclusion.

To be clear: I wouldn't object if the original function were written
the way you propose because we all get used to scanning code looking
for things like this.  However, a patch to change existing code fails
the net benefit test.

James

  reply	other threads:[~2017-04-21 18:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21  9:16 [PATCH 0/9] scsi: sd/sd_zbc cleanup and improvements damien.lemoal
2017-04-21  9:16 ` [PATCH 1/9] sd: Remove white space before EOL damien.lemoal
2017-04-21 17:22   ` Bart Van Assche
2017-04-24  0:14     ` Damien Le Moal
2017-04-21  9:16 ` [PATCH 2/9] sd: Fix functions description damien.lemoal
2017-04-21 17:28   ` Bart Van Assche
2017-04-24  0:21     ` Damien Le Moal
2017-04-21  9:16 ` [PATCH 3/9] sd: Remove unecessary variable in sd_done() damien.lemoal
2017-04-21 18:42   ` James Bottomley [this message]
2017-04-24  0:25     ` Damien Le Moal
2017-04-21  9:16 ` [PATCH 4/9] sd: Improve sd_completed_bytes damien.lemoal
2017-04-21  9:16 ` [PATCH 5/9] sd: Cleanup sd_done sense data handling damien.lemoal
2017-04-21 18:41   ` Bart Van Assche
2017-04-24  0:23     ` Damien Le Moal
2017-04-21  9:16 ` [PATCH 6/9] scsi: Improve scsi_get_sense_info_fld damien.lemoal
2017-04-21 16:58   ` Bart Van Assche
2017-04-23 23:59     ` Damien Le Moal
2017-04-21  9:16 ` [PATCH 7/9] sd_zbc: Rename sd_zbc_setup_write_cmnd damien.lemoal
2017-04-21 17:07   ` Bart Van Assche
2017-04-24  0:00     ` Damien Le Moal
2017-04-21  9:16 ` [PATCH 8/9] sd_zbc: Remove superfluous assignments damien.lemoal
2017-04-21  9:16 ` [PATCH 9/9] sd_zbc: Do not write lock zones for reset damien.lemoal
2017-04-21 17:15   ` Bart Van Assche
2017-04-24  0:11     ` Damien Le Moal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1492800162.7079.33.camel@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=Bart.VanAssche@sandisk.com \
    --cc=damien.lemoal@wdc.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox