From patchwork Tue Oct 17 10:44:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10011639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BF7160235 for ; Tue, 17 Oct 2017 10:45:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F2ED28847 for ; Tue, 17 Oct 2017 10:45:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63C5D28849; Tue, 17 Oct 2017 10:45:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAE1528847 for ; Tue, 17 Oct 2017 10:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756331AbdJQKpn (ORCPT ); Tue, 17 Oct 2017 06:45:43 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:65505 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752841AbdJQKpm (ORCPT ); Tue, 17 Oct 2017 06:45:42 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0M1CHs-1dFb4b1Ysq-00tCGo; Tue, 17 Oct 2017 12:45:21 +0200 From: Arnd Bergmann To: Mark Brown Cc: Lucas Stach , Naresh Kamboju , Arnd Bergmann , Geert Uytterhoeven , Andy Shevchenko , "Rafael J. Wysocki" , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] spi: fix bogus SPI bus number Date: Tue, 17 Oct 2017 12:44:50 +0200 Message-Id: <20171017104519.878892-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:2wt02w9Jll4St1alaGbwgUb2BBDFvSJoeyHjvu/3NkbOPNbrQO6 ea4v1hkeE3A8CFe1gna+AUl8hMdeCbJP5gN6RNkf/P+LC7sTWzuZsELERe++klW56DXCvA+ 0BihKlESajL85RlZcMVN8zncvKZqLgALVQESiRvq1qkf3UX2AI014pVubM676Cirf4aBZFy reixQIPk8FHEcxyq+a0fA== X-UI-Out-Filterresults: notjunk:1; V01:K0:wx0gpR2a9ns=:BOemI6birSINFpS3WBphJ6 M3g64fDEutzNHR66o58O9LHnMtgTXuX4sTi9t4IRIfa6yMhssSrME9oXT2ZALa1ld4P1k4o3c 0J8Y1iUW1ZK6E9rMYFTLqC2iZ6leVKb/ba7EYCQ4fwXC89gV6UUkgY/3Qc5GDNO1kiW5oS5pY XJIwJW9uPhyxMX9GalnHMQJpKfXYh0f+tAlMjR56sfDLcfa//T1JMJULmDmwkP4UHzhVwc2gz g3oZPfjQxyaj/fMeCILCDizJD13UT4xHH99adWRNi58IFte9bVq0KCXqU0wXCV1iv0+SL5Gzt xahxTWEsBHGxV+kEGon24cC0ljxPpZQyvvet+QDu1aMFJDqdiX/P6P6MKhDMz7ueWPvSEKtsE CqYXfOacayVCR+pz24JKkdROp4EJ9L4ZCYLETxKYHQanX53p/qbxoqKb7sD7uuNPtVhvnol6J godAxI7CUyqGRp3Hd1lzrA7uFkfCA+vLi5JKLJJcI3maNyfykXolapgYaW6HI5dFWTm6gwrLf fcuUscCO3DLbQL4xUSn5CaYgli0DwKqdP1PK4mmT/gNibqyM7DZZW2+yKbHXWNqcDm9/+c3ec eglabXyjbBjFuT8XAuEA0Qdm9UKSobzqvQdbL2CB0zJC4Vt98y3pFgWCZaVCOkPL8NLrmdCE1 w7vt/KeODlXJZNhFYgVozVZuTOdZxfr1SeqA6kqdtE+OcntSY2wZNBdeMEg2LzM4dRo+HDVll GeYLyVnO4DxaJ3KcIY11wYAB8wAbQ96NMsVk5Q== Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;