linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] mtd: rawnand: meson: fix a loop in meson_nand_bch_mode()
@ 2019-02-01  8:30 Dan Carpenter
  2019-02-02  3:01 ` Liang Yang
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2019-02-01  8:30 UTC (permalink / raw)
  To: Liang Yang
  Cc: Boris Brezillon, Richard Weinberger, kernel-janitors,
	Marek Vasut, linux-mtd, Kevin Hilman, Miquel Raynal,
	linux-amlogic, Brian Norris, David Woodhouse

There is a sizeof() vs ARRAY_SIZE() bug here.  We want the number of
elements in the array, not the number of bytes.  It means we potentially
read beyond the end of the array.

Fixes: 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/mtd/nand/raw/meson_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
index 94c90be7e1e0..0d93d0b9c1af 100644
--- a/drivers/mtd/nand/raw/meson_nand.c
+++ b/drivers/mtd/nand/raw/meson_nand.c
@@ -1143,7 +1143,7 @@ static int meson_nand_bch_mode(struct nand_chip *nand)
 	if (nand->ecc.strength > 60 || nand->ecc.strength < 8)
 		return -EINVAL;
 
-	for (i = 0; i < sizeof(meson_ecc); i++) {
+	for (i = 0; i < ARRAY_SIZE(meson_ecc); i++) {
 		if (meson_ecc[i].strength == nand->ecc.strength) {
 			meson_chip->bch_mode = meson_ecc[i].bch;
 			return 0;
-- 
2.17.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/3] mtd: rawnand: meson: fix a loop in meson_nand_bch_mode()
  2019-02-01  8:30 [PATCH 2/3] mtd: rawnand: meson: fix a loop in meson_nand_bch_mode() Dan Carpenter
@ 2019-02-02  3:01 ` Liang Yang
  0 siblings, 0 replies; 2+ messages in thread
From: Liang Yang @ 2019-02-02  3:01 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Boris Brezillon, Richard Weinberger, kernel-janitors,
	Marek Vasut, linux-mtd, Kevin Hilman, Miquel Raynal,
	linux-amlogic, Brian Norris, David Woodhouse


On 2019/2/1 16:30, Dan Carpenter wrote:
> There is a sizeof() vs ARRAY_SIZE() bug here.  We want the number of
> elements in the array, not the number of bytes.  It means we potentially
> read beyond the end of the array.
> 
> Fixes: 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>   drivers/mtd/nand/raw/meson_nand.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
> index 94c90be7e1e0..0d93d0b9c1af 100644
> --- a/drivers/mtd/nand/raw/meson_nand.c
> +++ b/drivers/mtd/nand/raw/meson_nand.c
> @@ -1143,7 +1143,7 @@ static int meson_nand_bch_mode(struct nand_chip *nand)
>   	if (nand->ecc.strength > 60 || nand->ecc.strength < 8)
>   		return -EINVAL;
>   
> -	for (i = 0; i < sizeof(meson_ecc); i++) {
> +	for (i = 0; i < ARRAY_SIZE(meson_ecc); i++) {

ok.

Acked-by: Liang Yang <liang.yang@amlogic.com>

>   		if (meson_ecc[i].strength == nand->ecc.strength) {
>   			meson_chip->bch_mode = meson_ecc[i].bch;
>   			return 0;
> 

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-02  3:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-01  8:30 [PATCH 2/3] mtd: rawnand: meson: fix a loop in meson_nand_bch_mode() Dan Carpenter
2019-02-02  3:01 ` Liang Yang

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).