All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] memory: atmel-sdramc: check of_device_get_match_data() return value
@ 2021-04-07 15:44 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-04-07 15:44 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Ludovic Desroches, linux-kernel, linux-arm-kernel

If the driver is probed, the of_device_get_match_data() should not
return NULL, however for sanity check its return value.

Addresses-Coverity: Dereference null return value
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 drivers/memory/atmel-sdramc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/memory/atmel-sdramc.c b/drivers/memory/atmel-sdramc.c
index 9c49d00c2a96..e09b2617f63d 100644
--- a/drivers/memory/atmel-sdramc.c
+++ b/drivers/memory/atmel-sdramc.c
@@ -45,6 +45,8 @@ static int atmel_ramc_probe(struct platform_device *pdev)
 	struct clk *clk;
 
 	caps = of_device_get_match_data(&pdev->dev);
+	if (!caps)
+		return -EINVAL;
 
 	if (caps->has_ddrck) {
 		clk = devm_clk_get(&pdev->dev, "ddrck");
-- 
2.25.1


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

* [PATCH] memory: atmel-sdramc: check of_device_get_match_data() return value
@ 2021-04-07 15:44 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-04-07 15:44 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Nicolas Ferre, Alexandre Belloni,
	Ludovic Desroches, linux-kernel, linux-arm-kernel

If the driver is probed, the of_device_get_match_data() should not
return NULL, however for sanity check its return value.

Addresses-Coverity: Dereference null return value
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 drivers/memory/atmel-sdramc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/memory/atmel-sdramc.c b/drivers/memory/atmel-sdramc.c
index 9c49d00c2a96..e09b2617f63d 100644
--- a/drivers/memory/atmel-sdramc.c
+++ b/drivers/memory/atmel-sdramc.c
@@ -45,6 +45,8 @@ static int atmel_ramc_probe(struct platform_device *pdev)
 	struct clk *clk;
 
 	caps = of_device_get_match_data(&pdev->dev);
+	if (!caps)
+		return -EINVAL;
 
 	if (caps->has_ddrck) {
 		clk = devm_clk_get(&pdev->dev, "ddrck");
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] memory: atmel-sdramc: check of_device_get_match_data() return value
  2021-04-07 15:44 ` Krzysztof Kozlowski
@ 2021-04-07 16:19   ` Alexandre Belloni
  -1 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2021-04-07 16:19 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Nicolas Ferre, Ludovic Desroches, linux-kernel, linux-arm-kernel

Hi,

On 07/04/2021 17:44:47+0200, Krzysztof Kozlowski wrote:
> If the driver is probed, the of_device_get_match_data() should not
> return NULL, however for sanity check its return value.
> 

As you say, there is no way this will ever be the case, I don't see the
point of checking the return value, this adds 12 bytes for nothing...

Maybe coverity should be fixed as there are many drivers making the same
(true) assumption and I don't think this is worth the churn.

> Addresses-Coverity: Dereference null return value
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> ---
>  drivers/memory/atmel-sdramc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/memory/atmel-sdramc.c b/drivers/memory/atmel-sdramc.c
> index 9c49d00c2a96..e09b2617f63d 100644
> --- a/drivers/memory/atmel-sdramc.c
> +++ b/drivers/memory/atmel-sdramc.c
> @@ -45,6 +45,8 @@ static int atmel_ramc_probe(struct platform_device *pdev)
>  	struct clk *clk;
>  
>  	caps = of_device_get_match_data(&pdev->dev);
> +	if (!caps)
> +		return -EINVAL;
>  
>  	if (caps->has_ddrck) {
>  		clk = devm_clk_get(&pdev->dev, "ddrck");
> -- 
> 2.25.1
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH] memory: atmel-sdramc: check of_device_get_match_data() return value
@ 2021-04-07 16:19   ` Alexandre Belloni
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2021-04-07 16:19 UTC (permalink / raw)
  To: Krzysztof Kozlowski; +Cc: Ludovic Desroches, linux-arm-kernel, linux-kernel

Hi,

On 07/04/2021 17:44:47+0200, Krzysztof Kozlowski wrote:
> If the driver is probed, the of_device_get_match_data() should not
> return NULL, however for sanity check its return value.
> 

As you say, there is no way this will ever be the case, I don't see the
point of checking the return value, this adds 12 bytes for nothing...

Maybe coverity should be fixed as there are many drivers making the same
(true) assumption and I don't think this is worth the churn.

> Addresses-Coverity: Dereference null return value
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> ---
>  drivers/memory/atmel-sdramc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/memory/atmel-sdramc.c b/drivers/memory/atmel-sdramc.c
> index 9c49d00c2a96..e09b2617f63d 100644
> --- a/drivers/memory/atmel-sdramc.c
> +++ b/drivers/memory/atmel-sdramc.c
> @@ -45,6 +45,8 @@ static int atmel_ramc_probe(struct platform_device *pdev)
>  	struct clk *clk;
>  
>  	caps = of_device_get_match_data(&pdev->dev);
> +	if (!caps)
> +		return -EINVAL;
>  
>  	if (caps->has_ddrck) {
>  		clk = devm_clk_get(&pdev->dev, "ddrck");
> -- 
> 2.25.1
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
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] 6+ messages in thread

* Re: [PATCH] memory: atmel-sdramc: check of_device_get_match_data() return value
  2021-04-07 16:19   ` Alexandre Belloni
@ 2021-04-07 16:55     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-04-07 16:55 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Nicolas Ferre, Ludovic Desroches, linux-kernel, linux-arm-kernel

On 07/04/2021 18:19, Alexandre Belloni wrote:
> Hi,
> 
> On 07/04/2021 17:44:47+0200, Krzysztof Kozlowski wrote:
>> If the driver is probed, the of_device_get_match_data() should not
>> return NULL, however for sanity check its return value.
>>
> 
> As you say, there is no way this will ever be the case, I don't see the
> point of checking the return value, this adds 12 bytes for nothing...
> 
> Maybe coverity should be fixed as there are many drivers making the same
> (true) assumption and I don't think this is worth the churn.

There are also several drivers having this check. To me an explicit NULL
check is better and more readable than non-obvious assumption that the
of_device_id table contains data for each entry and there is no other
bind method (like for OF+I2C drivers). Even if the case is not real,
this is nice, simple and explicit code.

Best regards,
Krzysztof

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

* Re: [PATCH] memory: atmel-sdramc: check of_device_get_match_data() return value
@ 2021-04-07 16:55     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-04-07 16:55 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Ludovic Desroches, linux-arm-kernel, linux-kernel

On 07/04/2021 18:19, Alexandre Belloni wrote:
> Hi,
> 
> On 07/04/2021 17:44:47+0200, Krzysztof Kozlowski wrote:
>> If the driver is probed, the of_device_get_match_data() should not
>> return NULL, however for sanity check its return value.
>>
> 
> As you say, there is no way this will ever be the case, I don't see the
> point of checking the return value, this adds 12 bytes for nothing...
> 
> Maybe coverity should be fixed as there are many drivers making the same
> (true) assumption and I don't think this is worth the churn.

There are also several drivers having this check. To me an explicit NULL
check is better and more readable than non-obvious assumption that the
of_device_id table contains data for each entry and there is no other
bind method (like for OF+I2C drivers). Even if the case is not real,
this is nice, simple and explicit code.

Best regards,
Krzysztof

_______________________________________________
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] 6+ messages in thread

end of thread, other threads:[~2021-04-07 16:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 15:44 [PATCH] memory: atmel-sdramc: check of_device_get_match_data() return value Krzysztof Kozlowski
2021-04-07 15:44 ` Krzysztof Kozlowski
2021-04-07 16:19 ` Alexandre Belloni
2021-04-07 16:19   ` Alexandre Belloni
2021-04-07 16:55   ` Krzysztof Kozlowski
2021-04-07 16:55     ` Krzysztof Kozlowski

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.