Skip to content

Commit bcc678c

Browse files
author
Boris Brezillon
committed
mtd: nand: Do not expose the NAND manufacturer table directly
There is no reason to expose the NAND manufacturer table. Provide an helper function to find manufacturers by their id. We also turn the nand_manufacturers table into a const array, since its members are not modified after the initial assignment. Finally, we remove the sentinel manufacturer entry from the manufacturers table (we already have the array size information given by ARRAY_SIZE()), and add the nand_manufacturer_name() helper to handle the "Unknown" case properly. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
1 parent f16bd7c commit bcc678c

3 files changed

Lines changed: 39 additions & 15 deletions

File tree

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,9 +4052,10 @@ static bool find_full_id_nand(struct nand_chip *chip,
40524052
*/
40534053
static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
40544054
{
4055+
const struct nand_manufacturer *manufacturer;
40554056
struct mtd_info *mtd = nand_to_mtd(chip);
40564057
int busw;
4057-
int i, maf_idx;
4058+
int i;
40584059
u8 *id_data = chip->id.data;
40594060
u8 maf_id, dev_id;
40604061

@@ -4159,10 +4160,7 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
41594160
ident_done:
41604161

41614162
/* Try to identify manufacturer */
4162-
for (maf_idx = 0; nand_manuf_ids[maf_idx].id != 0x0; maf_idx++) {
4163-
if (nand_manuf_ids[maf_idx].id == maf_id)
4164-
break;
4165-
}
4163+
manufacturer = nand_get_manufacturer(maf_id);
41664164

41674165
if (chip->options & NAND_BUSWIDTH_AUTO) {
41684166
WARN_ON(busw & NAND_BUSWIDTH_16);
@@ -4174,7 +4172,8 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
41744172
*/
41754173
pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n",
41764174
maf_id, dev_id);
4177-
pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, mtd->name);
4175+
pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
4176+
mtd->name);
41784177
pr_warn("bus width %d instead of %d bits\n", busw ? 16 : 8,
41794178
(chip->options & NAND_BUSWIDTH_16) ? 16 : 8);
41804179
return -EINVAL;
@@ -4207,14 +4206,14 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
42074206
maf_id, dev_id);
42084207

42094208
if (chip->onfi_version)
4210-
pr_info("%s %s\n", nand_manuf_ids[maf_idx].name,
4211-
chip->onfi_params.model);
4209+
pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
4210+
chip->onfi_params.model);
42124211
else if (chip->jedec_version)
4213-
pr_info("%s %s\n", nand_manuf_ids[maf_idx].name,
4214-
chip->jedec_params.model);
4212+
pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
4213+
chip->jedec_params.model);
42154214
else
4216-
pr_info("%s %s\n", nand_manuf_ids[maf_idx].name,
4217-
type->name);
4215+
pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
4216+
type->name);
42184217

42194218
pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n",
42204219
(int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",

‎drivers/mtd/nand/nand_ids.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct nand_flash_dev nand_flash_ids[] = {
169169
};
170170

171171
/* Manufacturer IDs */
172-
struct nand_manufacturer nand_manuf_ids[] = {
172+
static const struct nand_manufacturer nand_manufacturers[] = {
173173
{NAND_MFR_TOSHIBA, "Toshiba"},
174174
{NAND_MFR_ESMT, "ESMT"},
175175
{NAND_MFR_SAMSUNG, "Samsung"},
@@ -186,5 +186,23 @@ struct nand_manufacturer nand_manuf_ids[] = {
186186
{NAND_MFR_INTEL, "Intel"},
187187
{NAND_MFR_ATO, "ATO"},
188188
{NAND_MFR_WINBOND, "Winbond"},
189-
{0x0, "Unknown"}
190189
};
190+
191+
/**
192+
* nand_get_manufacturer - Get manufacturer information from the manufacturer
193+
* ID
194+
* @id: manufacturer ID
195+
*
196+
* Returns a pointer a nand_manufacturer object if the manufacturer is defined
197+
* in the NAND manufacturers database, NULL otherwise.
198+
*/
199+
const struct nand_manufacturer *nand_get_manufacturer(u8 id)
200+
{
201+
int i;
202+
203+
for (i = 0; i < ARRAY_SIZE(nand_manufacturers); i++)
204+
if (nand_manufacturers[i].id == id)
205+
return &nand_manufacturers[i];
206+
207+
return NULL;
208+
}

‎include/linux/mtd/nand.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,15 @@ struct nand_manufacturer {
10711071
char *name;
10721072
};
10731073

1074+
const struct nand_manufacturer *nand_get_manufacturer(u8 id);
1075+
1076+
static inline const char *
1077+
nand_manufacturer_name(const struct nand_manufacturer *manufacturer)
1078+
{
1079+
return manufacturer ? manufacturer->name : "Unknown";
1080+
}
1081+
10741082
extern struct nand_flash_dev nand_flash_ids[];
1075-
extern struct nand_manufacturer nand_manuf_ids[];
10761083

10771084
int nand_default_bbt(struct mtd_info *mtd);
10781085
int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);

0 commit comments

Comments
 (0)