diff mbox series

[v2] mtd: lpddr2_nvm: Fix possible null-ptr-deref

Message ID 20221114090240.244172-1-tanghui20@huawei.com
State Accepted
Headers show
Series [v2] mtd: lpddr2_nvm: Fix possible null-ptr-deref | expand

Commit Message

Hui Tang Nov. 14, 2022, 9:02 a.m. UTC
It will cause null-ptr-deref when resource_size(add_range) invoked,
if platform_get_resource() returns NULL.

Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
Signed-off-by: Hui Tang <tanghui20@huawei.com>
---
v1 -> v2:
 - replace IS_ERR(add_range) with !add_range
 - fix commit subject format
---
 drivers/mtd/lpddr/lpddr2_nvm.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Uwe Kleine-König Nov. 14, 2022, 9:30 a.m. UTC | #1
On Mon, Nov 14, 2022 at 05:02:40PM +0800, Hui Tang wrote:
> It will cause null-ptr-deref when resource_size(add_range) invoked,
> if platform_get_resource() returns NULL.
> 
> Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
> Signed-off-by: Hui Tang <tanghui20@huawei.com>

Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe
Miquel Raynal Nov. 17, 2022, 9:16 p.m. UTC | #2
On Mon, 2022-11-14 at 09:02:40 UTC, Hui Tang wrote:
> It will cause null-ptr-deref when resource_size(add_range) invoked,
> if platform_get_resource() returns NULL.
> 
> Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
> Signed-off-by: Hui Tang <tanghui20@huawei.com>
> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel
diff mbox series

Patch

diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c
index 367e2d906de0..e71af4c49096 100644
--- a/drivers/mtd/lpddr/lpddr2_nvm.c
+++ b/drivers/mtd/lpddr/lpddr2_nvm.c
@@ -433,6 +433,8 @@  static int lpddr2_nvm_probe(struct platform_device *pdev)
 
 	/* lpddr2_nvm address range */
 	add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!add_range)
+		return -ENODEV;
 
 	/* Populate map_info data structure */
 	*map = (struct map_info) {