* [PATCH] mfd: max77843: Fix max77843_chg_init() return on error
@ 2015-09-14 8:23 Javier Martinez Canillas
2015-09-15 2:20 ` Krzysztof Kozlowski
0 siblings, 1 reply; 3+ messages in thread
From: Javier Martinez Canillas @ 2015-09-14 8:23 UTC (permalink / raw)
To: linux-kernel; +Cc: Javier Martinez Canillas, Lee Jones, Samuel Ortiz
If i2c_new_dummy() fails in max77843_chg_init(), an PTR_ERR(NULL) is
returned which is 0. So the function was wrongly returning a success
value instead of an error code.
Fixes: c7f585fe46d8 ("mfd: max77843: Add max77843 MFD driver core driver")
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
---
drivers/mfd/max77843.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c
index c52162ea3d0a..586098f1b233 100644
--- a/drivers/mfd/max77843.c
+++ b/drivers/mfd/max77843.c
@@ -80,7 +80,7 @@ static int max77843_chg_init(struct max77693_dev *max77843)
if (!max77843->i2c_chg) {
dev_err(&max77843->i2c->dev,
"Cannot allocate I2C device for Charger\n");
- return PTR_ERR(max77843->i2c_chg);
+ return -ENODEV;
}
i2c_set_clientdata(max77843->i2c_chg, max77843);
--
2.4.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] mfd: max77843: Fix max77843_chg_init() return on error
2015-09-14 8:23 [PATCH] mfd: max77843: Fix max77843_chg_init() return on error Javier Martinez Canillas
@ 2015-09-15 2:20 ` Krzysztof Kozlowski
2015-09-20 4:17 ` Lee Jones
0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Kozlowski @ 2015-09-15 2:20 UTC (permalink / raw)
To: Javier Martinez Canillas; +Cc: linux-kernel, Lee Jones, Samuel Ortiz
2015-09-14 17:23 GMT+09:00 Javier Martinez Canillas <javier@osg.samsung.com>:
> If i2c_new_dummy() fails in max77843_chg_init(), an PTR_ERR(NULL) is
> returned which is 0. So the function was wrongly returning a success
> value instead of an error code.
>
> Fixes: c7f585fe46d8 ("mfd: max77843: Add max77843 MFD driver core driver")
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
>
> ---
>
> drivers/mfd/max77843.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Nice catch. I think this should go to stable. I did not try to
reproduce it but looking at the code this should lead to NULL pointer
exceptions on:
1. first access to max77843->regmap_chg (this won't actually happen
because charger driver was not merged);
2. first dereference of pointer returned by i2c_get_clientdata() which
will happen on first system suspend or device unbind/removal.
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Best regards,
Krzysztof
>
> diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c
> index c52162ea3d0a..586098f1b233 100644
> --- a/drivers/mfd/max77843.c
> +++ b/drivers/mfd/max77843.c
> @@ -80,7 +80,7 @@ static int max77843_chg_init(struct max77693_dev *max77843)
> if (!max77843->i2c_chg) {
> dev_err(&max77843->i2c->dev,
> "Cannot allocate I2C device for Charger\n");
> - return PTR_ERR(max77843->i2c_chg);
> + return -ENODEV;
> }
> i2c_set_clientdata(max77843->i2c_chg, max77843);
>
> --
> 2.4.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] mfd: max77843: Fix max77843_chg_init() return on error
2015-09-15 2:20 ` Krzysztof Kozlowski
@ 2015-09-20 4:17 ` Lee Jones
0 siblings, 0 replies; 3+ messages in thread
From: Lee Jones @ 2015-09-20 4:17 UTC (permalink / raw)
To: Krzysztof Kozlowski; +Cc: Javier Martinez Canillas, linux-kernel, Samuel Ortiz
On Tue, 15 Sep 2015, Krzysztof Kozlowski wrote:
> 2015-09-14 17:23 GMT+09:00 Javier Martinez Canillas <javier@osg.samsung.com>:
> > If i2c_new_dummy() fails in max77843_chg_init(), an PTR_ERR(NULL) is
> > returned which is 0. So the function was wrongly returning a success
> > value instead of an error code.
> >
> > Fixes: c7f585fe46d8 ("mfd: max77843: Add max77843 MFD driver core driver")
> > Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> >
> > ---
> >
> > drivers/mfd/max77843.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Nice catch. I think this should go to stable. I did not try to
> reproduce it but looking at the code this should lead to NULL pointer
> exceptions on:
> 1. first access to max77843->regmap_chg (this won't actually happen
> because charger driver was not merged);
> 2. first dereference of pointer returned by i2c_get_clientdata() which
> will happen on first system suspend or device unbind/removal.
>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Please re-send this with stable Cc'ed and Krzysztof's RB applied.
> > diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c
> > index c52162ea3d0a..586098f1b233 100644
> > --- a/drivers/mfd/max77843.c
> > +++ b/drivers/mfd/max77843.c
> > @@ -80,7 +80,7 @@ static int max77843_chg_init(struct max77693_dev *max77843)
> > if (!max77843->i2c_chg) {
> > dev_err(&max77843->i2c->dev,
> > "Cannot allocate I2C device for Charger\n");
> > - return PTR_ERR(max77843->i2c_chg);
> > + return -ENODEV;
> > }
> > i2c_set_clientdata(max77843->i2c_chg, max77843);
> >
> >
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-09-20 4:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-14 8:23 [PATCH] mfd: max77843: Fix max77843_chg_init() return on error Javier Martinez Canillas
2015-09-15 2:20 ` Krzysztof Kozlowski
2015-09-20 4:17 ` Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox