public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: linux-mtd@lists.infradead.org,
	Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: Re: [PATCH 10/12] mtd: nand: read ECC algorithm from the new field
Date: Sat, 16 Apr 2016 09:58:07 +0200	[thread overview]
Message-ID: <20160416095807.112d2f59@bbrezillon> (raw)
In-Reply-To: <1460750052-16285-11-git-send-email-zajec5@gmail.com>

On Fri, 15 Apr 2016 21:54:10 +0200
Rafał Miłecki <zajec5@gmail.com> wrote:

> Now we have all drivers properly setting this new field we can start
> using it and proceed with deprecating NAND_ECC_SOFT_BCH.
> 
> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
> ---
>  drivers/mtd/nand/nand_base.c | 98 ++++++++++++++++++++++++--------------------
>  1 file changed, 53 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index e1f3cf8..ffd1b32 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -4154,7 +4154,7 @@ int nand_scan_tail(struct mtd_info *mtd)
>  	/*
>  	 * If no default placement scheme is given, select an appropriate one.
>  	 */
> -	if (!mtd->ooblayout && (ecc->mode != NAND_ECC_SOFT_BCH)) {
> +	if (!mtd->ooblayout && ecc->algo != NAND_ECC_BCH) {

Should be:

	if (!mtd->ooblayout && ecc->algo == NAND_ECC_SOFT &&
	    ecc->algo != NAND_ECC_BCH) {

Otherwise you're also taking the NAND_ECC_HW + NAND_ECC_BCH into
account. 

>  		switch (mtd->oobsize) {
>  		case 8:
>  		case 16:
> @@ -4248,51 +4248,59 @@ int nand_scan_tail(struct mtd_info *mtd)
>  		ecc->algo = NAND_ECC_HAMMING;
>  
>  	case NAND_ECC_SOFT:
> -		ecc->calculate = nand_calculate_ecc;
> -		ecc->correct = nand_correct_data;
> -		ecc->read_page = nand_read_page_swecc;
> -		ecc->read_subpage = nand_read_subpage;
> -		ecc->write_page = nand_write_page_swecc;
> -		ecc->read_page_raw = nand_read_page_raw;
> -		ecc->write_page_raw = nand_write_page_raw;
> -		ecc->read_oob = nand_read_oob_std;
> -		ecc->write_oob = nand_write_oob_std;
> -		if (!ecc->size)
> -			ecc->size = 256;
> -		ecc->bytes = 3;
> -		ecc->strength = 1;
> -		break;
> -
>  	case NAND_ECC_SOFT_BCH:

Shouldn't we drop this case?

> -		if (!mtd_nand_has_bch()) {
> -			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;
> -		ecc->read_page = nand_read_page_swecc;
> -		ecc->read_subpage = nand_read_subpage;
> -		ecc->write_page = nand_write_page_swecc;
> -		ecc->read_page_raw = nand_read_page_raw;
> -		ecc->write_page_raw = nand_write_page_raw;
> -		ecc->read_oob = nand_read_oob_std;
> -		ecc->write_oob = nand_write_oob_std;
> -		/*
> -		 * Board driver should supply ecc.size and ecc.strength values
> -		 * to select how many bits are correctable. Otherwise, default
> -		 * to 4 bits for large page devices.
> -		 */
> -		if (!ecc->size && (mtd->oobsize >= 64)) {
> -			ecc->size = 512;
> -			ecc->strength = 4;
> -		}
> +		switch (ecc->algo) {

Please put this logic in a sub-function, nand_scan_tail() is already
quite long and hard to read, let's try to not define sub switch-case
blocks inside existing ones.

> +		case NAND_ECC_HAMMING:
> +			ecc->calculate = nand_calculate_ecc;
> +			ecc->correct = nand_correct_data;
> +			ecc->read_page = nand_read_page_swecc;
> +			ecc->read_subpage = nand_read_subpage;
> +			ecc->write_page = nand_write_page_swecc;
> +			ecc->read_page_raw = nand_read_page_raw;
> +			ecc->write_page_raw = nand_write_page_raw;
> +			ecc->read_oob = nand_read_oob_std;
> +			ecc->write_oob = nand_write_oob_std;
> +			if (!ecc->size)
> +				ecc->size = 256;
> +			ecc->bytes = 3;
> +			ecc->strength = 1;
> +			break;
> +		case NAND_ECC_BCH:
> +			if (!mtd_nand_has_bch()) {
> +				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;
> +			ecc->read_page = nand_read_page_swecc;
> +			ecc->read_subpage = nand_read_subpage;
> +			ecc->write_page = nand_write_page_swecc;
> +			ecc->read_page_raw = nand_read_page_raw;
> +			ecc->write_page_raw = nand_write_page_raw;
> +			ecc->read_oob = nand_read_oob_std;
> +			ecc->write_oob = nand_write_oob_std;
> +			/*
> +			* Board driver should supply ecc.size and ecc.strength
> +			* values to select how many bits are correctable.
> +			* Otherwise, default to 4 bits for large page devices.
> +			*/
> +			if (!ecc->size && (mtd->oobsize >= 64)) {
> +				ecc->size = 512;
> +				ecc->strength = 4;
> +			}
>  
> -		/* See nand_bch_init() for details. */
> -		ecc->bytes = 0;
> -		ecc->priv = nand_bch_init(mtd);
> -		if (!ecc->priv) {
> -			WARN(1, "BCH ECC initialization failed!\n");
> +			/* See nand_bch_init() for details. */
> +			ecc->bytes = 0;
> +			ecc->priv = nand_bch_init(mtd);
> +			if (!ecc->priv) {
> +				WARN(1, "BCH ECC initialization failed!\n");
> +				ret = -EINVAL;
> +				goto err_free;
> +			}
> +			break;
> +		default:
> +			WARN(1, "Unsupported ECC algorithm!\n");
>  			ret = -EINVAL;
>  			goto err_free;
>  		}
> @@ -4478,7 +4486,7 @@ void nand_release(struct mtd_info *mtd)
>  {
>  	struct nand_chip *chip = mtd_to_nand(mtd);
>  
> -	if (chip->ecc.mode == NAND_ECC_SOFT_BCH)
> +	if (chip->ecc.algo == NAND_ECC_BCH)

Again, should be:

	if (chip->ecc.mode = NAND_ECC_SOFT &&
	    chip->ecc.algo == NAND_ECC_BCH)

>  		nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
>  
>  	mtd_device_unregister(mtd);



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

  reply	other threads:[~2016-04-16  7:58 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1460750052-16285-1-git-send-email-zajec5@gmail.com>
2016-04-15 19:54 ` [PATCH 01/12] mtd: nand: bf5xx: set ECC algorithm explicitly Rafał Miłecki
2016-04-15 19:54 ` [PATCH 02/12] mtd: nand: davinci: " Rafał Miłecki
2016-04-15 19:54 ` [PATCH 03/12] avr32: set Atmel NAND " Rafał Miłecki
2016-04-16  7:38   ` Boris Brezillon
2016-04-16 12:58   ` Hans-Christian Noren Egtvedt
2016-04-15 19:54 ` [PATCH 04/12] mtd: nand: atmel: set " Rafał Miłecki
2016-04-16  7:40   ` Boris Brezillon
2016-04-15 19:54 ` [PATCH 05/12] CRIS v32: nand: " Rafał Miłecki
2016-04-15 19:54 ` [PATCH 06/12] staging: mt29f_spinand: " Rafał Miłecki
2016-04-15 19:54 ` [PATCH 07/12] mtd: nand: set ECC algorithm to Hamming on fallback Rafał Miłecki
2016-04-15 19:54 ` [PATCH 08/12] mtd: nand: hisi504: set ECC algorithm based on DT info Rafał Miłecki
2016-04-16  7:48   ` Boris Brezillon
2016-04-15 19:54 ` [PATCH 09/12] mtd: nand: fsmc: validate ECC setup by checking algorithm directly Rafał Miłecki
2016-04-15 20:23   ` Joe Perches
2016-04-15 20:24     ` Joe Perches
2016-04-15 20:43       ` Rafał Miłecki
2016-04-15 19:54 ` [PATCH 10/12] mtd: nand: read ECC algorithm from the new field Rafał Miłecki
2016-04-16  7:58   ` Boris Brezillon [this message]
2016-04-16  8:11     ` Boris Brezillon
2016-04-17 16:27     ` Rafał Miłecki
2016-04-17 16:50       ` Boris Brezillon
2016-04-17 16:57         ` Boris Brezillon
2016-04-17 16:57         ` Rafał Miłecki
2016-04-15 19:54 ` [PATCH 11/12] of: mtd: drop support for NAND_ECC_SOFT_BCH as "soft_bch" mapping Rafał Miłecki
2016-04-16  8:00   ` Boris Brezillon
2016-04-16  8:01     ` Boris Brezillon
2016-04-15 19:54 ` [PATCH 12/12] mtd: mtd: drop NAND_ECC_SOFT_BCH enum value Rafał Miłecki
2016-04-17 17:05   ` Boris Brezillon
2016-04-17 17:10     ` Rafał Miłecki
2016-04-17 19:01       ` Boris Brezillon
     [not found] ` <1460913104-27388-1-git-send-email-zajec5@gmail.com>
2016-04-17 17:11   ` [PATCH V2 01/11] mtd: nand: bf5xx: set ECC algorithm explicitly Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 02/11] mtd: nand: davinci: " Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 03/11] mtd: nand: atmel: " Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 04/11] CRIS v32: nand: " Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 05/11] staging: mt29f_spinand: " Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 06/11] mtd: nand: set ECC algorithm to Hamming on fallback Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 07/11] mtd: nand: hisi504: set ECC algorithm based on DT info Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 08/11] mtd: nand: fsmc: validate ECC setup by checking algorithm directly Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 09/11] mtd: nand: read ECC algorithm from the new field Rafał Miłecki
2016-04-17 18:59     ` Boris Brezillon
2016-04-17 17:11   ` [PATCH V2 10/11] of: mtd: drop support for NAND_ECC_SOFT_BCH as "soft_bch" mapping Rafał Miłecki
2016-04-17 17:11   ` [PATCH V2 11/11] mtd: mtd: drop NAND_ECC_SOFT_BCH enum value Rafał Miłecki
     [not found]   ` <1460926387-9563-1-git-send-email-zajec5@gmail.com>
2016-04-17 20:52     ` [PATCH V3 01/11] mtd: nand: bf5xx: set ECC algorithm explicitly Rafał Miłecki
2016-04-17 20:52     ` [PATCH V3 02/11] mtd: nand: davinci: " Rafał Miłecki
2016-04-17 20:52     ` [PATCH V3 03/11] mtd: nand: atmel: " Rafał Miłecki
2016-04-17 20:53     ` [PATCH V3 04/11] CRIS v32: nand: " Rafał Miłecki
2016-04-21 20:18       ` Boris Brezillon
2016-04-21 20:44       ` Mikael Starvik
2016-04-22  7:26       ` Jesper Nilsson
2016-04-17 20:53     ` [PATCH V3 05/11] staging: mt29f_spinand: " Rafał Miłecki
2016-04-21 20:20       ` Boris Brezillon
2016-04-22  2:32         ` Greg Kroah-Hartman
2016-04-17 20:53     ` [PATCH V3 06/11] mtd: nand: set ECC algorithm to Hamming on fallback Rafał Miłecki
2016-04-17 20:53     ` [PATCH V3 07/11] mtd: nand: hisi504: set ECC algorithm based on DT info Rafał Miłecki
2016-04-17 20:53     ` [PATCH V3 08/11] mtd: nand: fsmc: validate ECC setup by checking algorithm directly Rafał Miłecki
2016-04-17 20:53     ` [PATCH V3 09/11] mtd: nand: read ECC algorithm from the new field Rafał Miłecki
2016-04-17 20:53     ` [PATCH V3 10/11] of: mtd: drop support for NAND_ECC_SOFT_BCH as "soft_bch" mapping Rafał Miłecki
2016-04-17 20:53     ` [PATCH V3 11/11] mtd: mtd: drop NAND_ECC_SOFT_BCH enum value Rafał Miłecki

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=20160416095807.112d2f59@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=zajec5@gmail.com \
    /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