Commit b3802db5 authored by Robert Jarzmik's avatar Robert Jarzmik Committed by Ulf Hansson

mmc: pxamci: fix potential oops

As reported by Dan in his report in [1], there is a potential NULL
pointer derefence if these conditions are met :
 - there is no platform_data provided, ie. host->pdata = NULL

Fix this by only using the platform data ro_invert when a gpio for
read-only is provided by the platform data.

This doesn't appear yet as every pxa board provides a platform_data, and
calls pxa_set_mci_info() with a non NULL pointer.

[1] [bug report] mmc: pxamci: fix card detect with slot-gpio API.
The commit fd546ee6 ("mmc: pxamci: fix card detect with slot-gpio
API") from Sep 26, 2015, leads to the following static checker warning:

	drivers/mmc/host/pxamci.c:809 pxamci_probe()
	warn: variable dereferenced before check 'host->pdata' (see line 798)

Fixes: fd546ee6 ("mmc: pxamci: fix card detect with slot-gpio API")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent f68381a7
...@@ -789,14 +789,16 @@ static int pxamci_probe(struct platform_device *pdev) ...@@ -789,14 +789,16 @@ static int pxamci_probe(struct platform_device *pdev)
gpio_direction_output(gpio_power, gpio_direction_output(gpio_power,
host->pdata->gpio_power_invert); host->pdata->gpio_power_invert);
} }
if (gpio_is_valid(gpio_ro)) if (gpio_is_valid(gpio_ro)) {
ret = mmc_gpio_request_ro(mmc, gpio_ro); ret = mmc_gpio_request_ro(mmc, gpio_ro);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed requesting gpio_ro %d\n", gpio_ro); dev_err(&pdev->dev, "Failed requesting gpio_ro %d\n",
goto out; gpio_ro);
} else { goto out;
mmc->caps2 |= host->pdata->gpio_card_ro_invert ? } else {
0 : MMC_CAP2_RO_ACTIVE_HIGH; mmc->caps2 |= host->pdata->gpio_card_ro_invert ?
0 : MMC_CAP2_RO_ACTIVE_HIGH;
}
} }
if (gpio_is_valid(gpio_cd)) if (gpio_is_valid(gpio_cd))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment