linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: fix bogus SPI bus number
@ 2017-10-17 10:44 Arnd Bergmann
       [not found] ` <20171017104519.878892-1-arnd-r2nGTMty4D4@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2017-10-17 10:44 UTC (permalink / raw)
  To: Mark Brown
  Cc: Lucas Stach, Naresh Kamboju, Arnd Bergmann, Geert Uytterhoeven,
	Andy Shevchenko, Rafael J. Wysocki,
	linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

lkft found a boot time regression on the Hikey board that has no
aliases entry for spi buses. of_alias_get_highest_id() here
returns -ENODEV, which is then used as the initial number for the
IDR allocation, and that in turn triggers a WARN_ON:

WARNING: CPU: 3 PID: 53 at include/linux/idr.h:113 spi_register_controller+0x890/0x940

This reworks the algorithm to turn any negative number into zero
again, restoring the original behavior for the Hikey case.

Fixes: 9ce70d49fa80 ("spi: fix IDR collision on systems with both fixed and dynamic SPI bus numbers")
Reported-by: Naresh Kamboju <naresh.kamboju-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Link: https://lkft.validation.linaro.org/scheduler/job/48009#L3147
Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
---
Not tested yet, please review carefully
---
 drivers/spi/spi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 0483410e7cb3..4b6985ec962c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2116,9 +2116,11 @@ int spi_register_controller(struct spi_controller *ctlr)
 	}
 	if (ctlr->bus_num < 0) {
 		mutex_lock(&board_lock);
+		id = of_alias_get_highest_id("spi");
+		if (id < 0)
+			id = -1;
 		id = idr_alloc(&spi_master_idr, ctlr,
-			       of_alias_get_highest_id("spi") + 1,
-			       0, GFP_KERNEL);
+			       id + 1, 0, GFP_KERNEL);
 		mutex_unlock(&board_lock);
 		if (WARN(id < 0, "couldn't get idr"))
 			return id;
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: fix bogus SPI bus number
       [not found] ` <20171017104519.878892-1-arnd-r2nGTMty4D4@public.gmane.org>
@ 2017-10-17 12:20   ` Lucas Stach
  2017-10-17 12:25   ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Lucas Stach @ 2017-10-17 12:20 UTC (permalink / raw)
  To: Arnd Bergmann, Mark Brown
  Cc: Naresh Kamboju, Geert Uytterhoeven, Andy Shevchenko,
	Rafael J. Wysocki, linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Am Dienstag, den 17.10.2017, 12:44 +0200 schrieb Arnd Bergmann:
> lkft found a boot time regression on the Hikey board that has no
> aliases entry for spi buses. of_alias_get_highest_id() here
> returns -ENODEV, which is then used as the initial number for the
> IDR allocation, and that in turn triggers a WARN_ON:
> 
> WARNING: CPU: 3 PID: 53 at include/linux/idr.h:113
> spi_register_controller+0x890/0x940
> 
> This reworks the algorithm to turn any negative number into zero
> again, restoring the original behavior for the Hikey case.
> 
> Fixes: 9ce70d49fa80 ("spi: fix IDR collision on systems with both
> fixed and dynamic SPI bus numbers")
> Reported-by: Naresh Kamboju <naresh.kamboju-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Link: https://lkft.validation.linaro.org/scheduler/job/48009#L3147
> Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
> ---
> Not tested yet, please review carefully

I've already sent a v2 of the borked patch, which Mark apparently
applied to his fix/idr branch.

Regards,
Lucas

> ---
>  drivers/spi/spi.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 0483410e7cb3..4b6985ec962c 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -2116,9 +2116,11 @@ int spi_register_controller(struct
> spi_controller *ctlr)
>  	}
>  	if (ctlr->bus_num < 0) {
>  		mutex_lock(&board_lock);
> +		id = of_alias_get_highest_id("spi");
> +		if (id < 0)
> +			id = -1;
>  		id = idr_alloc(&spi_master_idr, ctlr,
> -			       of_alias_get_highest_id("spi") + 1,
> -			       0, GFP_KERNEL);
> +			       id + 1, 0, GFP_KERNEL);
>  		mutex_unlock(&board_lock);
>  		if (WARN(id < 0, "couldn't get idr"))
>  			return id;
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: fix bogus SPI bus number
       [not found] ` <20171017104519.878892-1-arnd-r2nGTMty4D4@public.gmane.org>
  2017-10-17 12:20   ` Lucas Stach
@ 2017-10-17 12:25   ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2017-10-17 12:25 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Lucas Stach, Naresh Kamboju, Geert Uytterhoeven, Andy Shevchenko,
	Rafael J. Wysocki, linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 382 bytes --]

On Tue, Oct 17, 2017 at 12:44:50PM +0200, Arnd Bergmann wrote:
> lkft found a boot time regression on the Hikey board that has no
> aliases entry for spi buses. of_alias_get_highest_id() here
> returns -ENODEV, which is then used as the initial number for the
> IDR allocation, and that in turn triggers a WARN_ON:

This doesn't apply against current code, please check and resend.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-17 12:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-17 10:44 [PATCH] spi: fix bogus SPI bus number Arnd Bergmann
     [not found] ` <20171017104519.878892-1-arnd-r2nGTMty4D4@public.gmane.org>
2017-10-17 12:20   ` Lucas Stach
2017-10-17 12:25   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).