Skip to contentSkip to conversation

mux: checking for IS_ERR() instead of NULL or vice versa

PATCH In review Dan Carpenter 2 participants 5 messages Mar 14, 2017 – Mar 15, 2017

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

PATCH 1/1 mux: checking for IS_ERR() instead of NULL or vice versa

This error handling is mixed up. mux_chip_alloc() doesn't return error pointers but devm_mux_chip_alloc() does.

Fixes 4f5078327db1 ("mux: minimal mux subsystem and gpio-based mux controller")
drivers/mux/mux-core.c +2 -2
index 46088a0f9677..de678520a329 100644
@@ -167,9 +167,9 @@ struct mux_chip *devm_mux_chip_alloc(struct device *dev,
 		return ERR_PTR(-ENOMEM);
 
 	mux_chip = mux_chip_alloc(dev, controllers, sizeof_priv);
-	if (IS_ERR(mux_chip)) {
+	if (!mux_chip) {
 		devres_free(ptr);
-		return mux_chip;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	*ptr = mux_chip;
drivers/mux/mux-gpio.c +2 -2
index 04c6e548ecdc..d0596a3c2f79 100644
@@ -63,8 +63,8 @@ static int mux_gpio_probe(struct platform_device *pdev)
 
 	mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux_gpio) +
 				       pins * sizeof(*mux_gpio->val));
-	if (!mux_chip)
-		return -ENOMEM;
+	if (IS_ERR(mux_chip))
+		return PTR_ERR(mux_chip);
 
 	mux_gpio = mux_chip_priv(mux_chip);
 	mux_gpio->val = (int *)(mux_gpio + 1);
drivers/mux/mux-adg792a.c +2 -2
index d58971641fdc..8972f4f6c655 100644
@@ -65,8 +65,8 @@ static int adg792a_probe(struct i2c_client *i2c,
 		return -EINVAL;
 
 	mux_chip = devm_mux_chip_alloc(dev, cells ? 3 : 1, 0);
-	if (!mux_chip)
-		return -ENOMEM;
+	if (IS_ERR(mux_chip))
+		return PTR_ERR(mux_chip);
 
 	mux_chip->ops = &adg792a_ops;
 
#1 lore raw
Quoted 5 lines · Dan Carpenter

This error handling is mixed up. mux_chip_alloc() doesn't return error pointers but devm_mux_chip_alloc() does.

Fixes 4f5078327db1 ("mux: minimal mux subsystem and gpio-based mux controller")

Eeek, thanks for pointing this out! I have apparently stared at this for too long...

However, you did not update the documentation (in include/linux/mux.h) to match the code, so I'm going to use an alternative (and more localized) patch instead to align the code with the documentation.

Patch in followup email, please review! I also updated the Fixes tag since I have amended the buggy patch since the version that is currently in linux-next was picked up (linux-next isn't getting any updates this week, which is why you're seeing "old" stuff).

Cheers,
Peter

#2 lore raw

PATCH 1/1 mux: core: fix error handling in devm_mux_chip_alloc

The error handling is mixed up. mux_chip_alloc() doesn't return an error pointer (just NULL on failure), so check for NULL instead of using IS_ERR. devm_mux_chip_alloc is documented to return NULL on failure, so fix that as well.

All users of devm_mux_chip_alloc() are coded according to documentation.

Fixes a11c524a6b90 ("mux: minimal mux subsystem and gpio-based mux controller")
---
 drivers/mux/mux-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mux/mux-core.c +3 -3
index 900b88526f97..66a8bccfc3d7 100644
@@ -166,12 +166,12 @@ struct mux_chip *devm_mux_chip_alloc(struct device *dev,
 
 	ptr = devres_alloc(devm_mux_chip_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
-		return ERR_PTR(-ENOMEM);
+		return NULL;
 
 	mux_chip = mux_chip_alloc(dev, controllers, sizeof_priv);
-	if (IS_ERR(mux_chip)) {
+	if (!mux_chip) {
 		devres_free(ptr);
-		return mux_chip;
+		return NULL;
 	}
 
 	*ptr = mux_chip;
Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH] mux: core: fix error handling in devm_mux_chip_alloc

Looks good!

regards,
dan carpenter