Skip to content

Commit 0cf5c7d

Browse files
Abhishek Sahumiquelraynal
authored andcommitted
mtd: rawnand: provide only single helper function for ECC conf
Function nand_ecc_choose_conf() will be help for all the cases, so other helper functions can be made static. nand_check_ecc_caps(): Invoke nand_ecc_choose_conf() with both chip->ecc.size and chip->ecc.strength value set. nand_maximize_ecc(): Invoke nand_ecc_choose_conf() with NAND_ECC_MAXIMIZE flag. nand_match_ecc_req(): Invoke nand_ecc_choose_conf() with either chip->ecc.size or chip->ecc.strength value set and without NAND_ECC_MAXIMIZE flag. CC: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Abhishek Sahu <absahu@codeaurora.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 85632c1 commit 0cf5c7d

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

drivers/mtd/nand/raw/nand_base.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6085,24 +6085,17 @@ static int nand_set_ecc_soft_ops(struct mtd_info *mtd)
60856085
* by the controller and the calculated ECC bytes fit within the chip's OOB.
60866086
* On success, the calculated ECC bytes is set.
60876087
*/
6088-
int nand_check_ecc_caps(struct nand_chip *chip,
6089-
const struct nand_ecc_caps *caps, int oobavail)
6088+
static int
6089+
nand_check_ecc_caps(struct nand_chip *chip,
6090+
const struct nand_ecc_caps *caps, int oobavail)
60906091
{
60916092
struct mtd_info *mtd = nand_to_mtd(chip);
60926093
const struct nand_ecc_step_info *stepinfo;
60936094
int preset_step = chip->ecc.size;
60946095
int preset_strength = chip->ecc.strength;
6095-
int nsteps, ecc_bytes;
6096+
int ecc_bytes, nsteps = mtd->writesize / preset_step;
60966097
int i, j;
60976098

6098-
if (WARN_ON(oobavail < 0))
6099-
return -EINVAL;
6100-
6101-
if (!preset_step || !preset_strength)
6102-
return -ENODATA;
6103-
6104-
nsteps = mtd->writesize / preset_step;
6105-
61066099
for (i = 0; i < caps->nstepinfos; i++) {
61076100
stepinfo = &caps->stepinfos[i];
61086101

@@ -6135,7 +6128,6 @@ int nand_check_ecc_caps(struct nand_chip *chip,
61356128

61366129
return -ENOTSUPP;
61376130
}
6138-
EXPORT_SYMBOL_GPL(nand_check_ecc_caps);
61396131

61406132
/**
61416133
* nand_match_ecc_req - meet the chip's requirement with least ECC bytes
@@ -6147,8 +6139,9 @@ EXPORT_SYMBOL_GPL(nand_check_ecc_caps);
61476139
* number of ECC bytes (i.e. with the largest number of OOB-free bytes).
61486140
* On success, the chosen ECC settings are set.
61496141
*/
6150-
int nand_match_ecc_req(struct nand_chip *chip,
6151-
const struct nand_ecc_caps *caps, int oobavail)
6142+
static int
6143+
nand_match_ecc_req(struct nand_chip *chip,
6144+
const struct nand_ecc_caps *caps, int oobavail)
61526145
{
61536146
struct mtd_info *mtd = nand_to_mtd(chip);
61546147
const struct nand_ecc_step_info *stepinfo;
@@ -6159,9 +6152,6 @@ int nand_match_ecc_req(struct nand_chip *chip,
61596152
int best_ecc_bytes_total = INT_MAX;
61606153
int i, j;
61616154

6162-
if (WARN_ON(oobavail < 0))
6163-
return -EINVAL;
6164-
61656155
/* No information provided by the NAND chip */
61666156
if (!req_step || !req_strength)
61676157
return -ENOTSUPP;
@@ -6220,7 +6210,6 @@ int nand_match_ecc_req(struct nand_chip *chip,
62206210

62216211
return 0;
62226212
}
6223-
EXPORT_SYMBOL_GPL(nand_match_ecc_req);
62246213

62256214
/**
62266215
* nand_maximize_ecc - choose the max ECC strength available
@@ -6231,8 +6220,9 @@ EXPORT_SYMBOL_GPL(nand_match_ecc_req);
62316220
* Choose the max ECC strength that is supported on the controller, and can fit
62326221
* within the chip's OOB. On success, the chosen ECC settings are set.
62336222
*/
6234-
int nand_maximize_ecc(struct nand_chip *chip,
6235-
const struct nand_ecc_caps *caps, int oobavail)
6223+
static int
6224+
nand_maximize_ecc(struct nand_chip *chip,
6225+
const struct nand_ecc_caps *caps, int oobavail)
62366226
{
62376227
struct mtd_info *mtd = nand_to_mtd(chip);
62386228
const struct nand_ecc_step_info *stepinfo;
@@ -6242,9 +6232,6 @@ int nand_maximize_ecc(struct nand_chip *chip,
62426232
int best_strength, best_ecc_bytes;
62436233
int i, j;
62446234

6245-
if (WARN_ON(oobavail < 0))
6246-
return -EINVAL;
6247-
62486235
for (i = 0; i < caps->nstepinfos; i++) {
62496236
stepinfo = &caps->stepinfos[i];
62506237
step_size = stepinfo->stepsize;
@@ -6293,7 +6280,6 @@ int nand_maximize_ecc(struct nand_chip *chip,
62936280

62946281
return 0;
62956282
}
6296-
EXPORT_SYMBOL_GPL(nand_maximize_ecc);
62976283

62986284
/**
62996285
* nand_ecc_choose_conf - Set the ECC strength and ECC step size
@@ -6315,6 +6301,11 @@ EXPORT_SYMBOL_GPL(nand_maximize_ecc);
63156301
int nand_ecc_choose_conf(struct nand_chip *chip,
63166302
const struct nand_ecc_caps *caps, int oobavail)
63176303
{
6304+
struct mtd_info *mtd = nand_to_mtd(chip);
6305+
6306+
if (WARN_ON(oobavail < 0 || oobavail > mtd->oobsize))
6307+
return -EINVAL;
6308+
63186309
if (chip->ecc.size && chip->ecc.strength)
63196310
return nand_check_ecc_caps(chip, caps, oobavail);
63206311

include/linux/mtd/rawnand.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,15 +1663,6 @@ int nand_check_erased_ecc_chunk(void *data, int datalen,
16631663
void *extraoob, int extraooblen,
16641664
int threshold);
16651665

1666-
int nand_check_ecc_caps(struct nand_chip *chip,
1667-
const struct nand_ecc_caps *caps, int oobavail);
1668-
1669-
int nand_match_ecc_req(struct nand_chip *chip,
1670-
const struct nand_ecc_caps *caps, int oobavail);
1671-
1672-
int nand_maximize_ecc(struct nand_chip *chip,
1673-
const struct nand_ecc_caps *caps, int oobavail);
1674-
16751666
int nand_ecc_choose_conf(struct nand_chip *chip,
16761667
const struct nand_ecc_caps *caps, int oobavail);
16771668

0 commit comments

Comments
 (0)