mmux: mmio: fix IS_ERR() vs NULL check for mux_mmio_probe()
PATCH 1/1 mmux: mmio: fix IS_ERR() vs NULL check for mux_mmio_probe()
devm_kmalloc() returns NULL on failure, not an ERR_PTR value. The current IS_ERR() check will never catch allocation failures, which could lead to NULL pointer dereference.
--- drivers/mux/mmio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mux/mmio.c +4 -4
@@ -101,13 +101,13 @@ static int mux_mmio_probe(struct platform_device *pdev) mux_mmio =mux_chip_priv (mux_chip); mux_mmio->fields =devm_kmalloc (dev, num_fields *sizeof (*mux_mmio->fields),GFP_KERNEL ); -if (IS_ERR (mux_mmio->fields)) -return PTR_ERR (mux_mmio->fields); +if (!mux_mmio->fields) +return -ENOMEM ; mux_mmio->hardware_states =devm_kmalloc (dev, num_fields *sizeof (*mux_mmio->hardware_states),GFP_KERNEL ); -if (IS_ERR (mux_mmio->hardware_states)) -return PTR_ERR (mux_mmio->hardware_states); +if (!mux_mmio->hardware_states) +return -ENOMEM ;for (i =0 ; i < num_fields; i++) {struct mux_control *mux = &mux_chip->mux[i];
Signature · 1 line
2.43.0
Quoted 5 lines · Alper Ak
devm_kmalloc()returns NULL on failure, not anERR_PTRvalue. The currentIS_ERR()check will never catch allocation failures, which could lead to NULL pointer dereference.Signed-off-by Alper Ak <[email protected]>
Missing fixes tag.
Quoted 9 lines
--- drivers/mux/mmio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/mux/mmio.c +0
-0
drivers/mux/mmio.c static int mux_mmio_probe(struct platform_device *pdev) · line 105
Quoted 5 lines
drivers/mux/mmio.c +0
-2@@ -101,13 +101,13 @@ static int mux_mmio_probe(struct platform_device *pdev) mux_mmio =mux_chip_priv (mux_chip); mux_mmio->fields =devm_kmalloc (dev, num_fields *sizeof (*mux_mmio->fields),GFP_KERNEL ); -if (IS_ERR (mux_mmio->fields)) -return PTR_ERR (mux_mmio->fields);
I really wonder from where do the people sometimes copy code...
With missing tag:
Best regards,
Krzysztof
PATCH v2 1/1 mux: mmio: fix IS_ERR() vs NULL check for mux_mmio_probe()
devm_kmalloc() returns NULL on failure, not an ERR_PTR value. The current IS_ERR() check will never catch allocation failures, which could lead to NULL pointer dereference.
--- drivers/mux/mmio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mux/mmio.c +4 -4
@@ -101,13 +101,13 @@ static int mux_mmio_probe(struct platform_device *pdev) mux_mmio =mux_chip_priv (mux_chip); mux_mmio->fields =devm_kmalloc (dev, num_fields *sizeof (*mux_mmio->fields),GFP_KERNEL ); -if (IS_ERR (mux_mmio->fields)) -return PTR_ERR (mux_mmio->fields); +if (!mux_mmio->fields) +return -ENOMEM ; mux_mmio->hardware_states =devm_kmalloc (dev, num_fields *sizeof (*mux_mmio->hardware_states),GFP_KERNEL ); -if (IS_ERR (mux_mmio->hardware_states)) -return PTR_ERR (mux_mmio->hardware_states); +if (!mux_mmio->hardware_states) +return -ENOMEM ;for (i =0 ; i < num_fields; i++) {struct mux_control *mux = &mux_chip->mux[i];
Signature · 1 line
2.43.0