[PATCH] mtd: nand: fix return code for uncorrectable error
Brian Norris
computersforpeace at gmail.com
Wed Sep 17 01:00:00 PDT 2014
On Sun, Sep 14, 2014 at 11:45:02PM +0200, Hauke Mehrtens wrote:
> nand_correct_data() should return -EBADMSG when it finds an
> uncorrectable error and not just -1.
Why should it? Is there any bug here, or is this just a cosmetic fix
along the lines of "we should use meaningful error codes"?
> This is based on OpenWrt patch:
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.10/451-mtd-nand-fix-return-code-of-nand_correct_data-function.patcht
>
> Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
> ---
> drivers/mtd/nand/nand_ecc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c
> index 97c4c02..244a634 100644
> --- a/drivers/mtd/nand/nand_ecc.c
> +++ b/drivers/mtd/nand/nand_ecc.c
> @@ -507,7 +507,7 @@ int __nand_correct_data(unsigned char *buf,
> return 1; /* error in ECC data; no action needed */
>
> pr_err("%s: uncorrectable ECC error\n", __func__);
> - return -1;
> + return -EBADMSG;
I think this will break at least one piece of code which relies on the
fact that the implicit standard for the correct() function is that it
returns -1 for ECC errors; see drivers/mtd/tests/mtd_nandecctest.c:
static int double_bit_error_detect(void *error_data, void *error_ecc,
void *correct_data, const size_t size)
{
unsigned char calc_ecc[3];
int ret;
__nand_calculate_ecc(error_data, size, calc_ecc);
ret = __nand_correct_data(error_data, error_ecc, calc_ecc, size);
return (ret == -1) ? 0 : -EINVAL;
}
So, if you're going to change error codes like this, I'd prefer a little
more explanation and a more comprehensive look at the existing body of
code.
> }
> EXPORT_SYMBOL(__nand_correct_data);
>
Brian
More information about the linux-mtd
mailing list