All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
@ 2017-07-07  6:39 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-07  6:39 UTC (permalink / raw)
  To: Thierry Reding, Maxime Ripard, Chen-Yu Tsai
  Cc: linux-pwm, linux-arm-kernel, linux-kernel, Gustavo A. R. Silva

Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/pwm/pwm-sun4i.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index 1284ffa..295ca19 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 
 	match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "failed to match device\n");
+		return -ENODEV;
+	}
 
 	pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
 	if (!pwm)
-- 
2.5.0

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

* [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
@ 2017-07-07  6:39 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-07  6:39 UTC (permalink / raw)
  To: linux-arm-kernel

Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/pwm/pwm-sun4i.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index 1284ffa..295ca19 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 
 	match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "failed to match device\n");
+		return -ENODEV;
+	}
 
 	pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
 	if (!pwm)
-- 
2.5.0

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

* Re: [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
  2017-07-07  6:39 ` Gustavo A. R. Silva
@ 2017-07-07  7:16   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 8+ messages in thread
From: Chen-Yu Tsai @ 2017-07-07  7:16 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Thierry Reding, Maxime Ripard, Chen-Yu Tsai, linux-pwm,
	linux-kernel, linux-arm-kernel

On Fri, Jul 7, 2017 at 2:39 PM, Gustavo A. R. Silva
<garsilva@embeddedor.com> wrote:
> Check return value from call to of_match_device()
> in order to prevent a NULL pointer dereference.
>
> In case of NULL print error message and return -ENODEV
>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/pwm/pwm-sun4i.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 1284ffa..295ca19 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
>         const struct of_device_id *match;
>
>         match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);

AFAIK this simply can not and should not fail with a device tree
only driver with properly populated of_device_id tables.

ChenYu

> +       if (!match) {
> +               dev_err(&pdev->dev, "failed to match device\n");
> +               return -ENODEV;
> +       }
>
>         pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
>         if (!pwm)
> --
> 2.5.0
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
@ 2017-07-07  7:16   ` Chen-Yu Tsai
  0 siblings, 0 replies; 8+ messages in thread
From: Chen-Yu Tsai @ 2017-07-07  7:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jul 7, 2017 at 2:39 PM, Gustavo A. R. Silva
<garsilva@embeddedor.com> wrote:
> Check return value from call to of_match_device()
> in order to prevent a NULL pointer dereference.
>
> In case of NULL print error message and return -ENODEV
>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/pwm/pwm-sun4i.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 1284ffa..295ca19 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
>         const struct of_device_id *match;
>
>         match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);

AFAIK this simply can not and should not fail with a device tree
only driver with properly populated of_device_id tables.

ChenYu

> +       if (!match) {
> +               dev_err(&pdev->dev, "failed to match device\n");
> +               return -ENODEV;
> +       }
>
>         pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
>         if (!pwm)
> --
> 2.5.0
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
  2017-07-07  7:16   ` Chen-Yu Tsai
@ 2017-07-07  9:33     ` Thierry Reding
  -1 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2017-07-07  9:33 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Gustavo A. R. Silva, Maxime Ripard, linux-pwm, linux-kernel,
	linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 1352 bytes --]

On Fri, Jul 07, 2017 at 03:16:23PM +0800, Chen-Yu Tsai wrote:
> On Fri, Jul 7, 2017 at 2:39 PM, Gustavo A. R. Silva
> <garsilva@embeddedor.com> wrote:
> > Check return value from call to of_match_device()
> > in order to prevent a NULL pointer dereference.
> >
> > In case of NULL print error message and return -ENODEV
> >
> > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> > ---
> >  drivers/pwm/pwm-sun4i.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> > index 1284ffa..295ca19 100644
> > --- a/drivers/pwm/pwm-sun4i.c
> > +++ b/drivers/pwm/pwm-sun4i.c
> > @@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
> >         const struct of_device_id *match;
> >
> >         match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
> 
> AFAIK this simply can not and should not fail with a device tree
> only driver with properly populated of_device_id tables.

Technically this could happen if someone manually created the platform
device. In that case the core will try to match by name if there is no
device node to use for a match against the list of of_device_ids.

In my opinion it's best to let things crash in this situation to make
it really obvious that people have done something wrong.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
@ 2017-07-07  9:33     ` Thierry Reding
  0 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2017-07-07  9:33 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jul 07, 2017 at 03:16:23PM +0800, Chen-Yu Tsai wrote:
> On Fri, Jul 7, 2017 at 2:39 PM, Gustavo A. R. Silva
> <garsilva@embeddedor.com> wrote:
> > Check return value from call to of_match_device()
> > in order to prevent a NULL pointer dereference.
> >
> > In case of NULL print error message and return -ENODEV
> >
> > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> > ---
> >  drivers/pwm/pwm-sun4i.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> > index 1284ffa..295ca19 100644
> > --- a/drivers/pwm/pwm-sun4i.c
> > +++ b/drivers/pwm/pwm-sun4i.c
> > @@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
> >         const struct of_device_id *match;
> >
> >         match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
> 
> AFAIK this simply can not and should not fail with a device tree
> only driver with properly populated of_device_id tables.

Technically this could happen if someone manually created the platform
device. In that case the core will try to match by name if there is no
device node to use for a match against the list of of_device_ids.

In my opinion it's best to let things crash in this situation to make
it really obvious that people have done something wrong.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170707/7dc65b25/attachment-0001.sig>

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

* Re: [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
  2017-07-07  9:33     ` Thierry Reding
@ 2017-07-10 19:26       ` Gustavo A. R. Silva
  -1 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-10 19:26 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Chen-Yu Tsai, Maxime Ripard, linux-pwm, linux-kernel, linux-arm-kernel

Hi all,

Quoting Thierry Reding <thierry.reding@gmail.com>:

> On Fri, Jul 07, 2017 at 03:16:23PM +0800, Chen-Yu Tsai wrote:
>> On Fri, Jul 7, 2017 at 2:39 PM, Gustavo A. R. Silva
>> <garsilva@embeddedor.com> wrote:
>> > Check return value from call to of_match_device()
>> > in order to prevent a NULL pointer dereference.
>> >
>> > In case of NULL print error message and return -ENODEV
>> >
>> > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> > ---
>> >  drivers/pwm/pwm-sun4i.c | 4 ++++
>> >  1 file changed, 4 insertions(+)
>> >
>> > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
>> > index 1284ffa..295ca19 100644
>> > --- a/drivers/pwm/pwm-sun4i.c
>> > +++ b/drivers/pwm/pwm-sun4i.c
>> > @@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct  
>> platform_device *pdev)
>> >         const struct of_device_id *match;
>> >
>> >         match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
>>
>> AFAIK this simply can not and should not fail with a device tree
>> only driver with properly populated of_device_id tables.
>
> Technically this could happen if someone manually created the platform
> device. In that case the core will try to match by name if there is no
> device node to use for a match against the list of of_device_ids.
>
> In my opinion it's best to let things crash in this situation to make
> it really obvious that people have done something wrong.
>

I get it.

Thanks for clarifying.
--
Gustavo A. R. Silva

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

* [PATCH] pwm: sun4i: add NULL check on of_match_device() return value
@ 2017-07-10 19:26       ` Gustavo A. R. Silva
  0 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-10 19:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi all,

Quoting Thierry Reding <thierry.reding@gmail.com>:

> On Fri, Jul 07, 2017 at 03:16:23PM +0800, Chen-Yu Tsai wrote:
>> On Fri, Jul 7, 2017 at 2:39 PM, Gustavo A. R. Silva
>> <garsilva@embeddedor.com> wrote:
>> > Check return value from call to of_match_device()
>> > in order to prevent a NULL pointer dereference.
>> >
>> > In case of NULL print error message and return -ENODEV
>> >
>> > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> > ---
>> >  drivers/pwm/pwm-sun4i.c | 4 ++++
>> >  1 file changed, 4 insertions(+)
>> >
>> > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
>> > index 1284ffa..295ca19 100644
>> > --- a/drivers/pwm/pwm-sun4i.c
>> > +++ b/drivers/pwm/pwm-sun4i.c
>> > @@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct  
>> platform_device *pdev)
>> >         const struct of_device_id *match;
>> >
>> >         match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
>>
>> AFAIK this simply can not and should not fail with a device tree
>> only driver with properly populated of_device_id tables.
>
> Technically this could happen if someone manually created the platform
> device. In that case the core will try to match by name if there is no
> device node to use for a match against the list of of_device_ids.
>
> In my opinion it's best to let things crash in this situation to make
> it really obvious that people have done something wrong.
>

I get it.

Thanks for clarifying.
--
Gustavo A. R. Silva

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

end of thread, other threads:[~2017-07-10 19:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-07  6:39 [PATCH] pwm: sun4i: add NULL check on of_match_device() return value Gustavo A. R. Silva
2017-07-07  6:39 ` Gustavo A. R. Silva
2017-07-07  7:16 ` Chen-Yu Tsai
2017-07-07  7:16   ` Chen-Yu Tsai
2017-07-07  9:33   ` Thierry Reding
2017-07-07  9:33     ` Thierry Reding
2017-07-10 19:26     ` Gustavo A. R. Silva
2017-07-10 19:26       ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.