Skip to content

Commit

Permalink
mtd: rawnand: intel: check return value of devm_kasprintf()
Browse files Browse the repository at this point in the history
[ Upstream commit 74ac5b5 ]

devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful by
checking the pointer validity.

Fixes: 0b1039f ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20231019065537.318391-1-yiyang13@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yi Yang authored and gregkh committed Nov 28, 2023
1 parent 0b8fb17 commit 6fc0bc0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/mtd/nand/raw/intel-nand-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ static int ebu_nand_probe(struct platform_device *pdev)
ebu_host->cs_num = cs;

resname = devm_kasprintf(dev, GFP_KERNEL, "nand_cs%d", cs);
if (!resname) {
ret = -ENOMEM;
goto err_of_node_put;
}

ebu_host->cs[cs].chipaddr = devm_platform_ioremap_resource_byname(pdev,
resname);
if (IS_ERR(ebu_host->cs[cs].chipaddr)) {
Expand Down Expand Up @@ -655,6 +660,11 @@ static int ebu_nand_probe(struct platform_device *pdev)
}

resname = devm_kasprintf(dev, GFP_KERNEL, "addr_sel%d", cs);
if (!resname) {
ret = -ENOMEM;
goto err_cleanup_dma;
}

res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname);
if (!res) {
ret = -EINVAL;
Expand Down

0 comments on commit 6fc0bc0

Please sign in to comment.