diff mbox

[v2,1/1] mmc: sdhci-spear: Fix NULL pointer dereference

Message ID 1378976643-26717-1-git-send-email-sachin.kamat@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Sachin Kamat Sept. 12, 2013, 9:04 a.m. UTC
pdata could be NULL if cd_gpio = -1. Dereference pdata only
if it is not NULL.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
---
Compile tested.
Changes since v1:
* Moved the pdata assignment inside if condition.
---
 drivers/mmc/host/sdhci-spear.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Viresh Kumar Sept. 12, 2013, 9:24 a.m. UTC | #1
On 12 September 2013 14:34, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> pdata could be NULL if cd_gpio = -1. Dereference pdata only
> if it is not NULL.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Compile tested.
> Changes since v1:
> * Moved the pdata assignment inside if condition.
> ---
>  drivers/mmc/host/sdhci-spear.c |    8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
> index 2dba9f8..76ddd89 100644
> --- a/drivers/mmc/host/sdhci-spear.c
> +++ b/drivers/mmc/host/sdhci-spear.c
> @@ -84,14 +84,12 @@ static struct sdhci_plat_data *sdhci_probe_config_dt(struct platform_device *pde
>         /* If pdata is required */
>         if (cd_gpio != -1) {
>                 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
> -               if (!pdata) {
> +               if (!pdata)
>                         dev_err(&pdev->dev, "DT: kzalloc failed\n");
> -                       return ERR_PTR(-ENOMEM);
> -               }
> +               else
> +                       pdata->card_int_gpio = cd_gpio;
>         }
>
> -       pdata->card_int_gpio = cd_gpio;
> -
>         return pdata;
>  }
>  #else

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sachin Kamat Sept. 27, 2013, 9:41 a.m. UTC | #2
On 12 September 2013 14:54, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 12 September 2013 14:34, Sachin Kamat <sachin.kamat@linaro.org> wrote:
>> pdata could be NULL if cd_gpio = -1. Dereference pdata only
>> if it is not NULL.
>>
>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> Cc: Viresh Kumar <viresh.kumar@linaro.org>
>> ---
>> Compile tested.
>> Changes since v1:
>> * Moved the pdata assignment inside if condition.
>> ---
>>  drivers/mmc/host/sdhci-spear.c |    8 +++-----
>>  1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
>> index 2dba9f8..76ddd89 100644
>> --- a/drivers/mmc/host/sdhci-spear.c
>> +++ b/drivers/mmc/host/sdhci-spear.c
>> @@ -84,14 +84,12 @@ static struct sdhci_plat_data *sdhci_probe_config_dt(struct platform_device *pde
>>         /* If pdata is required */
>>         if (cd_gpio != -1) {
>>                 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
>> -               if (!pdata) {
>> +               if (!pdata)
>>                         dev_err(&pdev->dev, "DT: kzalloc failed\n");
>> -                       return ERR_PTR(-ENOMEM);
>> -               }
>> +               else
>> +                       pdata->card_int_gpio = cd_gpio;
>>         }
>>
>> -       pdata->card_int_gpio = cd_gpio;
>> -
>>         return pdata;
>>  }
>>  #else
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>


Ping Chris.
Sachin Kamat Oct. 21, 2013, 3:10 a.m. UTC | #3
On 12 September 2013 14:34, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> pdata could be NULL if cd_gpio = -1. Dereference pdata only
> if it is not NULL.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Compile tested.
> Changes since v1:
> * Moved the pdata assignment inside if condition.
> ---
>  drivers/mmc/host/sdhci-spear.c |    8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
> index 2dba9f8..76ddd89 100644
> --- a/drivers/mmc/host/sdhci-spear.c
> +++ b/drivers/mmc/host/sdhci-spear.c
> @@ -84,14 +84,12 @@ static struct sdhci_plat_data *sdhci_probe_config_dt(struct platform_device *pde
>         /* If pdata is required */
>         if (cd_gpio != -1) {
>                 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
> -               if (!pdata) {
> +               if (!pdata)
>                         dev_err(&pdev->dev, "DT: kzalloc failed\n");
> -                       return ERR_PTR(-ENOMEM);
> -               }
> +               else
> +                       pdata->card_int_gpio = cd_gpio;
>         }
>
> -       pdata->card_int_gpio = cd_gpio;
> -
>         return pdata;
>  }
>  #else
> --
> 1.7.9.5
>

Gentle ping, Chris.
diff mbox

Patch

diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
index 2dba9f8..76ddd89 100644
--- a/drivers/mmc/host/sdhci-spear.c
+++ b/drivers/mmc/host/sdhci-spear.c
@@ -84,14 +84,12 @@  static struct sdhci_plat_data *sdhci_probe_config_dt(struct platform_device *pde
 	/* If pdata is required */
 	if (cd_gpio != -1) {
 		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
-		if (!pdata) {
+		if (!pdata)
 			dev_err(&pdev->dev, "DT: kzalloc failed\n");
-			return ERR_PTR(-ENOMEM);
-		}
+		else
+			pdata->card_int_gpio = cd_gpio;
 	}
 
-	pdata->card_int_gpio = cd_gpio;
-
 	return pdata;
 }
 #else