Skip to content

Commit dbc2f2e

Browse files
committed
mtd: rawnand: Return an enum from of_get_nand_ecc_algo()
There is an enumeration to list ECC algorithm, let's use it instead of returning an int. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Boris Brezillon <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 74e24cd commit dbc2f2e

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

drivers/mtd/nand/raw/nand_base.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5043,33 +5043,35 @@ static const char * const nand_ecc_algos[] = {
50435043
[NAND_ECC_RS] = "rs",
50445044
};
50455045

5046-
static int of_get_nand_ecc_algo(struct device_node *np)
5046+
static enum nand_ecc_algo of_get_nand_ecc_algo(struct device_node *np)
50475047
{
5048+
enum nand_ecc_algo ecc_algo;
50485049
const char *pm;
5049-
int err, i;
5050+
int err;
50505051

50515052
err = of_property_read_string(np, "nand-ecc-algo", &pm);
50525053
if (!err) {
5053-
for (i = NAND_ECC_HAMMING; i < ARRAY_SIZE(nand_ecc_algos); i++)
5054-
if (!strcasecmp(pm, nand_ecc_algos[i]))
5055-
return i;
5056-
return -ENODEV;
5054+
for (ecc_algo = NAND_ECC_HAMMING;
5055+
ecc_algo < ARRAY_SIZE(nand_ecc_algos);
5056+
ecc_algo++) {
5057+
if (!strcasecmp(pm, nand_ecc_algos[ecc_algo]))
5058+
return ecc_algo;
5059+
}
50575060
}
50585061

50595062
/*
50605063
* For backward compatibility we also read "nand-ecc-mode" checking
50615064
* for some obsoleted values that were specifying ECC algorithm.
50625065
*/
50635066
err = of_property_read_string(np, "nand-ecc-mode", &pm);
5064-
if (err < 0)
5065-
return err;
5066-
5067-
if (!strcasecmp(pm, "soft"))
5068-
return NAND_ECC_HAMMING;
5069-
else if (!strcasecmp(pm, "soft_bch"))
5070-
return NAND_ECC_BCH;
5067+
if (!err) {
5068+
if (!strcasecmp(pm, "soft"))
5069+
return NAND_ECC_HAMMING;
5070+
else if (!strcasecmp(pm, "soft_bch"))
5071+
return NAND_ECC_BCH;
5072+
}
50715073

5072-
return -ENODEV;
5074+
return NAND_ECC_UNKNOWN;
50735075
}
50745076

50755077
static int of_get_nand_ecc_step_size(struct device_node *np)
@@ -5114,7 +5116,8 @@ static bool of_get_nand_on_flash_bbt(struct device_node *np)
51145116
static int nand_dt_init(struct nand_chip *chip)
51155117
{
51165118
struct device_node *dn = nand_get_flash_node(chip);
5117-
int ecc_mode, ecc_algo, ecc_strength, ecc_step;
5119+
enum nand_ecc_algo ecc_algo;
5120+
int ecc_mode, ecc_strength, ecc_step;
51185121

51195122
if (!dn)
51205123
return 0;
@@ -5136,7 +5139,7 @@ static int nand_dt_init(struct nand_chip *chip)
51365139
if (ecc_mode >= 0)
51375140
chip->ecc.mode = ecc_mode;
51385141

5139-
if (ecc_algo >= 0)
5142+
if (ecc_algo != NAND_ECC_UNKNOWN)
51405143
chip->ecc.algo = ecc_algo;
51415144

51425145
if (ecc_strength >= 0)

0 commit comments

Comments
 (0)