linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception
@ 2020-12-22  8:48 Md Sadre Alam
  2020-12-31  6:41 ` Veerabhadrarao Badiganti
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Md Sadre Alam @ 2020-12-22  8:48 UTC (permalink / raw)
  To: bjorn.andersson, adrian.hunter, ulf.hansson, linux-arm-msm,
	linux-mmc, linux-kernel
  Cc: mdalam, sricharan

of_device_get_match_data returns NULL when no match.
So add the NULL pointer check to avoid dereference.

Signed-off-by: Md Sadre Alam <mdalam@codeaurora.org>
---
 drivers/mmc/host/sdhci-msm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 9c7927b..f20e424 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -2235,6 +2235,8 @@ static int sdhci_msm_probe(struct platform_device *pdev)
 	 * the data associated with the version info.
 	 */
 	var_info = of_device_get_match_data(&pdev->dev);
+	if (!var_info)
+		goto pltfm_free;
 
 	msm_host->mci_removed = var_info->mci_removed;
 	msm_host->restore_dll_config = var_info->restore_dll_config;
-- 
2.7.4


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

* Re: [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception
  2020-12-22  8:48 [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception Md Sadre Alam
@ 2020-12-31  6:41 ` Veerabhadrarao Badiganti
  2021-01-05 14:39 ` Adrian Hunter
  2021-01-05 19:20 ` Bjorn Andersson
  2 siblings, 0 replies; 4+ messages in thread
From: Veerabhadrarao Badiganti @ 2020-12-31  6:41 UTC (permalink / raw)
  To: Md Sadre Alam, bjorn.andersson, adrian.hunter, ulf.hansson,
	linux-arm-msm, linux-mmc, linux-kernel
  Cc: sricharan


On 12/22/2020 2:18 PM, Md Sadre Alam wrote:
> of_device_get_match_data returns NULL when no match.
> So add the NULL pointer check to avoid dereference.
>
> Signed-off-by: Md Sadre Alam <mdalam@codeaurora.org>
> ---

Reviewed-by: Veerabhadrarao Badiganti <vbadigan@codeaurora.org>

>   drivers/mmc/host/sdhci-msm.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 9c7927b..f20e424 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -2235,6 +2235,8 @@ static int sdhci_msm_probe(struct platform_device *pdev)
>   	 * the data associated with the version info.
>   	 */
>   	var_info = of_device_get_match_data(&pdev->dev);
> +	if (!var_info)
> +		goto pltfm_free;
>   
>   	msm_host->mci_removed = var_info->mci_removed;
>   	msm_host->restore_dll_config = var_info->restore_dll_config;

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

* Re: [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception
  2020-12-22  8:48 [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception Md Sadre Alam
  2020-12-31  6:41 ` Veerabhadrarao Badiganti
@ 2021-01-05 14:39 ` Adrian Hunter
  2021-01-05 19:20 ` Bjorn Andersson
  2 siblings, 0 replies; 4+ messages in thread
From: Adrian Hunter @ 2021-01-05 14:39 UTC (permalink / raw)
  To: Md Sadre Alam, bjorn.andersson, ulf.hansson, linux-arm-msm,
	linux-mmc, linux-kernel
  Cc: sricharan

On 22/12/20 10:48 am, Md Sadre Alam wrote:
> of_device_get_match_data returns NULL when no match.
> So add the NULL pointer check to avoid dereference.
> 
> Signed-off-by: Md Sadre Alam <mdalam@codeaurora.org>
> ---
>  drivers/mmc/host/sdhci-msm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 9c7927b..f20e424 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -2235,6 +2235,8 @@ static int sdhci_msm_probe(struct platform_device *pdev)
>  	 * the data associated with the version info.
>  	 */
>  	var_info = of_device_get_match_data(&pdev->dev);
> +	if (!var_info)

Shouldn't you set ret to -ENODEV here?

> +		goto pltfm_free;
>  
>  	msm_host->mci_removed = var_info->mci_removed;
>  	msm_host->restore_dll_config = var_info->restore_dll_config;
> 


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

* Re: [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception
  2020-12-22  8:48 [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception Md Sadre Alam
  2020-12-31  6:41 ` Veerabhadrarao Badiganti
  2021-01-05 14:39 ` Adrian Hunter
@ 2021-01-05 19:20 ` Bjorn Andersson
  2 siblings, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2021-01-05 19:20 UTC (permalink / raw)
  To: Md Sadre Alam
  Cc: adrian.hunter, ulf.hansson, linux-arm-msm, linux-mmc,
	linux-kernel, sricharan

On Tue 22 Dec 02:48 CST 2020, Md Sadre Alam wrote:

> of_device_get_match_data returns NULL when no match.
> So add the NULL pointer check to avoid dereference.
> 
> Signed-off-by: Md Sadre Alam <mdalam@codeaurora.org>
> ---
>  drivers/mmc/host/sdhci-msm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 9c7927b..f20e424 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -2235,6 +2235,8 @@ static int sdhci_msm_probe(struct platform_device *pdev)
>  	 * the data associated with the version info.
>  	 */
>  	var_info = of_device_get_match_data(&pdev->dev);
> +	if (!var_info)

To get this you (the SDHCI driver developer) needs to add an entry in
sdhci_msm_dt_match[] without a .data specified.

> +		goto pltfm_free;

And this will cause sdhci_msm_probe() to return 0, giving no hint to
said developer that they screwed up. Given that this can only be caused
by a developer working on this driver you should provide feedback
suitable for such developer, e.g. by:

	if (WARN_ON(!var_info))
		return -EINVAL;

But given that this is only for the developer himself, I don't see that
this adds any value over just reading the callstack you get from the
panic when the next line dereferences var_info (NULL).

Regards,
Bjorn

>  
>  	msm_host->mci_removed = var_info->mci_removed;
>  	msm_host->restore_dll_config = var_info->restore_dll_config;
> -- 
> 2.7.4
> 

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

end of thread, other threads:[~2021-01-05 19:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22  8:48 [PATCH] mmc: sdhci-msm: Fix possible NULL pointer exception Md Sadre Alam
2020-12-31  6:41 ` Veerabhadrarao Badiganti
2021-01-05 14:39 ` Adrian Hunter
2021-01-05 19:20 ` Bjorn Andersson

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).