mmc: host: dereference null return value
Subsystems (5)
PATCH 1/1 mmc: host: dereference null return value
From: Haibo Chen <[email protected]>
of_match_node() has the opportunity to return NULL, so need to dereference null return value.
This is reported by Coverity.
--- drivers/mmc/host/dw_mmc-exynos.c | 5 +++-- drivers/mmc/host/dw_mmc-k3.c | 5 +++-- drivers/mmc/host/dw_mmc-pltfm.c | 3 ++- drivers/mmc/host/sdhci-of-arasan.c | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-)
drivers/mmc/host/dw_mmc-exynos.c +3 -2
@@ -545,12 +545,13 @@ MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);static int dw_mci_exynos_probe (struct platform_device *pdev) { -const struct dw_mci_drv_data *drv_data; +const struct dw_mci_drv_data *drv_data =NULL ;const struct of_device_id *match;int ret; match =of_match_node (dw_mci_exynos_match, pdev->dev.of_node); - drv_data = match->data; +if (match) + drv_data = match->data;pm_runtime_get_noresume (&pdev->dev);pm_runtime_set_active (&pdev->dev);
drivers/mmc/host/dw_mmc-k3.c +3 -2
@@ -451,11 +451,12 @@ MODULE_DEVICE_TABLE(of, dw_mci_k3_match);static int dw_mci_k3_probe (struct platform_device *pdev) { -const struct dw_mci_drv_data *drv_data; +const struct dw_mci_drv_data *drv_data =NULL ;const struct of_device_id *match; match =of_match_node (dw_mci_k3_match, pdev->dev.of_node); - drv_data = match->data; +if (match) + drv_data = match->data;return dw_mci_pltfm_register (pdev, drv_data); }
drivers/mmc/host/dw_mmc-pltfm.c +2 -1
@@ -78,7 +78,8 @@ static int dw_mci_pltfm_probe(struct platform_device *pdev)if (pdev->dev.of_node) { match =of_match_node (dw_mci_pltfm_match, pdev->dev.of_node); - drv_data = match->data; +if (match) + drv_data = match->data; }return dw_mci_pltfm_register (pdev, drv_data);
drivers/mmc/host/sdhci-of-arasan.c +2 -0
@@ -1520,6 +1520,8 @@ static int sdhci_arasan_probe(struct platform_device *pdev)const struct sdhci_arasan_of_data *data; match =of_match_node (sdhci_arasan_of_match, pdev->dev.of_node); +if (match ==NULL ) +return -ENOPARAM ; data = match->data; host =sdhci_pltfm_init (pdev, data->pdata,sizeof (*sdhci_arasan));
Signature · 1 line
2.17.1
Adrian Hunter
maintainerQuoted 21 lines · On 23/06/20 7:06 am, [email protected] wrote:
From: Haibo Chen <[email protected]>
of_match_node()has the opportunity to return NULL, so need to dereference null return value.
This is reported by Coverity.Signed-off-by Haibo Chen <[email protected]>--- drivers/mmc/host/dw_mmc-exynos.c | 5 +++-- drivers/mmc/host/dw_mmc-k3.c | 5 +++-- drivers/mmc/host/dw_mmc-pltfm.c | 3 ++- drivers/mmc/host/sdhci-of-arasan.c | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-)drivers/mmc/host/dw_mmc-exynos.c +0
-0@@ -545,12 +545,13 @@ MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);static int dw_mci_exynos_probe (struct platform_device *pdev)
drivers/mmc/host/dw_mmc-exynos.c MODULE_DEVICE_TABLE(of, dw_mci_exynos_match); · line 554
Quoted 10 lines
drivers/mmc/host/dw_mmc-exynos.c +3
-2{ -const struct dw_mci_drv_data *drv_data; +const struct dw_mci_drv_data *drv_data =NULL ;const struct of_device_id *match;int ret; match =of_match_node (dw_mci_exynos_match, pdev->dev.of_node); - drv_data = match->data; +if (match) + drv_data = match->data;
Could be 1 line change:
drv_data = match ? match->data : NULL;
Quoted 9 lines
drivers/mmc/host/dw_mmc-exynos.c +0
-0pm_runtime_get_noresume (&pdev->dev);pm_runtime_set_active (&pdev->dev);drivers/mmc/host/dw_mmc-k3.c +0
-0@@ -451,11 +451,12 @@ MODULE_DEVICE_TABLE(of, dw_mci_k3_match);
drivers/mmc/host/dw_mmc-k3.c MODULE_DEVICE_TABLE(of, dw_mci_k3_match); · line 459
Quoted 10 lines
drivers/mmc/host/dw_mmc-k3.c +3
-2static int dw_mci_k3_probe (struct platform_device *pdev) { -const struct dw_mci_drv_data *drv_data; +const struct dw_mci_drv_data *drv_data =NULL ;const struct of_device_id *match; match =of_match_node (dw_mci_k3_match, pdev->dev.of_node); - drv_data = match->data; +if (match) + drv_data = match->data;
Could be 1 line change:
drv_data = match ? match->data : NULL;
Quoted 22 lines
drivers/mmc/host/dw_mmc-k3.c +0
-0return dw_mci_pltfm_register (pdev, drv_data); }drivers/mmc/host/dw_mmc-pltfm.c +2
-1@@ -78,7 +78,8 @@ static int dw_mci_pltfm_probe(struct platform_device *pdev)if (pdev->dev.of_node) { match =of_match_node (dw_mci_pltfm_match, pdev->dev.of_node); - drv_data = match->data; +if (match) + drv_data = match->data; }return dw_mci_pltfm_register (pdev, drv_data);drivers/mmc/host/sdhci-of-arasan.c +0
-0
drivers/mmc/host/sdhci-of-arasan.c static int sdhci_arasan_probe(struct platform_device *pdev) · line 1523
Quoted 4 lines
drivers/mmc/host/sdhci-of-arasan.c +1
-0@@ -1520,6 +1520,8 @@ static int sdhci_arasan_probe(struct platform_device *pdev)const struct sdhci_arasan_of_data *data; match =of_match_node (sdhci_arasan_of_match, pdev->dev.of_node); +if (match ==NULL )
(!match) seems to be preferred over (match == NULL)
drivers/mmc/host/sdhci-of-arasan.c static int sdhci_arasan_probe(struct platform_device *pdev) · line 1524
Quoted 1 line
drivers/mmc/host/sdhci-of-arasan.c +1
-0+return -ENOPARAM ;
ENOPARAM is unconventional here. ENODEV or EINVAL are better
Quoted 4 lines
drivers/mmc/host/sdhci-of-arasan.c +0
-0data = match->data; host =sdhci_pltfm_init (pdev, data->pdata,sizeof (*sdhci_arasan));
Hi,
Quoted 7 lines · On 23.06.2020 06:06, [email protected] wrote:
From: Haibo Chen <[email protected]>
of_match_node()has the opportunity to return NULL, so need to dereference null return value.
This is reported by Coverity.Signed-off-by Haibo Chen <[email protected]>
There is no point in such check for a NULL. The driver won't be instantiated/probed if there is no matching node found first by the upper level framework. If you really want to make this code cleaner, please change it to use of_device_get_match_data().
Quoted 8 lines
--- drivers/mmc/host/dw_mmc-exynos.c | 5 +++-- drivers/mmc/host/dw_mmc-k3.c | 5 +++-- drivers/mmc/host/dw_mmc-pltfm.c | 3 ++- drivers/mmc/host/sdhci-of-arasan.c | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-)...
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland