diff mbox

i2c-s3c2410: Fix potential NULL pointer dereference

Message ID 1347958128-13146-1-git-send-email-sachin.kamat@linaro.org
State Rejected
Headers show

Commit Message

Sachin Kamat Sept. 18, 2012, 8:48 a.m. UTC
of_match_node() returns NULL if a device_node does not have
a matching of_match structure. Thus the return value needs to be
checked for NULL to avoid NULL pointer dereferencing.

Cc: Wolfram Sang <w.sang@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
 drivers/i2c/busses/i2c-s3c2410.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Sachin Kamat Sept. 24, 2012, 3:54 a.m. UTC | #1
ping..

On 18 September 2012 14:18, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> of_match_node() returns NULL if a device_node does not have
> a matching of_match structure. Thus the return value needs to be
> checked for NULL to avoid NULL pointer dereferencing.
>
> Cc: Wolfram Sang <w.sang@pengutronix.de>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> Cc: Rob Herring <rob.herring@calxeda.com>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
>  drivers/i2c/busses/i2c-s3c2410.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
> index 5ae3b02..d906523 100644
> --- a/drivers/i2c/busses/i2c-s3c2410.c
> +++ b/drivers/i2c/busses/i2c-s3c2410.c
> @@ -123,6 +123,8 @@ static inline unsigned int s3c24xx_get_device_quirks(struct platform_device *pde
>         if (pdev->dev.of_node) {
>                 const struct of_device_id *match;
>                 match = of_match_node(s3c24xx_i2c_match, pdev->dev.of_node);
> +               if (!match)
> +                       return 0;
>                 return (unsigned int)match->data;
>         }
>
> --
> 1.7.4.1
>
Sachin Kamat Sept. 26, 2012, 4:07 a.m. UTC | #2
Hi,

Can we have this fix for the 3.6 series please?

On 18 September 2012 14:18, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> of_match_node() returns NULL if a device_node does not have
> a matching of_match structure. Thus the return value needs to be
> checked for NULL to avoid NULL pointer dereferencing.
>
> Cc: Wolfram Sang <w.sang@pengutronix.de>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> Cc: Rob Herring <rob.herring@calxeda.com>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
>  drivers/i2c/busses/i2c-s3c2410.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
> index 5ae3b02..d906523 100644
> --- a/drivers/i2c/busses/i2c-s3c2410.c
> +++ b/drivers/i2c/busses/i2c-s3c2410.c
> @@ -123,6 +123,8 @@ static inline unsigned int s3c24xx_get_device_quirks(struct platform_device *pde
>         if (pdev->dev.of_node) {
>                 const struct of_device_id *match;
>                 match = of_match_node(s3c24xx_i2c_match, pdev->dev.of_node);
> +               if (!match)
> +                       return 0;
>                 return (unsigned int)match->data;
>         }
>
> --
> 1.7.4.1
>
Wolfram Sang Oct. 6, 2012, 1:37 p.m. UTC | #3
On Tue, Sep 18, 2012 at 02:18:48PM +0530, Sachin Kamat wrote:
> of_match_node() returns NULL if a device_node does not have
> a matching of_match structure. Thus the return value needs to be
> checked for NULL to avoid NULL pointer dereferencing.

I am missing how the driver can be matched to the device if there is no
fitting device node?
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 5ae3b02..d906523 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -123,6 +123,8 @@  static inline unsigned int s3c24xx_get_device_quirks(struct platform_device *pde
 	if (pdev->dev.of_node) {
 		const struct of_device_id *match;
 		match = of_match_node(s3c24xx_i2c_match, pdev->dev.of_node);
+		if (!match)
+			return 0;
 		return (unsigned int)match->data;
 	}