mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-30 04:13:47 +00:00
mtd: rawnand: allocate model parameter dynamically
Thanks to the migration of all drivers to use nand_scan() and the related nand_controller_ops, we can now allocate data during the detection phase. Let's do it first for the NAND model parameter which is allocated in nand_detect(). Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
This commit is contained in:
parent
98732da1a0
commit
2023f1fa21
2 changed files with 42 additions and 12 deletions
|
@ -5225,8 +5225,11 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
|
||||||
|
|
||||||
sanitize_string(p->manufacturer, sizeof(p->manufacturer));
|
sanitize_string(p->manufacturer, sizeof(p->manufacturer));
|
||||||
sanitize_string(p->model, sizeof(p->model));
|
sanitize_string(p->model, sizeof(p->model));
|
||||||
strncpy(chip->parameters.model, p->model,
|
chip->parameters.model = kstrdup(p->model, GFP_KERNEL);
|
||||||
sizeof(chip->parameters.model) - 1);
|
if (!chip->parameters.model) {
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto free_onfi_param_page;
|
||||||
|
}
|
||||||
|
|
||||||
mtd->writesize = le32_to_cpu(p->byte_per_page);
|
mtd->writesize = le32_to_cpu(p->byte_per_page);
|
||||||
|
|
||||||
|
@ -5356,8 +5359,11 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
|
||||||
|
|
||||||
sanitize_string(p->manufacturer, sizeof(p->manufacturer));
|
sanitize_string(p->manufacturer, sizeof(p->manufacturer));
|
||||||
sanitize_string(p->model, sizeof(p->model));
|
sanitize_string(p->model, sizeof(p->model));
|
||||||
strncpy(chip->parameters.model, p->model,
|
chip->parameters.model = kstrdup(p->model, GFP_KERNEL);
|
||||||
sizeof(chip->parameters.model) - 1);
|
if (!chip->parameters.model) {
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto free_jedec_param_page;
|
||||||
|
}
|
||||||
|
|
||||||
mtd->writesize = le32_to_cpu(p->byte_per_page);
|
mtd->writesize = le32_to_cpu(p->byte_per_page);
|
||||||
|
|
||||||
|
@ -5546,8 +5552,9 @@ static bool find_full_id_nand(struct nand_chip *chip,
|
||||||
chip->onfi_timing_mode_default =
|
chip->onfi_timing_mode_default =
|
||||||
type->onfi_timing_mode_default;
|
type->onfi_timing_mode_default;
|
||||||
|
|
||||||
strncpy(chip->parameters.model, type->name,
|
chip->parameters.model = kstrdup(type->name, GFP_KERNEL);
|
||||||
sizeof(chip->parameters.model) - 1);
|
if (!chip->parameters.model)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -5706,8 +5713,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
|
||||||
if (!type->name)
|
if (!type->name)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
strncpy(chip->parameters.model, type->name,
|
chip->parameters.model = kstrdup(type->name, GFP_KERNEL);
|
||||||
sizeof(chip->parameters.model) - 1);
|
if (!chip->parameters.model)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
chip->chipsize = (uint64_t)type->chipsize << 20;
|
chip->chipsize = (uint64_t)type->chipsize << 20;
|
||||||
|
|
||||||
|
@ -5737,7 +5745,9 @@ ident_done:
|
||||||
mtd->name);
|
mtd->name);
|
||||||
pr_warn("bus width %d instead of %d bits\n", busw ? 16 : 8,
|
pr_warn("bus width %d instead of %d bits\n", busw ? 16 : 8,
|
||||||
(chip->options & NAND_BUSWIDTH_16) ? 16 : 8);
|
(chip->options & NAND_BUSWIDTH_16) ? 16 : 8);
|
||||||
return -EINVAL;
|
ret = -EINVAL;
|
||||||
|
|
||||||
|
goto free_detect_allocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
nand_decode_bbm_options(chip);
|
nand_decode_bbm_options(chip);
|
||||||
|
@ -5774,6 +5784,11 @@ ident_done:
|
||||||
(int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
|
(int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
|
||||||
mtd->erasesize >> 10, mtd->writesize, mtd->oobsize);
|
mtd->erasesize >> 10, mtd->writesize, mtd->oobsize);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
free_detect_allocation:
|
||||||
|
kfree(chip->parameters.model);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const nand_ecc_modes[] = {
|
static const char * const nand_ecc_modes[] = {
|
||||||
|
@ -6013,6 +6028,11 @@ static int nand_scan_ident(struct mtd_info *mtd, int maxchips,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void nand_scan_ident_cleanup(struct nand_chip *chip)
|
||||||
|
{
|
||||||
|
kfree(chip->parameters.model);
|
||||||
|
}
|
||||||
|
|
||||||
static int nand_set_ecc_soft_ops(struct mtd_info *mtd)
|
static int nand_set_ecc_soft_ops(struct mtd_info *mtd)
|
||||||
{
|
{
|
||||||
struct nand_chip *chip = mtd_to_nand(mtd);
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||||||
|
@ -6760,11 +6780,18 @@ int nand_scan_with_ids(struct mtd_info *mtd, int maxchips,
|
||||||
|
|
||||||
ret = nand_attach(chip);
|
ret = nand_attach(chip);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
goto cleanup_ident;
|
||||||
|
|
||||||
ret = nand_scan_tail(mtd);
|
ret = nand_scan_tail(mtd);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
goto detach_chip;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
detach_chip:
|
||||||
nand_detach(chip);
|
nand_detach(chip);
|
||||||
|
cleanup_ident:
|
||||||
|
nand_scan_ident_cleanup(chip);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -6796,6 +6823,9 @@ void nand_cleanup(struct nand_chip *chip)
|
||||||
|
|
||||||
/* Free controller specific allocations after chip identification */
|
/* Free controller specific allocations after chip identification */
|
||||||
nand_detach(chip);
|
nand_detach(chip);
|
||||||
|
|
||||||
|
/* Free identification phase allocations */
|
||||||
|
nand_scan_ident_cleanup(chip);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_SYMBOL_GPL(nand_cleanup);
|
EXPORT_SYMBOL_GPL(nand_cleanup);
|
||||||
|
|
|
@ -476,7 +476,7 @@ struct onfi_params {
|
||||||
*/
|
*/
|
||||||
struct nand_parameters {
|
struct nand_parameters {
|
||||||
/* Generic parameters */
|
/* Generic parameters */
|
||||||
char model[100];
|
const char *model;
|
||||||
bool supports_set_get_features;
|
bool supports_set_get_features;
|
||||||
DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER);
|
DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER);
|
||||||
DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);
|
DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);
|
||||||
|
|
Loading…
Add table
Reference in a new issue