diff mbox

[v3,1/1] mmc: omap_hsmmc: devm_pinctrl_get returns ERR_PTR upon error

Message ID 1461099853-15011-2-git-send-email-afenkart@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andreas Fenkart April 19, 2016, 9:04 p.m. UTC
Only the dummy implementation of devm_pinctrl_get returns NULL.
The real implementation returns ERR_PTR. By enforcing pinselect
in Kconfig we can simplify the test to check only for ERR_PTR.
detected/triggered by static code checker.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andreas Fenkart <afenkart@gmail.com>
---
 drivers/mmc/host/Kconfig      | 1 +
 drivers/mmc/host/omap_hsmmc.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

kernel test robot April 19, 2016, 10:03 p.m. UTC | #1
Hi,

[auto build test WARNING on ulf.hansson-mmc/next]
[also build test WARNING on v4.6-rc4 next-20160419]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Andreas-Fenkart/mmc-omap_hsmmc-devm_pinctrl_get-returns-ERR_PTR-upon-error/20160420-050634
base:   https://git.linaro.org/people/ulf.hansson/mmc next
config: mips-allmodconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=mips 

All warnings (new ones prefixed by >>):

warning: (BCM47XX && ARCH_REQUIRE_GPIOLIB && PINCTRL_AT91 && PINCTRL_AT91PIO4 && PINCTRL_MESON && PINCTRL_CHERRYVIEW && PINCTRL_INTEL && PINCTRL_TB10X && PINCTRL_SH_PFC_GPIO && PINCTRL_STM32 && PINCTRL_MTK && MFD_TC6393XB) selects GPIOLIB which has unmet direct dependencies (ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB)

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Arnd Bergmann April 19, 2016, 10:12 p.m. UTC | #2
On Tuesday 19 April 2016 23:04:13 Andreas Fenkart wrote:
> Only the dummy implementation of devm_pinctrl_get returns NULL.
> The real implementation returns ERR_PTR. By enforcing pinselect
> in Kconfig we can simplify the test to check only for ERR_PTR.
> detected/triggered by static code checker.

This is not how the interface is meant to work:

The dummy devm_pinctrl_get() intentionally returns NULL because IS_ERR()
treats that as valid. All other pinctrl functions subsequently ignore
that NULL pointer, so the second half of the patch is ok without the
first half.

	Arnd

> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Andreas Fenkart <afenkart@gmail.com>
> ---
>  drivers/mmc/host/Kconfig      | 1 +
>  drivers/mmc/host/omap_hsmmc.c | 4 ++--
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
> index 1526b8a..b469755 100644
> --- a/drivers/mmc/host/Kconfig
> +++ b/drivers/mmc/host/Kconfig
> @@ -366,6 +366,7 @@ config MMC_OMAP
>  config MMC_OMAP_HS
>  	tristate "TI OMAP High Speed Multimedia Card Interface support"
>  	depends on HAS_DMA
> +	select PINCTRL
>  	depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || COMPILE_TEST
>  	help
>  	  This selects the TI OMAP High Speed Multimedia card Interface.
> diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
> index 62e421a..15ebc3b 100644
> --- a/drivers/mmc/host/omap_hsmmc.c
> +++ b/drivers/mmc/host/omap_hsmmc.c
> @@ -1842,8 +1842,8 @@ static int omap_hsmmc_configure_wake_irq(struct omap_hsmmc_host *host)
>  	 */
>  	if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) {
>  		struct pinctrl *p = devm_pinctrl_get(host->dev);
> -		if (!p) {
> -			ret = -ENODEV;
> +		if (IS_ERR(p)) {
> +			ret = PTR_ERR(p);
>  			goto err_free_irq;
>  		}
>  		if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_DEFAULT))) {
> 

--
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
kernel test robot April 19, 2016, 10:15 p.m. UTC | #3
Hi,

[auto build test WARNING on ulf.hansson-mmc/next]
[also build test WARNING on v4.6-rc4 next-20160419]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Andreas-Fenkart/mmc-omap_hsmmc-devm_pinctrl_get-returns-ERR_PTR-upon-error/20160420-050634
base:   https://git.linaro.org/people/ulf.hansson/mmc next
config: tile-allmodconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=tile 

All warnings (new ones prefixed by >>):

warning: (ARCH_REQUIRE_GPIOLIB && PINCTRL_AT91 && PINCTRL_AT91PIO4 && PINCTRL_MESON && PINCTRL_CHERRYVIEW && PINCTRL_INTEL && PINCTRL_TB10X && PINCTRL_SH_PFC_GPIO && PINCTRL_STM32 && PINCTRL_MTK && MFD_TC6393XB) selects GPIOLIB which has unmet direct dependencies (ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB)

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot April 19, 2016, 10:19 p.m. UTC | #4
Hi,

[auto build test WARNING on ulf.hansson-mmc/next]
[also build test WARNING on v4.6-rc4 next-20160419]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Andreas-Fenkart/mmc-omap_hsmmc-devm_pinctrl_get-returns-ERR_PTR-upon-error/20160420-050634
base:   https://git.linaro.org/people/ulf.hansson/mmc next
config: blackfin-allmodconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=blackfin 

All warnings (new ones prefixed by >>):

warning: (MMC_OMAP_HS) selects PINCTRL which has unmet direct dependencies (BF54x || BF60x)

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Dan Carpenter April 20, 2016, 8:11 a.m. UTC | #5
On Tue, Apr 19, 2016 at 03:12:27PM -0700, Arnd Bergmann wrote:
> On Tuesday 19 April 2016 23:04:13 Andreas Fenkart wrote:
> > Only the dummy implementation of devm_pinctrl_get returns NULL.
> > The real implementation returns ERR_PTR. By enforcing pinselect
> > in Kconfig we can simplify the test to check only for ERR_PTR.
> > detected/triggered by static code checker.
> 
> This is not how the interface is meant to work:
> 
> The dummy devm_pinctrl_get() intentionally returns NULL because IS_ERR()
> treats that as valid. All other pinctrl functions subsequently ignore
> that NULL pointer, so the second half of the patch is ok without the
> first half.
> 

We had that discussion.  The static checker warning triggered the
discussion but the real reason for this patch is that the
hardware will not work without PINCTRL.  So instead of compiling an
unusable kernel we added the select.

I forget, but I think one of ARCH_OMAP2PLUS or ARCH_KEYSTONE selects
PINCTRL already and the other doesn't.  That was part of the discussion
as well.

regards,
dan carpenter


--
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
Andreas Fenkart April 20, 2016, 11:38 a.m. UTC | #6
2016-04-20 10:11 GMT+02:00 Dan Carpenter <dan.carpenter@oracle.com>:
> On Tue, Apr 19, 2016 at 03:12:27PM -0700, Arnd Bergmann wrote:
>> On Tuesday 19 April 2016 23:04:13 Andreas Fenkart wrote:
>> > Only the dummy implementation of devm_pinctrl_get returns NULL.
>> > The real implementation returns ERR_PTR. By enforcing pinselect
>> > in Kconfig we can simplify the test to check only for ERR_PTR.
>> > detected/triggered by static code checker.
>>
>> This is not how the interface is meant to work:
>>
>> The dummy devm_pinctrl_get() intentionally returns NULL because IS_ERR()
>> treats that as valid. All other pinctrl functions subsequently ignore
>> that NULL pointer, so the second half of the patch is ok without the
>> first half.
>>
>
> We had that discussion.  The static checker warning triggered the
> discussion but the real reason for this patch is that the
> hardware will not work without PINCTRL.  So instead of compiling an
> unusable kernel we added the select.

beaglebone needs the workaround, most chips don't. The code discussed,
only gives some feedback to users about an incorrect configuration.
I can drop that part or replace it with a dev_info line, pointing to
"Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt"

> I forget, but I think one of ARCH_OMAP2PLUS or ARCH_KEYSTONE selects
> PINCTRL already and the other doesn't.  That was part of the discussion
> as well.

ARCH_KEYSTONE doesn't have pinctrl, ARCH_OMAP2PLUS does

/Andi
--
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
Tony Lindgren April 20, 2016, 3:13 p.m. UTC | #7
* Andreas Fenkart <afenkart@gmail.com> [160420 04:39]:
> 2016-04-20 10:11 GMT+02:00 Dan Carpenter <dan.carpenter@oracle.com>:
> > On Tue, Apr 19, 2016 at 03:12:27PM -0700, Arnd Bergmann wrote:
> >> On Tuesday 19 April 2016 23:04:13 Andreas Fenkart wrote:
> >> > Only the dummy implementation of devm_pinctrl_get returns NULL.
> >> > The real implementation returns ERR_PTR. By enforcing pinselect
> >> > in Kconfig we can simplify the test to check only for ERR_PTR.
> >> > detected/triggered by static code checker.
> >>
> >> This is not how the interface is meant to work:
> >>
> >> The dummy devm_pinctrl_get() intentionally returns NULL because IS_ERR()
> >> treats that as valid. All other pinctrl functions subsequently ignore
> >> that NULL pointer, so the second half of the patch is ok without the
> >> first half.
> >>
> >
> > We had that discussion.  The static checker warning triggered the
> > discussion but the real reason for this patch is that the
> > hardware will not work without PINCTRL.  So instead of compiling an
> > unusable kernel we added the select.
> 
> beaglebone needs the workaround, most chips don't. The code discussed,
> only gives some feedback to users about an incorrect configuration.
> I can drop that part or replace it with a dev_info line, pointing to
> "Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt"

Yes pinctrl is optional for sure. And leaving pinctrl out does not
produce an unusable kernel for some boards that do all the pin muxing
in the bootloader. Like Andreas says, only some boards need dynamic
pin muxing for the wake-up events.

The dev_info change sounds like papering over the issue.. I'm fine
with that, but isn't the real problem devm_pinctrl_get prototype?

> > I forget, but I think one of ARCH_OMAP2PLUS or ARCH_KEYSTONE selects
> > PINCTRL already and the other doesn't.  That was part of the discussion
> > as well.
> 
> ARCH_KEYSTONE doesn't have pinctrl, ARCH_OMAP2PLUS does

Yes.

Regards,

Tony
--
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
Arnd Bergmann April 20, 2016, 10:28 p.m. UTC | #8
On Wednesday 20 April 2016 08:13:37 Tony Lindgren wrote:
> * Andreas Fenkart <afenkart@gmail.com> [160420 04:39]:
> > 2016-04-20 10:11 GMT+02:00 Dan Carpenter <dan.carpenter@oracle.com>:
> > > On Tue, Apr 19, 2016 at 03:12:27PM -0700, Arnd Bergmann wrote:
> > >> On Tuesday 19 April 2016 23:04:13 Andreas Fenkart wrote:
> > >> > Only the dummy implementation of devm_pinctrl_get returns NULL.
> > >> > The real implementation returns ERR_PTR. By enforcing pinselect
> > >> > in Kconfig we can simplify the test to check only for ERR_PTR.
> > >> > detected/triggered by static code checker.
> > >>
> > >> This is not how the interface is meant to work:
> > >>
> > >> The dummy devm_pinctrl_get() intentionally returns NULL because IS_ERR()
> > >> treats that as valid. All other pinctrl functions subsequently ignore
> > >> that NULL pointer, so the second half of the patch is ok without the
> > >> first half.
> > >>
> > >
> > > We had that discussion.  The static checker warning triggered the
> > > discussion but the real reason for this patch is that the
> > > hardware will not work without PINCTRL.  So instead of compiling an
> > > unusable kernel we added the select.

Ok, but if that is the case, that the changelog text above should be
rewritten to explain it (but as Tony explains it was probably a
misinterpretation).

> > beaglebone needs the workaround, most chips don't. The code discussed,
> > only gives some feedback to users about an incorrect configuration.
> > I can drop that part or replace it with a dev_info line, pointing to
> > "Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt"
> 
> Yes pinctrl is optional for sure. And leaving pinctrl out does not
> produce an unusable kernel for some boards that do all the pin muxing
> in the bootloader. Like Andreas says, only some boards need dynamic
> pin muxing for the wake-up events.
> 
> The dev_info change sounds like papering over the issue.. I'm fine
> with that, but isn't the real problem devm_pinctrl_get prototype?
> 
> 

I don't see anything wrong with the devm_pinctrl_get prototype other
than how it frequently confuses driver writers.

	Arnd
--
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
Dan Carpenter April 21, 2016, 4:32 a.m. UTC | #9
On Thu, Apr 21, 2016 at 12:28:05AM +0200, Arnd Bergmann wrote:
> I don't see anything wrong with the devm_pinctrl_get prototype other
> than how it frequently confuses driver writers.

Yeah.  It basically works.  There are a bunch of similar APIs where NULL
vs ERR_PTR is used the same way.

regards,
dan carpenter

--
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
diff mbox

Patch

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 1526b8a..b469755 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -366,6 +366,7 @@  config MMC_OMAP
 config MMC_OMAP_HS
 	tristate "TI OMAP High Speed Multimedia Card Interface support"
 	depends on HAS_DMA
+	select PINCTRL
 	depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || COMPILE_TEST
 	help
 	  This selects the TI OMAP High Speed Multimedia card Interface.
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 62e421a..15ebc3b 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -1842,8 +1842,8 @@  static int omap_hsmmc_configure_wake_irq(struct omap_hsmmc_host *host)
 	 */
 	if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) {
 		struct pinctrl *p = devm_pinctrl_get(host->dev);
-		if (!p) {
-			ret = -ENODEV;
+		if (IS_ERR(p)) {
+			ret = PTR_ERR(p);
 			goto err_free_irq;
 		}
 		if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_DEFAULT))) {