From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761597AbdJQMUt (ORCPT ); Tue, 17 Oct 2017 08:20:49 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:47443 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933274AbdJQMUq (ORCPT ); Tue, 17 Oct 2017 08:20:46 -0400 Message-ID: <1508242834.2146.16.camel@pengutronix.de> Subject: Re: [PATCH] spi: fix bogus SPI bus number From: Lucas Stach To: Arnd Bergmann , Mark Brown Cc: Naresh Kamboju , Geert Uytterhoeven , Andy Shevchenko , "Rafael J. Wysocki" , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 17 Oct 2017 14:20:34 +0200 In-Reply-To: <20171017104519.878892-1-arnd@arndb.de> References: <20171017104519.878892-1-arnd@arndb.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:fa0f:41ff:fe58:4010 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Link: https://lkft.validation.linaro.org/scheduler/job/48009#L3147 > Signed-off-by: Arnd Bergmann > --- > 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;