Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH -next] mtd: rawnand: macronix: Use match_string() helper to simplify the code
@ 2019-12-30  2:52 YueHaibing
  2019-12-30 12:37 ` kbuild test robot
  2019-12-31  1:36 ` [PATCH v2 " YueHaibing
  0 siblings, 2 replies; 4+ messages in thread
From: YueHaibing @ 2019-12-30  2:52 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, frieder.schrempf, masonccyang,
	allison, yuehaibing, tglx
  Cc: linux-mtd, linux-kernel

match_string() returns the array index of a matching string.
Use it instead of the open-coded implementation.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/mtd/nand/raw/nand_macronix.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
index 58511ae..5619289 100644
--- a/drivers/mtd/nand/raw/nand_macronix.c
+++ b/drivers/mtd/nand/raw/nand_macronix.c
@@ -80,12 +80,9 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 	if (!chip->parameters.supports_set_get_features)
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) {
-		if (!strcmp(broken_get_timings[i], chip->parameters.model))
-			break;
-	}
-
-	if (i == ARRAY_SIZE(broken_get_timings))
+	i = match_string(broken_get_timings, ARRAY_SIZE(broken_get_timings),
+			 chip->parameters.model);
+	if (i < 0)
 		return;
 
 	bitmap_clear(chip->parameters.get_feature_list,
-- 
2.7.4



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH -next] mtd: rawnand: macronix: Use match_string() helper to simplify the code
  2019-12-30  2:52 [PATCH -next] mtd: rawnand: macronix: Use match_string() helper to simplify the code YueHaibing
@ 2019-12-30 12:37 ` kbuild test robot
  2019-12-31  1:36 ` [PATCH v2 " YueHaibing
  1 sibling, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2019-12-30 12:37 UTC (permalink / raw)
  To: YueHaibing
  Cc: kbuild-all, vigneshr, richard, yuehaibing, linux-kernel,
	frieder.schrempf, linux-mtd, miquel.raynal, tglx, masonccyang,
	allison

Hi YueHaibing,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on next-20191220]
[also build test WARNING on linus/master v5.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/YueHaibing/mtd-rawnand-macronix-Use-match_string-helper-to-simplify-the-code/20191230-111849
base:    7ddd09fc4b745fb1d8942f95389583e08412e0cd

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

smatch warnings:
drivers/mtd/nand/raw/nand_macronix.c:85 macronix_nand_fix_broken_get_timings() warn: unsigned 'i' is never less than zero.

vim +/i +85 drivers/mtd/nand/raw/nand_macronix.c

    54	
    55	/*
    56	 * Macronix AC series does not support using SET/GET_FEATURES to change
    57	 * the timings unlike what is declared in the parameter page. Unflag
    58	 * this feature to avoid unnecessary downturns.
    59	 */
    60	static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
    61	{
    62		unsigned int i;
    63		static const char * const broken_get_timings[] = {
    64			"MX30LF1G18AC",
    65			"MX30LF1G28AC",
    66			"MX30LF2G18AC",
    67			"MX30LF2G28AC",
    68			"MX30LF4G18AC",
    69			"MX30LF4G28AC",
    70			"MX60LF8G18AC",
    71			"MX30UF1G18AC",
    72			"MX30UF1G16AC",
    73			"MX30UF2G18AC",
    74			"MX30UF2G16AC",
    75			"MX30UF4G18AC",
    76			"MX30UF4G16AC",
    77			"MX30UF4G28AC",
    78		};
    79	
    80		if (!chip->parameters.supports_set_get_features)
    81			return;
    82	
    83		i = match_string(broken_get_timings, ARRAY_SIZE(broken_get_timings),
    84				 chip->parameters.model);
  > 85		if (i < 0)
    86			return;
    87	
    88		bitmap_clear(chip->parameters.get_feature_list,
    89			     ONFI_FEATURE_ADDR_TIMING_MODE, 1);
    90		bitmap_clear(chip->parameters.set_feature_list,
    91			     ONFI_FEATURE_ADDR_TIMING_MODE, 1);
    92	}
    93	

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v2 -next] mtd: rawnand: macronix: Use match_string() helper to simplify the code
  2019-12-30  2:52 [PATCH -next] mtd: rawnand: macronix: Use match_string() helper to simplify the code YueHaibing
  2019-12-30 12:37 ` kbuild test robot
@ 2019-12-31  1:36 ` " YueHaibing
  2020-01-14 17:04   ` Miquel Raynal
  1 sibling, 1 reply; 4+ messages in thread
From: YueHaibing @ 2019-12-31  1:36 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, frieder.schrempf, masonccyang,
	allison, yuehaibing, tglx
  Cc: linux-mtd, linux-kernel

match_string() returns the array index of a matching string.
Use it instead of the open-coded implementation.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
v2: change type of variable 'i' to int
---
 drivers/mtd/nand/raw/nand_macronix.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
index 58511ae..3ff7ce0 100644
--- a/drivers/mtd/nand/raw/nand_macronix.c
+++ b/drivers/mtd/nand/raw/nand_macronix.c
@@ -59,7 +59,7 @@ static void macronix_nand_onfi_init(struct nand_chip *chip)
  */
 static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 {
-	unsigned int i;
+	int i;
 	static const char * const broken_get_timings[] = {
 		"MX30LF1G18AC",
 		"MX30LF1G28AC",
@@ -80,12 +80,9 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 	if (!chip->parameters.supports_set_get_features)
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) {
-		if (!strcmp(broken_get_timings[i], chip->parameters.model))
-			break;
-	}
-
-	if (i == ARRAY_SIZE(broken_get_timings))
+	i = match_string(broken_get_timings, ARRAY_SIZE(broken_get_timings),
+			 chip->parameters.model);
+	if (i < 0)
 		return;
 
 	bitmap_clear(chip->parameters.get_feature_list,
-- 
2.7.4



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2 -next] mtd: rawnand: macronix: Use match_string() helper to simplify the code
  2019-12-31  1:36 ` [PATCH v2 " YueHaibing
@ 2020-01-14 17:04   ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2020-01-14 17:04 UTC (permalink / raw)
  To: YueHaibing, miquel.raynal, richard, vigneshr, frieder.schrempf,
	masonccyang, allison, tglx
  Cc: linux-mtd, linux-kernel

On Tue, 2019-12-31 at 01:36:48 UTC, YueHaibing wrote:
> match_string() returns the array index of a matching string.
> Use it instead of the open-coded implementation.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-30  2:52 [PATCH -next] mtd: rawnand: macronix: Use match_string() helper to simplify the code YueHaibing
2019-12-30 12:37 ` kbuild test robot
2019-12-31  1:36 ` [PATCH v2 " YueHaibing
2020-01-14 17:04   ` Miquel Raynal

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git