* [PATCH v2 0/2] meson-nand: two small memory related fixes
@ 2019-03-18 20:47 Martin Blumenstingl
2019-03-18 20:47 ` [PATCH v2 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf() Martin Blumenstingl
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Martin Blumenstingl @ 2019-03-18 20:47 UTC (permalink / raw)
To: linux-amlogic, linux-mtd, bbrezillon, miquel.raynal
Cc: Martin Blumenstingl, richard, liang.yang, linux-kernel, jianxin.pan
While trying to add support for older Meson SoCs to the meson-nand
driver I was experiencing a crash in meson_nfc_read_buf(). While trying
to find out why that happened I inspected the code in that function and
found that there's:
- a missing check on the return value of a kzalloc() call
- a potential memory leak in it
Both fixes have nothing to do with my original crash (for which I'll
open a separate thread).
Changes since v1:
- collected Liang's Acked-by's (thank you!)
- rebased on top of v5.1-rc1
Martin Blumenstingl (2):
mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf()
mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf
drivers/mtd/nand/raw/meson_nand.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
--
2.21.0
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf()
2019-03-18 20:47 [PATCH v2 0/2] meson-nand: two small memory related fixes Martin Blumenstingl
@ 2019-03-18 20:47 ` Martin Blumenstingl
2019-03-19 16:16 ` Kevin Hilman
2019-03-18 20:47 ` [PATCH v2 2/2] mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf Martin Blumenstingl
2019-04-01 15:27 ` [PATCH v2 0/2] meson-nand: two small memory related fixes Miquel Raynal
2 siblings, 1 reply; 6+ messages in thread
From: Martin Blumenstingl @ 2019-03-18 20:47 UTC (permalink / raw)
To: linux-amlogic, linux-mtd, bbrezillon, miquel.raynal
Cc: Martin Blumenstingl, richard, liang.yang, linux-kernel, jianxin.pan
kzalloc() can return NULL if memory could not be allocated. Check the
return value of the kzalloc() call in meson_nfc_read_buf() to make it
consistent with other memory allocations within the meson_nand driver.
Fixes: 8fae856c53500a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Acked-by: Liang Yang <liang.yang@amlogic.com>
---
drivers/mtd/nand/raw/meson_nand.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
index 3e8aa71407b5..a1d8506b61c7 100644
--- a/drivers/mtd/nand/raw/meson_nand.c
+++ b/drivers/mtd/nand/raw/meson_nand.c
@@ -528,6 +528,9 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len)
u8 *info;
info = kzalloc(PER_INFO_BYTE, GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
ret = meson_nfc_dma_buffer_setup(nand, buf, len, info,
PER_INFO_BYTE, DMA_FROM_DEVICE);
if (ret)
--
2.21.0
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf
2019-03-18 20:47 [PATCH v2 0/2] meson-nand: two small memory related fixes Martin Blumenstingl
2019-03-18 20:47 ` [PATCH v2 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf() Martin Blumenstingl
@ 2019-03-18 20:47 ` Martin Blumenstingl
2019-03-19 16:17 ` Kevin Hilman
2019-04-01 15:27 ` [PATCH v2 0/2] meson-nand: two small memory related fixes Miquel Raynal
2 siblings, 1 reply; 6+ messages in thread
From: Martin Blumenstingl @ 2019-03-18 20:47 UTC (permalink / raw)
To: linux-amlogic, linux-mtd, bbrezillon, miquel.raynal
Cc: Martin Blumenstingl, richard, liang.yang, linux-kernel, jianxin.pan
meson_nfc_dma_buffer_setup() is called with the "info" buffer which is
allocated a few lines before using kzalloc(). If
meson_nfc_dma_buffer_setup() fails we need to free the allocated "info"
buffer instead of only freeing it upon success.
Fixes: 8fae856c53500a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Acked-by: Liang Yang <liang.yang@amlogic.com>
---
drivers/mtd/nand/raw/meson_nand.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
index a1d8506b61c7..38db4fd61459 100644
--- a/drivers/mtd/nand/raw/meson_nand.c
+++ b/drivers/mtd/nand/raw/meson_nand.c
@@ -534,7 +534,7 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len)
ret = meson_nfc_dma_buffer_setup(nand, buf, len, info,
PER_INFO_BYTE, DMA_FROM_DEVICE);
if (ret)
- return ret;
+ goto out;
cmd = NFC_CMD_N2M | (len & GENMASK(5, 0));
writel(cmd, nfc->reg_base + NFC_REG_CMD);
@@ -542,6 +542,8 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len)
meson_nfc_drain_cmd(nfc);
meson_nfc_wait_cmd_finish(nfc, 1000);
meson_nfc_dma_buffer_release(nand, len, PER_INFO_BYTE, DMA_FROM_DEVICE);
+
+out:
kfree(info);
return ret;
--
2.21.0
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf()
2019-03-18 20:47 ` [PATCH v2 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf() Martin Blumenstingl
@ 2019-03-19 16:16 ` Kevin Hilman
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Hilman @ 2019-03-19 16:16 UTC (permalink / raw)
To: Martin Blumenstingl, linux-amlogic, linux-mtd, bbrezillon, miquel.raynal
Cc: Martin Blumenstingl, richard, liang.yang, linux-kernel, jianxin.pan
Martin Blumenstingl <martin.blumenstingl@googlemail.com> writes:
> kzalloc() can return NULL if memory could not be allocated. Check the
> return value of the kzalloc() call in meson_nfc_read_buf() to make it
> consistent with other memory allocations within the meson_nand driver.
>
> Fixes: 8fae856c53500a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Acked-by: Liang Yang <liang.yang@amlogic.com>
Reviewed-by: Kevin Hilman <khilman@baylibre.com>
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf
2019-03-18 20:47 ` [PATCH v2 2/2] mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf Martin Blumenstingl
@ 2019-03-19 16:17 ` Kevin Hilman
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Hilman @ 2019-03-19 16:17 UTC (permalink / raw)
To: Martin Blumenstingl, linux-amlogic, linux-mtd, bbrezillon, miquel.raynal
Cc: Martin Blumenstingl, richard, liang.yang, linux-kernel, jianxin.pan
Martin Blumenstingl <martin.blumenstingl@googlemail.com> writes:
> meson_nfc_dma_buffer_setup() is called with the "info" buffer which is
> allocated a few lines before using kzalloc(). If
> meson_nfc_dma_buffer_setup() fails we need to free the allocated "info"
> buffer instead of only freeing it upon success.
>
> Fixes: 8fae856c53500a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Acked-by: Liang Yang <liang.yang@amlogic.com>
Reviewed-by: Kevin Hilman <khilman@baylibre.com>
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] meson-nand: two small memory related fixes
2019-03-18 20:47 [PATCH v2 0/2] meson-nand: two small memory related fixes Martin Blumenstingl
2019-03-18 20:47 ` [PATCH v2 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf() Martin Blumenstingl
2019-03-18 20:47 ` [PATCH v2 2/2] mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf Martin Blumenstingl
@ 2019-04-01 15:27 ` Miquel Raynal
2 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2019-04-01 15:27 UTC (permalink / raw)
To: Martin Blumenstingl
Cc: jianxin.pan, bbrezillon, richard, linux-kernel, liang.yang,
linux-mtd, linux-amlogic
Hi Martin,
Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote on Mon,
18 Mar 2019 21:47:20 +0100:
> While trying to add support for older Meson SoCs to the meson-nand
> driver I was experiencing a crash in meson_nfc_read_buf(). While trying
> to find out why that happened I inspected the code in that function and
> found that there's:
> - a missing check on the return value of a kzalloc() call
> - a potential memory leak in it
>
> Both fixes have nothing to do with my original crash (for which I'll
> open a separate thread).
>
>
> Changes since v1:
> - collected Liang's Acked-by's (thank you!)
> - rebased on top of v5.1-rc1
>
>
> Martin Blumenstingl (2):
> mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf()
> mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf
>
> drivers/mtd/nand/raw/meson_nand.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
Applied to git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git
on nand/next.
Thanks,
Miquèl
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-04-01 15:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 20:47 [PATCH v2 0/2] meson-nand: two small memory related fixes Martin Blumenstingl
2019-03-18 20:47 ` [PATCH v2 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf() Martin Blumenstingl
2019-03-19 16:16 ` Kevin Hilman
2019-03-18 20:47 ` [PATCH v2 2/2] mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf Martin Blumenstingl
2019-03-19 16:17 ` Kevin Hilman
2019-04-01 15:27 ` [PATCH v2 0/2] meson-nand: two small memory related fixes Miquel Raynal
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).