Skip to contentSkip to conversation

mux: mmio: Fix IS_ERR() vs NULL check in probe()

PATCH In review Dan Carpenter 2 participants 2 messages Nov 29, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mux: mmio: Fix IS_ERR() vs NULL check in probe()

The devm_kmalloc() function never returns error pointers, it returns NULL on error. Fix the error checking.

Fixes 4863cb2b0f50 ("mux: mmio: Add suspend and resume support")
---
 drivers/mux/mmio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mux/mmio.c +4 -4
index e4ddb1e61923..3409af1ffb80 100644
@@ -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.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Dan Carpenter

The devm_kmalloc() function never returns error pointers, it returns NULL on error. Fix the error checking.

Fixes 4863cb2b0f50 ("mux: mmio: Add suspend and resume support")
---
 drivers/mux/mmio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mux/mmio.c +0 -0
index e4ddb1e61923..3409af1ffb80 100644

drivers/mux/mmio.c static int mux_mmio_probe(struct platform_device *pdev) · line 106

Quoted 8 lines
drivers/mux/mmio.c +2 -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);
+	if (!mux_mmio->fields)
+		return -ENOMEM;
 

I wonder from where Thomas copied this code...

@Greg, that's a fix for something in your tree.

Best regards,
Krzysztof