Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 fd546ee6a7dc ("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: fd546ee6a7dc ("mmc: pxamci: fix card detect with slot-gpio API")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Robert Jarzmik and committed by
Ulf Hansson
b3802db5 f68381a7

+9 -7
+9 -7
drivers/mmc/host/pxamci.c
··· 789 789 gpio_direction_output(gpio_power, 790 790 host->pdata->gpio_power_invert); 791 791 } 792 - if (gpio_is_valid(gpio_ro)) 792 + if (gpio_is_valid(gpio_ro)) { 793 793 ret = mmc_gpio_request_ro(mmc, gpio_ro); 794 - if (ret) { 795 - dev_err(&pdev->dev, "Failed requesting gpio_ro %d\n", gpio_ro); 796 - goto out; 797 - } else { 798 - mmc->caps2 |= host->pdata->gpio_card_ro_invert ? 799 - 0 : MMC_CAP2_RO_ACTIVE_HIGH; 794 + if (ret) { 795 + dev_err(&pdev->dev, "Failed requesting gpio_ro %d\n", 796 + gpio_ro); 797 + goto out; 798 + } else { 799 + mmc->caps2 |= host->pdata->gpio_card_ro_invert ? 800 + 0 : MMC_CAP2_RO_ACTIVE_HIGH; 801 + } 800 802 } 801 803 802 804 if (gpio_is_valid(gpio_cd))