mux: checking for IS_ERR() instead of NULL or vice versa
Subsystems (2)
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.
drivers/mux/mux-core.c +2 -2
@@ -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
@@ -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
@@ -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;
Quoted 5 lines · Dan Carpenter
This error handling is mixed up.
mux_chip_alloc()doesn't return error pointers butdevm_mux_chip_alloc()does.Fixes 4f5078327db1 ("mux: minimal mux subsystem and gpio-based mux controller")Signed-off-by Dan Carpenter <[email protected]>
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
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.
--- drivers/mux/mux-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mux/mux-core.c +3 -3
@@ -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
Re: [PATCH] mux: core: fix error handling in devm_mux_chip_alloc
Looks good!
regards,
dan carpenter
Re: [PATCH] mux: core: fix error handling in devm_mux_chip_alloc
Quoted 1 line · Dan Carpenter
Looks good!
Thanks, now pushed out to the for-next branch of
https://gitlab.com/peda-linux/mux.git
Cheers,
peda