* [PATCH] pwm: Fill pwm->args before calling pwm_request_from_chip()
@ 2016-05-17 10:35 Boris Brezillon
2016-05-17 10:35 ` Boris Brezillon
0 siblings, 1 reply; 4+ messages in thread
From: Boris Brezillon @ 2016-05-17 10:35 UTC (permalink / raw)
To: Thierry Reding, linux-pwm, Mika Penttilä
Cc: linux-kernel, linux-arm-kernel, Daniel Mack, Haojian Zhuang,
Robert Jarzmik, Boris Brezillon
Commit e39c0df1be5a ("pwm: Introduce the pwm_args concept"), moved the
period and polarity initialization steps into pwm_request_device() (called
by pwm_request_from_chip()) based on the pwm->args information.
Make sure we fill pwm->args fields before calling pwm_request_from_chip().
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reported-by: Mika Penttilä <mika.penttila@nextfour.com>
Fixes: e39c0df1be5a ("pwm: Introduce the pwm_args concept")
---
Mika,
Can you test after applying this patch and let me know if it fixes your
bug.
Thanks,
Boris
drivers/pwm/core.c | 12 ++++++------
drivers/pwm/pwm-pxa.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 427142d..3d2eeaa 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -143,10 +143,6 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
- pwm = pwm_request_from_chip(pc, args->args[0], NULL);
- if (IS_ERR(pwm))
- return pwm;
-
pwm->args.period = args->args[1];
if (args->args[2] & PWM_POLARITY_INVERTED)
@@ -154,6 +150,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
else
pwm->args.polarity = PWM_POLARITY_NORMAL;
+ pwm = pwm_request_from_chip(pc, args->args[0], NULL);
+ if (IS_ERR(pwm))
+ return pwm;
+
return pwm;
}
EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
@@ -169,12 +169,12 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
+ pwm->args.period = args->args[1];
+
pwm = pwm_request_from_chip(pc, args->args[0], NULL);
if (IS_ERR(pwm))
return pwm;
- pwm->args.period = args->args[1];
-
return pwm;
}
diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
index 58b709f..c33bd42 100644
--- a/drivers/pwm/pwm-pxa.c
+++ b/drivers/pwm/pwm-pxa.c
@@ -156,12 +156,12 @@ pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
{
struct pwm_device *pwm;
+ pwm->args.period = args->args[0];
+
pwm = pwm_request_from_chip(pc, 0, NULL);
if (IS_ERR(pwm))
return pwm;
- pwm->args.period = args->args[0];
-
return pwm;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] pwm: Fill pwm->args before calling pwm_request_from_chip()
2016-05-17 10:35 [PATCH] pwm: Fill pwm->args before calling pwm_request_from_chip() Boris Brezillon
@ 2016-05-17 10:35 ` Boris Brezillon
2016-05-17 11:04 ` Thierry Reding
0 siblings, 1 reply; 4+ messages in thread
From: Boris Brezillon @ 2016-05-17 10:35 UTC (permalink / raw)
To: Thierry Reding, linux-pwm, Mika Penttilä
Cc: linux-kernel, linux-arm-kernel, Daniel Mack, Haojian Zhuang,
Robert Jarzmik, Boris Brezillon
Commit e39c0df1be5a ("pwm: Introduce the pwm_args concept"), moved the
period and polarity initialization steps into pwm_request_device() (called
by pwm_request_from_chip()) based on the pwm->args information.
Make sure we fill pwm->args fields before calling pwm_request_from_chip().
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reported-by: Mika Penttilä <mika.penttila@nextfour.com>
Fixes: e39c0df1be5a ("pwm: Introduce the pwm_args concept")
---
Mika,
Can you test after applying this patch and let me know if it fixes your
bug.
Thanks,
Boris
drivers/pwm/core.c | 12 ++++++------
drivers/pwm/pwm-pxa.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 427142d..3d2eeaa 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -143,10 +143,6 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
- pwm = pwm_request_from_chip(pc, args->args[0], NULL);
- if (IS_ERR(pwm))
- return pwm;
-
pwm->args.period = args->args[1];
if (args->args[2] & PWM_POLARITY_INVERTED)
@@ -154,6 +150,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
else
pwm->args.polarity = PWM_POLARITY_NORMAL;
+ pwm = pwm_request_from_chip(pc, args->args[0], NULL);
+ if (IS_ERR(pwm))
+ return pwm;
+
return pwm;
}
EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
@@ -169,12 +169,12 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
+ pwm->args.period = args->args[1];
+
pwm = pwm_request_from_chip(pc, args->args[0], NULL);
if (IS_ERR(pwm))
return pwm;
- pwm->args.period = args->args[1];
-
return pwm;
}
diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
index 58b709f..c33bd42 100644
--- a/drivers/pwm/pwm-pxa.c
+++ b/drivers/pwm/pwm-pxa.c
@@ -156,12 +156,12 @@ pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
{
struct pwm_device *pwm;
+ pwm->args.period = args->args[0];
+
pwm = pwm_request_from_chip(pc, 0, NULL);
if (IS_ERR(pwm))
return pwm;
- pwm->args.period = args->args[0];
-
return pwm;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] pwm: Fill pwm->args before calling pwm_request_from_chip()
2016-05-17 10:35 ` Boris Brezillon
@ 2016-05-17 11:04 ` Thierry Reding
2016-05-17 11:11 ` Boris Brezillon
0 siblings, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2016-05-17 11:04 UTC (permalink / raw)
To: Boris Brezillon
Cc: linux-pwm, Mika Penttilä, linux-kernel, linux-arm-kernel,
Daniel Mack, Haojian Zhuang, Robert Jarzmik
[-- Attachment #1: Type: text/plain, Size: 1602 bytes --]
On Tue, May 17, 2016 at 12:35:33PM +0200, Boris Brezillon wrote:
[...]
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 427142d..3d2eeaa 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -143,10 +143,6 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
> if (args->args[0] >= pc->npwm)
> return ERR_PTR(-EINVAL);
>
> - pwm = pwm_request_from_chip(pc, args->args[0], NULL);
> - if (IS_ERR(pwm))
> - return pwm;
> -
> pwm->args.period = args->args[1];
>
> if (args->args[2] & PWM_POLARITY_INVERTED)
> @@ -154,6 +150,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
> else
> pwm->args.polarity = PWM_POLARITY_NORMAL;
>
> + pwm = pwm_request_from_chip(pc, args->args[0], NULL);
> + if (IS_ERR(pwm))
> + return pwm;
> +
Can't do that, because now you're dereferencing an uninitialized
pointer.
> return pwm;
> }
> EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
> @@ -169,12 +169,12 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
> if (args->args[0] >= pc->npwm)
> return ERR_PTR(-EINVAL);
>
> + pwm->args.period = args->args[1];
Same here.
> diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
> index 58b709f..c33bd42 100644
> --- a/drivers/pwm/pwm-pxa.c
> +++ b/drivers/pwm/pwm-pxa.c
> @@ -156,12 +156,12 @@ pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
> {
> struct pwm_device *pwm;
>
> + pwm->args.period = args->args[0];
And here.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] pwm: Fill pwm->args before calling pwm_request_from_chip()
2016-05-17 11:04 ` Thierry Reding
@ 2016-05-17 11:11 ` Boris Brezillon
0 siblings, 0 replies; 4+ messages in thread
From: Boris Brezillon @ 2016-05-17 11:11 UTC (permalink / raw)
To: Thierry Reding
Cc: linux-pwm, Mika Penttilä, linux-kernel, linux-arm-kernel,
Daniel Mack, Haojian Zhuang, Robert Jarzmik
On Tue, 17 May 2016 13:04:38 +0200
Thierry Reding <thierry.reding@gmail.com> wrote:
> On Tue, May 17, 2016 at 12:35:33PM +0200, Boris Brezillon wrote:
> [...]
> > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> > index 427142d..3d2eeaa 100644
> > --- a/drivers/pwm/core.c
> > +++ b/drivers/pwm/core.c
> > @@ -143,10 +143,6 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
> > if (args->args[0] >= pc->npwm)
> > return ERR_PTR(-EINVAL);
> >
> > - pwm = pwm_request_from_chip(pc, args->args[0], NULL);
> > - if (IS_ERR(pwm))
> > - return pwm;
> > -
> > pwm->args.period = args->args[1];
> >
> > if (args->args[2] & PWM_POLARITY_INVERTED)
> > @@ -154,6 +150,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
> > else
> > pwm->args.polarity = PWM_POLARITY_NORMAL;
> >
> > + pwm = pwm_request_from_chip(pc, args->args[0], NULL);
> > + if (IS_ERR(pwm))
> > + return pwm;
> > +
>
> Can't do that, because now you're dereferencing an uninitialized
> pointer.
Yes, forget this patch, it's not needed anyway since all PWM users are
now directly calling pwm_apply_args() after requesting the PWM. The bad
news is I broke bisectibilty :-(.
Still does not explain the bug reported by Mika.
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-05-17 11:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-17 10:35 [PATCH] pwm: Fill pwm->args before calling pwm_request_from_chip() Boris Brezillon
2016-05-17 10:35 ` Boris Brezillon
2016-05-17 11:04 ` Thierry Reding
2016-05-17 11:11 ` Boris Brezillon
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).