linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mtd: spi-nor: Refactor spi_nor_read_id()
@ 2020-02-23 17:37 Jonathan Neuschäfer
  2020-03-02 18:11 ` Tudor.Ambarus
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Neuschäfer @ 2020-02-23 17:37 UTC (permalink / raw)
  To: linux-mtd
  Cc: Jonathan Neuschäfer, Tudor Ambarus, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra, linux-kernel

- Don't use `tmp` for two purposes (return value, loop counter).
  Instead, use `i` for the loop counter, and `ret` for the return value.
- Don't use tabs between type and name in variable declarations,
  for consistency with other functions in spi-nor.c.
- Rewrite nested `if`s as `if (a && b)`.
- Remove `info` variable, and use spi_nor_ids[i] directly.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---

v2:
- As suggested by Tudor Ambarus:
  - rename tmp to ret
  - remove tabs between variable type and name
  - remove `info` variable

v1:
- https://lore.kernel.org/lkml/20200218151034.24744-1-j.neuschaefer@gmx.net/
---
 drivers/mtd/spi-nor/spi-nor.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 4fc632ec18fe..4c01ebb38da8 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2711,9 +2711,8 @@ static const struct flash_info spi_nor_ids[] = {

 static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
 {
-	int			tmp;
-	u8			*id = nor->bouncebuf;
-	const struct flash_info	*info;
+	int ret, i;
+	u8 *id = nor->bouncebuf;

 	if (nor->spimem) {
 		struct spi_mem_op op =
@@ -2722,22 +2721,20 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
 				   SPI_MEM_OP_NO_DUMMY,
 				   SPI_MEM_OP_DATA_IN(SPI_NOR_MAX_ID_LEN, id, 1));

-		tmp = spi_mem_exec_op(nor->spimem, &op);
+		ret = spi_mem_exec_op(nor->spimem, &op);
 	} else {
-		tmp = nor->controller_ops->read_reg(nor, SPINOR_OP_RDID, id,
+		ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDID, id,
 						    SPI_NOR_MAX_ID_LEN);
 	}
-	if (tmp) {
-		dev_dbg(nor->dev, "error %d reading JEDEC ID\n", tmp);
-		return ERR_PTR(tmp);
+	if (ret) {
+		dev_dbg(nor->dev, "error %d reading JEDEC ID\n", ret);
+		return ERR_PTR(ret);
 	}

-	for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
-		info = &spi_nor_ids[tmp];
-		if (info->id_len) {
-			if (!memcmp(info->id, id, info->id_len))
-				return &spi_nor_ids[tmp];
-		}
+	for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) {
+		if (spi_nor_ids[i].id_len &&
+		    !memcmp(spi_nor_ids[i].id, id, spi_nor_ids[i].id_len))
+			return &spi_nor_ids[i];
 	}
 	dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
 		SPI_NOR_MAX_ID_LEN, id);
--
2.20.1


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

* Re: [PATCH v2] mtd: spi-nor: Refactor spi_nor_read_id()
  2020-02-23 17:37 [PATCH v2] mtd: spi-nor: Refactor spi_nor_read_id() Jonathan Neuschäfer
@ 2020-03-02 18:11 ` Tudor.Ambarus
  0 siblings, 0 replies; 2+ messages in thread
From: Tudor.Ambarus @ 2020-03-02 18:11 UTC (permalink / raw)
  To: j.neuschaefer; +Cc: linux-mtd, miquel.raynal, richard, vigneshr, linux-kernel

On Sunday, February 23, 2020 7:37:13 PM EET Jonathan Neuschäfer wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> - Don't use `tmp` for two purposes (return value, loop counter).
>   Instead, use `i` for the loop counter, and `ret` for the return value.
> - Don't use tabs between type and name in variable declarations,
>   for consistency with other functions in spi-nor.c.
> - Rewrite nested `if`s as `if (a && b)`.
> - Remove `info` variable, and use spi_nor_ids[i] directly.
> 
> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> ---
> 
> v2:
> - As suggested by Tudor Ambarus:
>   - rename tmp to ret
>   - remove tabs between variable type and name
>   - remove `info` variable
> 
> v1:
> - https://lore.kernel.org/lkml/20200218151034.24744-1-j.neuschaefer@gmx.net/
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 

Changed i's type from int to unsigned int, reordered local variables and 
applied to spi-nor/next. Thanks,
ta


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

end of thread, other threads:[~2020-03-02 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-23 17:37 [PATCH v2] mtd: spi-nor: Refactor spi_nor_read_id() Jonathan Neuschäfer
2020-03-02 18:11 ` Tudor.Ambarus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).