From: Dan Carpenter <dan.carpenter@linaro.org>
To: John Garry <john.g.garry@oracle.com>
Cc: Colin Ian King <colin.i.king@gmail.com>,
"James E . J . Bottomley" <James.Bottomley@hansenpartnership.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] scsi: scsi_debug: remove a redundant assignment to variable ret
Date: Thu, 17 Oct 2024 11:57:10 +0300 [thread overview]
Message-ID: <a2515a3d-1dbb-48b6-a489-25aba3358068@stanley.mountain> (raw)
In-Reply-To: <9151ca6d-7153-4a97-aaa2-7277fc5ffa84@oracle.com>
On Wed, Oct 16, 2024 at 08:16:16AM +0100, John Garry wrote:
> On 02/10/2024 16:10, Dan Carpenter wrote:
> > On Wed, Oct 02, 2024 at 02:50:43PM +0100, Colin Ian King wrote:
> > > The variable ret is being assigned a value that is never read, the
> > > following break statement exits the loop where ret is being re-assigned
> > > a new value. Remove the redundant assignment.
> > >
> > > Signed-off-by: Colin Ian King<colin.i.king@gmail.com>
> > > ---
> > > drivers/scsi/scsi_debug.c | 4 +---
> > > 1 file changed, 1 insertion(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> > > index d95f417e24c0..7c60f5acc4a3 100644
> > > --- a/drivers/scsi/scsi_debug.c
> > > +++ b/drivers/scsi/scsi_debug.c
> > > @@ -3686,14 +3686,12 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
> > > sdeb_data_sector_lock(sip, do_write);
> > > ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents,
> > You would think there would be a:
> >
> > total += ret;
> >
> > here.
> >
> > > fsp + (block * sdebug_sector_size),
> > > sdebug_sector_size, sg_skip, do_write);T
> > > sdeb_data_sector_unlock(sip, do_write);
> > > - if (ret != sdebug_sector_size) {
> > > - ret += (i * sdebug_sector_size);
> > > + if (ret != sdebug_sector_size)
> > > break;
> > > - }
> > > sg_skip += sdebug_sector_size;
> > > if (++block >= sdebug_store_sectors)
> > > block = 0;
> > > }
> > > ret = num * sdebug_sector_size;
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > And that this would be a "return total;"
>
> Right, the function is currently a little messy as there is no variable for
> "total", and we re-assign ret per loop.
>
> So I think that we can either:
> a. introduce a variable to hold "total"
> b. this change:
>
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index af5e3a7f47a9..39218ffc6a31 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -3690,13 +3690,14 @@ static int do_device_access(struct
> sdeb_store_info *sip, struct scsi_cmnd *scp,
> sdeb_data_sector_unlock(sip, do_write);
> if (ret != sdebug_sector_size) {
> ret += (i * sdebug_sector_size);
> - break;
> + goto out_unlock;
> }
> sg_skip += sdebug_sector_size;
> if (++block >= sdebug_store_sectors)
> block = 0;
> }
> ret = num * sdebug_sector_size;
> +out_unlock:
> sdeb_data_unlock(sip, atomic);
>
>
> Maybe a. is better, as b. is maintaining some messiness.
>
I'm happy with option a.
regards,
dan carpenter
prev parent reply other threads:[~2024-10-17 8:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 13:50 Colin Ian King
2024-10-02 15:10 ` Dan Carpenter
2024-10-02 15:19 ` Dan Carpenter
2024-10-16 7:16 ` John Garry
2024-10-17 7:59 ` John Garry
2024-10-17 8:57 ` Dan Carpenter [this message]
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=a2515a3d-1dbb-48b6-a489-25aba3358068@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=colin.i.king@gmail.com \
--cc=john.g.garry@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®