From: boris.brezillon@bootlin.com (Boris Brezillon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 32/33] mtd: rawnand: do not export nand_scan_[ident|tail]() anymore
Date: Fri, 20 Jul 2018 01:45:40 +0200 [thread overview]
Message-ID: <20180720014540.4600c87d@bbrezillon> (raw)
In-Reply-To: <20180719230026.8741-33-miquel.raynal@bootlin.com>
On Fri, 20 Jul 2018 01:00:25 +0200
Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> Both nand_scan_ident() and nand_scan_tail() helpers used to be called
> directly from controller drivers that needed to tweak some ECC-related
> parameters before nand_scan_tail(). This separation prevented dynamic
> allocations during the phase of NAND identification, which was
> inconvenient.
>
> All controller drivers have been moved to use nand_scan(), in
> conjunction with the chip->ecc.[attach|detach]_chip() hooks that
> actually do the required tweaking sequence between both ident/tail
> calls, allowing programmers to use dynamic allocation as they need all
> across the scanning sequence.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
> drivers/mtd/nand/raw/nand_base.c | 60 +++++++++++++++++++++++++++++++---------
> include/linux/mtd/rawnand.h | 11 ++------
> 2 files changed, 50 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index dea41fa25be1..dfee2556a8a8 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -5151,6 +5151,7 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
> {
> struct mtd_info *mtd = nand_to_mtd(chip);
> struct nand_onfi_params *p;
> + char *model;
> char id[4];
> int i, ret, val;
>
> @@ -5225,8 +5226,15 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
>
> sanitize_string(p->manufacturer, sizeof(p->manufacturer));
> sanitize_string(p->model, sizeof(p->model));
> - strncpy(chip->parameters.model, p->model,
> - sizeof(chip->parameters.model) - 1);
> + model = kmemdup(p->model, sizeof(p->model), GFP_KERNEL);
> + if (!model) {
> + ret = -ENOMEM;
> + goto free_onfi_param_page;
> + }
> +
> + chip->parameters.model = model;
> + if (!mtd->name)
> + mtd->name = chip->parameters.model;
>
> mtd->writesize = le32_to_cpu(p->byte_per_page);
>
> @@ -5306,6 +5314,7 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
> struct nand_jedec_params *p;
> struct jedec_ecc_info *ecc;
> int jedec_version = 0;
> + char *model;
> char id[5];
> int i, val, ret;
>
> @@ -5356,8 +5365,16 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
>
> sanitize_string(p->manufacturer, sizeof(p->manufacturer));
> sanitize_string(p->model, sizeof(p->model));
> - strncpy(chip->parameters.model, p->model,
> - sizeof(chip->parameters.model) - 1);
> + model = kzalloc(sizeof(p->model), GFP_KERNEL);
> + if (!p) {
> + ret = -ENOMEM;
> + goto free_jedec_param_page;
> + }
> +
> + strncpy(model, p->model, sizeof(model) - 1);
> + chip->parameters.model = model;
> + if (!mtd->name)
> + mtd->name = chip->parameters.model;
All changes related to the the char model[] -> const char *mode
transition should be done in a separate commit. Plus, as pointed in
patch 33, you have a regression here.
>
> mtd->writesize = le32_to_cpu(p->byte_per_page);
>
> @@ -5924,7 +5941,7 @@ static int nand_dt_init(struct nand_chip *chip)
> }
>
> /**
> - * nand_scan_ident - [NAND Interface] Scan for the NAND device
> + * nand_scan_ident - Scan for the NAND device
> * @mtd: MTD device structure
> * @maxchips: number of chips to scan for
> * @table: alternative NAND ID table
> @@ -5932,9 +5949,13 @@ static int nand_dt_init(struct nand_chip *chip)
> * This is the first phase of the normal nand_scan() function. It reads the
> * flash ID and sets up MTD fields accordingly.
> *
> + * This helper used to be called directly from controller drivers that needed
> + * to tweak some ECC-related parameters before nand_scan_tail(). This separation
> + * prevented dynamic allocations during this phase which was unconvenient and
> + * as been banned for the benefit of the ->init_ecc()/cleanup_ecc() hooks.
> */
> -int nand_scan_ident(struct mtd_info *mtd, int maxchips,
> - struct nand_flash_dev *table)
> +static int nand_scan_ident(struct mtd_info *mtd, int maxchips,
> + struct nand_flash_dev *table)
> {
> int i, nand_maf_id, nand_dev_id;
> struct nand_chip *chip = mtd_to_nand(mtd);
> @@ -6008,7 +6029,11 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
>
> return 0;
> }
> -EXPORT_SYMBOL(nand_scan_ident);
> +
> +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)
> {
> @@ -6385,14 +6410,14 @@ static bool nand_ecc_strength_good(struct mtd_info *mtd)
> }
>
> /**
> - * nand_scan_tail - [NAND Interface] Scan for the NAND device
> + * nand_scan_tail - Scan for the NAND device
> * @mtd: MTD device structure
> *
> * This is the second phase of the normal nand_scan() function. It fills out
> * all the uninitialized function pointers with the defaults and scans for a
> * bad block table if appropriate.
> */
> -int nand_scan_tail(struct mtd_info *mtd)
> +static int nand_scan_tail(struct mtd_info *mtd)
> {
> struct nand_chip *chip = mtd_to_nand(mtd);
> struct nand_ecc_ctrl *ecc = &chip->ecc;
> @@ -6716,7 +6741,6 @@ int nand_scan_tail(struct mtd_info *mtd)
>
> return ret;
> }
> -EXPORT_SYMBOL(nand_scan_tail);
>
> static int nand_attach(struct nand_chip *chip)
> {
> @@ -6754,11 +6778,18 @@ int nand_scan_with_ids(struct mtd_info *mtd, int maxchips,
>
> ret = nand_attach(chip);
> if (ret)
> - return ret;
> + goto cleanup_ident;
>
> ret = nand_scan_tail(mtd);
> if (ret)
> - nand_detach(chip);
> + goto detach_chip;
> +
> + return 0;
> +
> +detach_chip:
> + nand_detach(chip);
> +cleanup_ident:
> + nand_scan_ident_cleanup(chip);
>
> return ret;
> }
> @@ -6790,6 +6821,9 @@ void nand_cleanup(struct nand_chip *chip)
>
> /* Free controller specific allocations after chip identification */
> nand_detach(chip);
> +
> + /* Free identification phase allocations */
> + nand_scan_ident_cleanup(chip);
> }
>
> EXPORT_SYMBOL_GPL(nand_cleanup);
> diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
> index a20c78e25878..5723d940a47d 100644
> --- a/include/linux/mtd/rawnand.h
> +++ b/include/linux/mtd/rawnand.h
> @@ -36,14 +36,9 @@ static inline int nand_scan(struct mtd_info *mtd, int max_chips)
> }
>
> /*
> - * Separate phases of nand_scan(), allowing board driver to intervene
> - * and override command or ECC setup according to flash type.
> + * Unregister the MTD device and free resources held by the NAND device, must be
> + * called on error after a successful nand_scan().
> */
> -int nand_scan_ident(struct mtd_info *mtd, int max_chips,
> - struct nand_flash_dev *table);
> -int nand_scan_tail(struct mtd_info *mtd);
> -
> -/* Unregister the MTD device and free resources held by the NAND device */
> void nand_release(struct mtd_info *mtd);
>
> /* Internal helper for board drivers which need to override command function */
> @@ -487,7 +482,7 @@ struct onfi_params {
> */
> struct nand_parameters {
> /* Generic parameters */
> - char model[100];
> + const char *model;
> bool supports_set_get_features;
> DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER);
> DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);
next prev parent reply other threads:[~2018-07-19 23:45 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-19 22:59 [PATCH v3 00/33] Allow dynamic allocations during NAND chip identification phase Miquel Raynal
2018-07-19 22:59 ` [PATCH v3 01/33] mtd: rawnand: brcmnand: convert driver to nand_scan() Miquel Raynal
2018-07-19 23:17 ` Boris Brezillon
2018-07-20 7:12 ` Miquel Raynal
2018-07-19 22:59 ` [PATCH v3 02/33] mtd: rawnand: cafe: " Miquel Raynal
2018-07-19 22:59 ` [PATCH v3 03/33] mtd: rawnand: davinci: " Miquel Raynal
2018-07-19 22:59 ` [PATCH v3 04/33] mtd: rawnand: denali: convert " Miquel Raynal
2018-07-19 22:59 ` [PATCH v3 05/33] mtd: rawnand: fsl_elbc: convert driver " Miquel Raynal
2018-07-19 22:59 ` [PATCH v3 06/33] mtd: rawnand: fsl_ifc: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 07/33] mtd: rawnand: fsmc: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 08/33] mtd: rawnand: gpmi: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 09/33] mtd: rawnand: hisi504: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 10/33] mtd: rawnand: jz4780: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 11/33] mtd: rawnand: lpc32xx_mlc: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 12/33] mtd: rawnand: lpc32xx_slc: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 13/33] mtd: rawnand: marvell: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 14/33] mtd: rawnand: mtk: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 15/33] mtd: rawnand: mxc: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 16/33] mtd: rawnand: nandsim: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 17/33] mtd: rawnand: omap2: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 18/33] mtd: rawnand: s3c2410: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 19/33] mtd: rawnand: sh_flctl: move all NAND chip related setup in one function Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 20/33] mtd: rawnand: sh_flctl: convert driver to nand_scan() Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 21/33] mtd: rawnand: sunxi: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 22/33] mtd: rawnand: tango: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 23/33] mtd: rawnand: txx9ndfmc: rename nand controller internal structure Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 24/33] mtd: rawnand: txx9ndfmc: convert driver to nand_scan() Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 25/33] mtd: rawnand: vf610: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 26/33] mtd: rawnand: atmel: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 27/33] mtd: rawnand: sm_common: convert driver to nand_scan_with_ids() Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 28/33] mtd: rawnand: docg4: convert driver to nand_scan() Miquel Raynal
2018-07-19 23:27 ` Boris Brezillon
2018-07-20 7:17 ` Miquel Raynal
2018-07-20 7:35 ` Boris Brezillon
2018-07-19 23:00 ` [PATCH v3 29/33] mtd: rawnand: qcom: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 30/33] mtd: rawnand: jz4740: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 31/33] mtd: rawnand: tegra: " Miquel Raynal
2018-07-19 23:00 ` [PATCH v3 32/33] mtd: rawnand: do not export nand_scan_[ident|tail]() anymore Miquel Raynal
2018-07-19 23:45 ` Boris Brezillon [this message]
2018-07-19 23:00 ` [PATCH v3 33/33] mtd: rawnand: allocate dynamically ONFI parameters during detection Miquel Raynal
2018-07-19 23:42 ` Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180720014540.4600c87d@bbrezillon \
--to=boris.brezillon@bootlin.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).