All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Sound: soc: samsung - Fix possible NULL derefrence.
       [not found] <CGME20170130050433epcas3p158c643fc3cba0b3b616dc24a50e11bc0@epcas3p1.samsung.com>
@ 2017-01-30  5:04 ` Shailendra Verma
  2017-01-30 13:34   ` [alsa-devel] " Sylwester Nawrocki
  0 siblings, 1 reply; 2+ messages in thread
From: Shailendra Verma @ 2017-01-30  5:04 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Sangbeom Kim, Sylwester Nawrocki,
	Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	alsa-devel, linux-kernel, p.shailesh, ashish.kalra,
	Shailendra Verma, Shailendra Verma

of_device_get_match_data could return NULL, and so can cause
a NULL pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 sound/soc/samsung/i2s.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index 7825bff..b5acce2 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -1224,8 +1224,13 @@ static int samsung_i2s_probe(struct platform_device *pdev)
 	const struct samsung_i2s_dai_data *i2s_dai_data;
 	int ret;
 
-	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
+	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
 		i2s_dai_data = of_device_get_match_data(&pdev->dev);
+		if (!i2s_dai_data) {
+			dev_err(&pdev->dev, "no device match found\n");
+			return -ENODEV;
+		}
+	}
 	else
 		i2s_dai_data = (struct samsung_i2s_dai_data *)
 				platform_get_device_id(pdev)->driver_data;
-- 
1.7.9.5

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

* Re: [alsa-devel] [PATCH] Sound: soc: samsung - Fix possible NULL derefrence.
  2017-01-30  5:04 ` [PATCH] Sound: soc: samsung - Fix possible NULL derefrence Shailendra Verma
@ 2017-01-30 13:34   ` Sylwester Nawrocki
  0 siblings, 0 replies; 2+ messages in thread
From: Sylwester Nawrocki @ 2017-01-30 13:34 UTC (permalink / raw)
  To: Shailendra Verma, p.shailesh, ashish.kalra, Shailendra Verma
  Cc: Krzysztof Kozlowski, Sangbeom Kim, Liam Girdwood, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

On 01/30/2017 06:04 AM, Shailendra Verma wrote:
> of_device_get_match_data could return NULL, and so can cause
> a NULL pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
> ---
>  sound/soc/samsung/i2s.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
> index 7825bff..b5acce2 100644
> --- a/sound/soc/samsung/i2s.c
> +++ b/sound/soc/samsung/i2s.c
> @@ -1224,8 +1224,13 @@ static int samsung_i2s_probe(struct platform_device *pdev)
>  	const struct samsung_i2s_dai_data *i2s_dai_data;
>  	int ret;
>  
> -	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
> +	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
>  		i2s_dai_data = of_device_get_match_data(&pdev->dev);
> +		if (!i2s_dai_data) {
> +			dev_err(&pdev->dev, "no device match found\n");
> +			return -ENODEV;
> +		}
> +	}

As Javier commented on similar patch for gpu/drm/exynos i2s_dai_data
can't be NULL as for DT case all struct of_device_id::data entries
are initialized in this driver and the probe callback can only be
called when device's compatible string got matched with one of entries
in the OF device id table.

>  	else
>  		i2s_dai_data = (struct samsung_i2s_dai_data *)
>  				platform_get_device_id(pdev)->driver_data;
> 

Similarly in non-dt case all struct_device_id::driver_data entries
are initialized so i2s_dai_data normally also cannot be NULL here.
If we were adding a sanity check for i2s_dai_data, it would need to
be here to cover both dt and non-dt.

I don't think this patch is necessary.  The error log above is slightly
misleading as actual device/driver matching happens already before
probe() is called.

-- 
Thanks,
Sylwester

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

end of thread, other threads:[~2017-01-30 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170130050433epcas3p158c643fc3cba0b3b616dc24a50e11bc0@epcas3p1.samsung.com>
2017-01-30  5:04 ` [PATCH] Sound: soc: samsung - Fix possible NULL derefrence Shailendra Verma
2017-01-30 13:34   ` [alsa-devel] " Sylwester Nawrocki

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.