Skip to contentSkip to conversation

mmc: sdhci-msm: Fix possible NULL pointer exception

PATCH In review Md Sadre Alam 4 participants 4 messages Dec 22, 2020 – Jan 5, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: sdhci-msm: Fix possible NULL pointer exception

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

---
 drivers/mmc/host/sdhci-msm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-msm.c +2 -0
index 9c7927b..f20e424 100644
@@ -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;
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Md Sadre Alam

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

---

Quoted 16 lines
  drivers/mmc/host/sdhci-msm.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-msm.c +2 -0
index 9c7927b..f20e424 100644
@@ -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;
maintainer
#2 lore raw
In reply to Md Sadre Alam
Quoted 13 lines · Md Sadre Alam

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

---
 drivers/mmc/host/sdhci-msm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-msm.c +0 -0
index 9c7927b..f20e424 100644

drivers/mmc/host/sdhci-msm.c static int sdhci_msm_probe(struct platform_device *pdev) · line 2238

Quoted 4 lines
drivers/mmc/host/sdhci-msm.c +1 -0
@@ -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?

Quoted 5 lines
drivers/mmc/host/sdhci-msm.c +1 -0
+		goto pltfm_free;
 
 	msm_host->mci_removed = var_info->mci_removed;
 	msm_host->restore_dll_config = var_info->restore_dll_config;
#3 lore raw
In reply to Md Sadre Alam
Quoted 13 lines · Md Sadre Alam

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

---
 drivers/mmc/host/sdhci-msm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-msm.c +0 -0
index 9c7927b..f20e424 100644

drivers/mmc/host/sdhci-msm.c static int sdhci_msm_probe(struct platform_device *pdev) · line 2238

Quoted 4 lines
drivers/mmc/host/sdhci-msm.c +1 -0
@@ -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.

drivers/mmc/host/sdhci-msm.c static int sdhci_msm_probe(struct platform_device *pdev) · line 2239

Quoted 1 line
drivers/mmc/host/sdhci-msm.c +1 -0
+		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

Quoted 6 lines
drivers/mmc/host/sdhci-msm.c +0 -0
 	msm_host->mci_removed = var_info->mci_removed;
 	msm_host->restore_dll_config = var_info->restore_dll_config;
Signature · 1 line
2.7.4