From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Cc: <linux-mtd@lists.infradead.org>,
Brian Norris <computersforpeace@gmail.com>,
Richard Weinberger <richard@nod.at>,
David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH 2/2] mtd: nand: Remove BUG() abuse in nand_scan_tail
Date: Tue, 5 Apr 2016 18:58:08 +0200 [thread overview]
Message-ID: <20160405185808.4693768d@bbrezillon> (raw)
In-Reply-To: <1459546164-6269-3-git-send-email-ezequiel@vanguardiasur.com.ar>
On Fri, 1 Apr 2016 18:29:24 -0300
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar> wrote:
> There's no reason to BUG() when parameters are being
> validated. Drivers can get things wrong, and it's much nicer
> to just throw a noisy warn and fail gracefully, than calling
> BUG() and throwing the whole system down the drain.
>
> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Applied.
Thanks,
Boris
> ---
> drivers/mtd/nand/nand_base.c | 52 ++++++++++++++++++++++++++++----------------
> 1 file changed, 33 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index befa04ef4a04..0fe644ebe264 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -4119,10 +4119,12 @@ int nand_scan_tail(struct mtd_info *mtd)
> struct nand_chip *chip = mtd_to_nand(mtd);
> struct nand_ecc_ctrl *ecc = &chip->ecc;
> struct nand_buffers *nbuf;
> + int ret;
>
> /* New bad blocks should be marked in OOB, flash-based BBT, or both */
> - BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
> - !(chip->bbt_options & NAND_BBT_USE_FLASH));
> + if (WARN_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
> + !(chip->bbt_options & NAND_BBT_USE_FLASH)))
> + return -EINVAL;
>
> if (!(chip->options & NAND_OWN_BUFFERS)) {
> nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
> @@ -4160,9 +4162,10 @@ int nand_scan_tail(struct mtd_info *mtd)
> ecc->layout = &nand_oob_128;
> break;
> default:
> - pr_warn("No oob scheme defined for oobsize %d\n",
> - mtd->oobsize);
> - BUG();
> + WARN(1, "No oob scheme defined for oobsize %d\n",
> + mtd->oobsize);
> + ret = -EINVAL;
> + goto err_free;
> }
> }
>
> @@ -4178,8 +4181,9 @@ int nand_scan_tail(struct mtd_info *mtd)
> case NAND_ECC_HW_OOB_FIRST:
> /* Similar to NAND_ECC_HW, but a separate read_page handle */
> if (!ecc->calculate || !ecc->correct || !ecc->hwctl) {
> - pr_warn("No ECC functions supplied; hardware ECC not possible\n");
> - BUG();
> + WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
> + ret = -EINVAL;
> + goto err_free;
> }
> if (!ecc->read_page)
> ecc->read_page = nand_read_page_hwecc_oob_first;
> @@ -4209,8 +4213,9 @@ int nand_scan_tail(struct mtd_info *mtd)
> ecc->read_page == nand_read_page_hwecc ||
> !ecc->write_page ||
> ecc->write_page == nand_write_page_hwecc)) {
> - pr_warn("No ECC functions supplied; hardware ECC not possible\n");
> - BUG();
> + WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
> + ret = -EINVAL;
> + goto err_free;
> }
> /* Use standard syndrome read/write page function? */
> if (!ecc->read_page)
> @@ -4228,8 +4233,9 @@ int nand_scan_tail(struct mtd_info *mtd)
>
> if (mtd->writesize >= ecc->size) {
> if (!ecc->strength) {
> - pr_warn("Driver must set ecc.strength when using hardware ECC\n");
> - BUG();
> + WARN(1, "Driver must set ecc.strength when using hardware ECC\n");
> + ret = -EINVAL;
> + goto err_free;
> }
> break;
> }
> @@ -4255,8 +4261,9 @@ int nand_scan_tail(struct mtd_info *mtd)
>
> case NAND_ECC_SOFT_BCH:
> if (!mtd_nand_has_bch()) {
> - pr_warn("CONFIG_MTD_NAND_ECC_BCH not enabled\n");
> - BUG();
> + WARN(1, "CONFIG_MTD_NAND_ECC_BCH not enabled\n");
> + ret = -EINVAL;
> + goto err_free;
> }
> ecc->calculate = nand_bch_calculate_ecc;
> ecc->correct = nand_bch_correct_data;
> @@ -4281,8 +4288,9 @@ int nand_scan_tail(struct mtd_info *mtd)
> ecc->bytes = 0;
> ecc->priv = nand_bch_init(mtd);
> if (!ecc->priv) {
> - pr_warn("BCH ECC initialization failed!\n");
> - BUG();
> + WARN(1, "BCH ECC initialization failed!\n");
> + ret = -EINVAL;
> + goto err_free;
> }
> break;
>
> @@ -4300,8 +4308,9 @@ int nand_scan_tail(struct mtd_info *mtd)
> break;
>
> default:
> - pr_warn("Invalid NAND_ECC_MODE %d\n", ecc->mode);
> - BUG();
> + WARN(1, "Invalid NAND_ECC_MODE %d\n", ecc->mode);
> + ret = -EINVAL;
> + goto err_free;
> }
>
> /* For many systems, the standard OOB write also works for raw */
> @@ -4331,8 +4340,9 @@ int nand_scan_tail(struct mtd_info *mtd)
> */
> ecc->steps = mtd->writesize / ecc->size;
> if (ecc->steps * ecc->size != mtd->writesize) {
> - pr_warn("Invalid ECC parameters\n");
> - BUG();
> + WARN(1, "Invalid ECC parameters\n");
> + ret = -EINVAL;
> + goto err_free;
> }
> ecc->total = ecc->steps * ecc->bytes;
>
> @@ -4410,6 +4420,10 @@ int nand_scan_tail(struct mtd_info *mtd)
>
> /* Build bad block table */
> return chip->scan_bbt(mtd);
> +err_free:
> + if (!(chip->options & NAND_OWN_BUFFERS))
> + kfree(chip->buffers);
> + return ret;
> }
> EXPORT_SYMBOL(nand_scan_tail);
>
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
next prev parent reply other threads:[~2016-04-05 16:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-01 21:29 [PATCH 0/2] nand: Remove BUG abuse Ezequiel Garcia
2016-04-01 21:29 ` [PATCH 1/2] mtd: nand: Drop mtd.owner requirement in nand_scan Ezequiel Garcia
2016-04-01 21:57 ` Richard Weinberger
2016-04-01 22:06 ` Ezequiel Garcia
2016-04-01 22:26 ` Brian Norris
2016-04-02 13:52 ` Boris Brezillon
2016-04-03 6:14 ` Brian Norris
2016-04-01 21:29 ` [PATCH 2/2] mtd: nand: Remove BUG() abuse in nand_scan_tail Ezequiel Garcia
2016-04-01 21:51 ` Richard Weinberger
2016-04-02 13:55 ` Boris Brezillon
2016-04-04 15:20 ` Boris Brezillon
2016-04-04 15:26 ` Ezequiel Garcia
2016-04-04 15:30 ` Richard Weinberger
2016-04-04 15:34 ` Ezequiel Garcia
2016-04-04 18:30 ` Boris Brezillon
2016-04-04 16:43 ` Brian Norris
2016-04-05 16:58 ` Boris Brezillon [this message]
2016-04-02 13:55 ` [PATCH 0/2] nand: Remove BUG abuse Boris Brezillon
2016-04-02 15:37 ` Ezequiel Garcia
2016-04-04 15:33 ` Boris Brezillon
2016-04-04 15:39 ` Ezequiel Garcia
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=20160405185808.4693768d@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
/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