From: <Tudor.Ambarus@microchip.com>
To: <joe@perches.com>, <p.yadav@ti.com>
Cc: <vigneshr@ti.com>, <michael@walle.cc>,
<linux-mtd@lists.infradead.org>, <miquel.raynal@bootlin.com>,
<richard@nod.at>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 5/5] mtd: spi-nor: swp: Drop 'else' after 'return'
Date: Mon, 15 Mar 2021 11:24:32 +0000 [thread overview]
Message-ID: <3ed8da81-55cc-4fbc-cb01-9405ac9709d7@microchip.com> (raw)
In-Reply-To: <5723fabcc03455ee6624a7d223186e5fad2bf2e9.camel@perches.com>
On 3/15/21 8:53 AM, Joe Perches wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> On Mon, 2021-03-08 at 11:58 +0530, Pratyush Yadav wrote:
>> On 06/03/21 11:50AM, Tudor Ambarus wrote:
>>> else is not generally useful after a break or return.
>>>
>>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>>
>> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
>>
>
> I don't think this improves the code.
>
> Generally, checkpatch is a stupid little script.
>
> This code uses a form like:
> if (foo)
> return bar;
> else
> return baz;
Isn't else redundant? What are the benefits of keeping the else?
>
> which checkpatch recognizes as OK and so checkpatch does not
> emit any warning message, but this code just adds comments
> before each return which confuses checkpatch.
>
> I think better would be to change the code to use temporaries
> and convert the functions to bool.
>
> Something like:
> ---
> drivers/mtd/spi-nor/core.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 0522304f52fa..e174a2f1d621 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1798,36 +1798,41 @@ static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs,
> }
>
> /*
> - * Return 1 if the entire region is locked (if @locked is true) or unlocked (if
> - * @locked is false); 0 otherwise
> + * Return true if the entire region is locked
> + * (if @locked is true) or unlocked (if @locked is false); false otherwise
> */
> -static int spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs,
> +static bool spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs,
> uint64_t len, u8 sr, bool locked)
> {
> loff_t lock_offs;
> uint64_t lock_len;
> + uint64_t lock_max;
> + uint64_t ofs_max;
>
> if (!len)
> - return 1;
> + return true;
returning one is wrong indeed, would you submit a patch for the conversion
of the functions to bool?
>
> spi_nor_get_locked_range_sr(nor, sr, &lock_offs, &lock_len);
>
> + lock_max = lock_offs + lock_len;
> + ofs_max = ofs + len;
> +
> if (locked)
> /* Requested range is a sub-range of locked range */
> - return (ofs + len <= lock_offs + lock_len) && (ofs >= lock_offs);
> + return (ofs_max <= lock_max) && (ofs >= lock_offs);
> else
> /* Requested range does not overlap with locked range */
> - return (ofs >= lock_offs + lock_len) || (ofs + len <= lock_offs);
> + return (ofs >= lock_max) || (ofs_max <= lock_offs);
This should be fine too.
Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2021-03-15 11:26 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-06 9:49 [PATCH v2 0/5] mtd: spi-nor: Cleanup patches Tudor Ambarus
2021-03-06 9:49 ` [PATCH v2 1/5] mtd: spi-nor: core: Advance erase after the erase cmd has been completed Tudor Ambarus
2021-03-06 9:49 ` [PATCH v2 2/5] mtd: spi-nor: core: Add vdbg msg for spi_nor_erase_multi_sectors() Tudor Ambarus
2021-03-08 6:21 ` Pratyush Yadav
2021-03-06 9:50 ` [PATCH v2 3/5] mtd: spi-nor: Get rid of duplicated argument in spi_nor_parse_sfdp() Tudor Ambarus
2021-03-08 6:26 ` Pratyush Yadav
2021-03-06 9:50 ` [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core Tudor Ambarus
2021-03-06 11:19 ` Michael Walle
2021-03-15 6:09 ` Tudor.Ambarus
2021-03-15 8:27 ` Pratyush Yadav
2021-03-15 8:43 ` Michael Walle
2021-03-08 17:28 ` Vignesh Raghavendra
2021-03-09 7:28 ` Tudor.Ambarus
2021-03-15 6:23 ` Vignesh Raghavendra
2021-03-17 6:09 ` Tudor.Ambarus
2021-03-17 8:21 ` Michael Walle
2021-03-17 9:30 ` Tudor.Ambarus
2021-03-17 17:50 ` Michael Walle
2021-03-17 9:05 ` Pratyush Yadav
2021-03-17 16:14 ` Vignesh Raghavendra
2021-03-06 9:50 ` [PATCH v2 5/5] mtd: spi-nor: swp: Drop 'else' after 'return' Tudor Ambarus
2021-03-08 6:28 ` Pratyush Yadav
2021-03-15 6:53 ` Joe Perches
2021-03-15 11:24 ` Tudor.Ambarus [this message]
2021-03-15 14:43 ` Joe Perches
2021-03-17 5:55 ` (subset) [PATCH v2 0/5] mtd: spi-nor: Cleanup patches Tudor Ambarus
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=3ed8da81-55cc-4fbc-cb01-9405ac9709d7@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=michael@walle.cc \
--cc=miquel.raynal@bootlin.com \
--cc=p.yadav@ti.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.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