diff mbox series

mmc: sdhci-pxav3: Fix potential NULL dereference in sdhci_pxav3_probe

Message ID 20240710070039.318658-1-make24@iscas.ac.cn
State New
Headers show
Series mmc: sdhci-pxav3: Fix potential NULL dereference in sdhci_pxav3_probe | expand

Commit Message

Ma Ke July 10, 2024, 7 a.m. UTC
In sdhci_pxav3_probe(), mv_mbus_dram_info() returns NULL if
CONFIG_PLAT_ORION macro is not defined. Fix this bug by adding NULL check.

Fixes: aa8165f91442 ("mmc: sdhci-pxav3: do the mbus window configuration after enabling clocks")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/mmc/host/sdhci-pxav3.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Adrian Hunter July 10, 2024, 9:26 a.m. UTC | #1
On 10/07/24 10:00, Ma Ke wrote:
> In sdhci_pxav3_probe(), mv_mbus_dram_info() returns NULL if
> CONFIG_PLAT_ORION macro is not defined. Fix this bug by adding NULL check.

Looks like mv_conf_mbus_windows() in sdhci-pxav3.c already checks
for NULL i.e.

static int mv_conf_mbus_windows(struct platform_device *pdev,
				const struct mbus_dram_target_info *dram)
{
	int i;
	void __iomem *regs;
	struct resource *res;

	if (!dram) {
		dev_err(&pdev->dev, "no mbus dram info\n");
		return -EINVAL;
	}


> 
> Fixes: aa8165f91442 ("mmc: sdhci-pxav3: do the mbus window configuration after enabling clocks")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>  drivers/mmc/host/sdhci-pxav3.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
> index 3af43ac05825..ac89cb2eb9f6 100644
> --- a/drivers/mmc/host/sdhci-pxav3.c
> +++ b/drivers/mmc/host/sdhci-pxav3.c
> @@ -375,6 +375,7 @@ static int sdhci_pxav3_probe(struct platform_device *pdev)
>  	struct sdhci_host *host = NULL;
>  	struct sdhci_pxa *pxa = NULL;
>  	const struct of_device_id *match;
> +	const struct mbus_dram_target_info *dram;
>  	int ret;
>  
>  	host = sdhci_pltfm_init(pdev, &sdhci_pxav3_pdata, sizeof(*pxa));
> @@ -406,7 +407,12 @@ static int sdhci_pxav3_probe(struct platform_device *pdev)
>  		ret = armada_38x_quirks(pdev, host);
>  		if (ret < 0)
>  			goto err_mbus_win;
> -		ret = mv_conf_mbus_windows(pdev, mv_mbus_dram_info());
> +		dram = mv_mbus_dram_info();
> +		if (!dram) {
> +			ret = 0;
> +			goto err_mbus_win;
> +		}
> +		ret = mv_conf_mbus_windows(pdev, dram);
>  		if (ret < 0)
>  			goto err_mbus_win;
>  	}
diff mbox series

Patch

diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index 3af43ac05825..ac89cb2eb9f6 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -375,6 +375,7 @@  static int sdhci_pxav3_probe(struct platform_device *pdev)
 	struct sdhci_host *host = NULL;
 	struct sdhci_pxa *pxa = NULL;
 	const struct of_device_id *match;
+	const struct mbus_dram_target_info *dram;
 	int ret;
 
 	host = sdhci_pltfm_init(pdev, &sdhci_pxav3_pdata, sizeof(*pxa));
@@ -406,7 +407,12 @@  static int sdhci_pxav3_probe(struct platform_device *pdev)
 		ret = armada_38x_quirks(pdev, host);
 		if (ret < 0)
 			goto err_mbus_win;
-		ret = mv_conf_mbus_windows(pdev, mv_mbus_dram_info());
+		dram = mv_mbus_dram_info();
+		if (!dram) {
+			ret = 0;
+			goto err_mbus_win;
+		}
+		ret = mv_conf_mbus_windows(pdev, dram);
 		if (ret < 0)
 			goto err_mbus_win;
 	}