Skip to contentSkip to conversation

mmc: pxamci: fix card detect with slot-gpio API

bug report Dan Carpenter 2 participants 2 messages Jul 13, 2016 – Jul 14, 2016 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

Hello Robert Jarzmik,

The patch 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)

drivers/mmc/host/pxamci.c
775

   776          if (host->pdata) {
                    ^^^^^^^^^^^

We check it here.

   777                  gpio_cd = host->pdata->gpio_card_detect;
   778                  gpio_ro = host->pdata->gpio_card_ro;
   779                  gpio_power = host->pdata->gpio_power;

780 }
781 if (gpio_is_valid(gpio_power)) {
782 ret = devm_gpio_request(&pdev->dev, gpio_power,
783 "mmc card power");
784 if (ret) {
785 dev_err(&pdev->dev, "Failed requesting gpio_power %d\n",
786 gpio_power);
787 goto out;
788 }
789 gpio_direction_output(gpio_power,
790 host->pdata->gpio_power_invert);
791 }
792 if (gpio_is_valid(gpio_ro))

If gpio_is_valid is valid that implies "host->pdata" is non-NULL.

793 ret = mmc_gpio_request_ro(mmc, gpio_ro);

   794          if (ret) {
                    ^^^

If host->pdata is NULL that implies ret is zero. If it's non-NULL then ret could be zero or negative.

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 ?

                                      ^^^^^^^^^^^^^

Potential oops.

799 0 : MMC_CAP2_RO_ACTIVE_HIGH;
800 }
801
802 if (gpio_is_valid(gpio_cd))
803 ret = mmc_gpio_request_cd(mmc, gpio_cd, 0);
804 if (ret) {
805 dev_err(&pdev->dev, "Failed requesting gpio_cd %d\n", gpio_cd);
806 goto out;
807 }
808
809 if (host->pdata && host->pdata->init)

                    ^^^^^^^^^^^

There are no possible path where we can reach this check with host->pdata is NULL and we haven't oopsed.

   810                  host->pdata->init(&pdev->dev, pxamci_detect_irq, mmc);
   811  

regards,
dan carpenter

#1 lore raw
Quoted 4 lines · Dan Carpenter

Hello Robert Jarzmik,

The patch fd546ee6a7dc: "mmc: pxamci: fix card detect with slot-gpio API" from Sep 26, 2015, leads to the following static checker warning:

Hi Dan,

I'm taking that fix, thanks for the report.

By the way, if your mails are "auto-generated", could you amend the generator to use the format "commit <12+ chars of sha1> ("<title line>")" instead of "patch xxx", so that we(I) can quote you directly in the commit message ?

Cheers.

--
Robert