summaryrefslogtreecommitdiff
path: root/drivers/mtd/nand/core.c
diff options
context:
space:
mode:
authorAndrew Goodbody <andrew.goodbody@linaro.org>2025-07-31 17:21:32 +0100
committerMichael Trimarchi <michael@amarulasolutions.com>2025-08-23 16:37:26 +0200
commit6b156c62ced25d3f8aed64c81e471353b56d0f2c (patch)
tree48c4465035fb12099158203a07f5a8a265d8c7ce /drivers/mtd/nand/core.c
parentd246e70cf81d0a0d7cc49abd520c93df59d42e16 (diff)
mtd: nand: Do not dereference before NULL check
In nanddev_init mtd and memorg are assigned values that dereference nand but this happens before a NULL check for nand. Move the assignments after the NULL check. This issue was found by Smatch. Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Diffstat (limited to 'drivers/mtd/nand/core.c')
-rw-r--r--drivers/mtd/nand/core.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
index 472ad0bdefb..01ff6e3befa 100644
--- a/drivers/mtd/nand/core.c
+++ b/drivers/mtd/nand/core.c
@@ -201,8 +201,8 @@ EXPORT_SYMBOL_GPL(nanddev_mtd_erase);
int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
struct module *owner)
{
- struct mtd_info *mtd = nanddev_to_mtd(nand);
- struct nand_memory_organization *memorg = nanddev_get_memorg(nand);
+ struct mtd_info *mtd;
+ struct nand_memory_organization *memorg;
if (!nand || !ops)
return -EINVAL;
@@ -210,6 +210,9 @@ int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
if (!ops->erase || !ops->markbad || !ops->isbad)
return -EINVAL;
+ mtd = nanddev_to_mtd(nand);
+ memorg = nanddev_get_memorg(nand);
+
if (!memorg->bits_per_cell || !memorg->pagesize ||
!memorg->pages_per_eraseblock || !memorg->eraseblocks_per_lun ||
!memorg->planes_per_lun || !memorg->luns_per_target ||