kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mux: checking for IS_ERR() instead of NULL or vice versa
@ 2017-03-14  7:56 Dan Carpenter
  2017-03-14 16:47 ` Peter Rosin
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2017-03-14  7:56 UTC (permalink / raw)
  To: Peter Rosin; +Cc: linux-kernel, kernel-janitors

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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/mux/mux-core.c b/drivers/mux/mux-core.c
index 46088a0f9677..de678520a329 100644
--- a/drivers/mux/mux-core.c
+++ b/drivers/mux/mux-core.c
@@ -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;
diff --git a/drivers/mux/mux-gpio.c b/drivers/mux/mux-gpio.c
index 04c6e548ecdc..d0596a3c2f79 100644
--- a/drivers/mux/mux-gpio.c
+++ b/drivers/mux/mux-gpio.c
@@ -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);
diff --git a/drivers/mux/mux-adg792a.c b/drivers/mux/mux-adg792a.c
index d58971641fdc..8972f4f6c655 100644
--- a/drivers/mux/mux-adg792a.c
+++ b/drivers/mux/mux-adg792a.c
@@ -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;
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mux: checking for IS_ERR() instead of NULL or vice versa
  2017-03-14  7:56 [PATCH] mux: checking for IS_ERR() instead of NULL or vice versa Dan Carpenter
@ 2017-03-14 16:47 ` Peter Rosin
  2017-03-14 16:49   ` [PATCH] mux: core: fix error handling in devm_mux_chip_alloc Peter Rosin
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Rosin @ 2017-03-14 16:47 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-kernel, kernel-janitors

On 2017-03-14 08:56, Dan Carpenter wrote:
> 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] mux: core: fix error handling in devm_mux_chip_alloc
  2017-03-14 16:47 ` Peter Rosin
@ 2017-03-14 16:49   ` Peter Rosin
  2017-03-14 18:16     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Rosin @ 2017-03-14 16:49 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Peter Rosin, linux-kernel, kernel-janitors

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")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/mux/mux-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mux/mux-core.c b/drivers/mux/mux-core.c
index 900b88526f97..66a8bccfc3d7 100644
--- a/drivers/mux/mux-core.c
+++ b/drivers/mux/mux-core.c
@@ -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;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mux: core: fix error handling in devm_mux_chip_alloc
  2017-03-14 16:49   ` [PATCH] mux: core: fix error handling in devm_mux_chip_alloc Peter Rosin
@ 2017-03-14 18:16     ` Dan Carpenter
  2017-03-15 10:01       ` Peter Rosin
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2017-03-14 18:16 UTC (permalink / raw)
  To: Peter Rosin; +Cc: linux-kernel, kernel-janitors

Looks good!

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mux: core: fix error handling in devm_mux_chip_alloc
  2017-03-14 18:16     ` Dan Carpenter
@ 2017-03-15 10:01       ` Peter Rosin
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Rosin @ 2017-03-15 10:01 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-kernel, kernel-janitors

On 2017-03-14 19:16, Dan Carpenter wrote:
> Looks good!

Thanks, now pushed out to the for-next branch of

	https://gitlab.com/peda-linux/mux.git

Cheers,
peda


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-03-15 10:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14  7:56 [PATCH] mux: checking for IS_ERR() instead of NULL or vice versa Dan Carpenter
2017-03-14 16:47 ` Peter Rosin
2017-03-14 16:49   ` [PATCH] mux: core: fix error handling in devm_mux_chip_alloc Peter Rosin
2017-03-14 18:16     ` Dan Carpenter
2017-03-15 10:01       ` Peter Rosin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).