From patchwork Mon Aug 13 16:48:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill kapranov X-Patchwork-Id: 10564547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1DC814E2 for ; Mon, 13 Aug 2018 17:31:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD5C429705 for ; Mon, 13 Aug 2018 17:31:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A17022970A; Mon, 13 Aug 2018 17:31:35 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 1A78B29705 for ; Mon, 13 Aug 2018 17:31:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729461AbeHMUOn (ORCPT ); Mon, 13 Aug 2018 16:14:43 -0400 Received: from softlayer.compulab.co.il ([50.23.254.55]:51342 "EHLO compulab.co.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728533AbeHMUOn (ORCPT ); Mon, 13 Aug 2018 16:14:43 -0400 X-Greylist: delayed 2606 seconds by postgrey-1.27 at vger.kernel.org; Mon, 13 Aug 2018 16:14:42 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=compulab.co.il; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=39UePiHbFAVZbtidvD6EHE0giUzBprqe5hJufJEqkqs=; b=itbMgepeYQT4ont2ghwofGkgO5 RJhAmJ62LFu/ILAPINhgCG6Gksn9sSCQAuQPwXRBczn4XVcy63Ni8qvDQGa7gJ6MAUdfErWx/FAr6 cj3jSeVJ3fHAJYr1sZp2A738e/hUjuijoiYC2IsYWi+Bth5e1fUAzBoOClVJb8b8JQTvqS701QjXY lwSWMddB1XL/vX9RpWeYhHptYqyjS8ObyZpIT716taXp1zzoeHP583a7peG3SFuUbRmXX050Ycnop Wgf+daSEZLSNQu95VItnDblYpvLhH0mjXt7gwJFds7aWdmFXTL2WUPJIfcFVKGIcXt/7rRrYlWJZH 3QdOvxDg==; Received: from [37.142.126.90] (port=39234 helo=zimbra-mta.compulab.co.il) by softlayer.compulab.co.il with esmtp (Exim 4.87) (envelope-from ) id 1fpG0t-000299-Kc; Mon, 13 Aug 2018 19:48:15 +0300 Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id ADC7448280F; Mon, 13 Aug 2018 19:48:14 +0300 (IDT) Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id IksGcmip7Bhd; Mon, 13 Aug 2018 19:48:14 +0300 (IDT) Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 39E4D48280E; Mon, 13 Aug 2018 19:48:14 +0300 (IDT) X-Virus-Scanned: amavisd-new at zimbra-mta.compulab.co.il Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 6H0mJxOblER5; Mon, 13 Aug 2018 19:48:14 +0300 (IDT) Received: from kkk.compulab.local (lifshitz-linux.compulab.local [192.168.11.10]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 097FD482805; Mon, 13 Aug 2018 19:48:14 +0300 (IDT) From: Kirill Kapranov To: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, l.stach@pengutronix.de Cc: Kirill Kapranov Subject: [PATCH] spi:fix IDR collision on systems with both fixed and dynamic SPI bus numbers Date: Mon, 13 Aug 2018 19:48:10 +0300 Message-Id: <20180813164810.16769-1-kirill.kapranov@compulab.co.il> X-Mailer: git-send-email 2.11.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - softlayer.compulab.co.il X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - compulab.co.il X-Get-Message-Sender-Via: softlayer.compulab.co.il: acl_c_recent_authed_mail_ips_text_entry: kirill.kapranov@compulab.co.il|compulab.co.il X-Authenticated-Sender: softlayer.compulab.co.il: kirill.kapranov@compulab.co.il 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 On systems where some controllers get a dynamic ID assigned and some have a fixed number (e.g. from ACPI tables), the current implementation might run into an IDR collision: in case of a fixed bus number is gotten by a driver (but not marked busy in IDR tree) and a driver with dynamic bus number gets the same ID and predictably fails. Fix this by means of checking-in fixed IDsin IDR as far as dynamic ones at the moment of the controller registration. Fixes: 9b61e302210e (spi: Pick spi bus number from Linux idr or spi alias) Signed-off-by: Kirill Kapranov --- drivers/spi/spi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ec395a6baf9c..97e303185d5b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2170,6 +2170,15 @@ int spi_register_controller(struct spi_controller *ctlr) if (WARN(id < 0, "couldn't get idr")) return id; ctlr->bus_num = id; + } else { + /* devices with a fixed bus num must check-in with the num */ + mutex_lock(&board_lock); + id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num, + ctlr->bus_num + 1, GFP_KERNEL); + mutex_unlock(&board_lock); + if (WARN(id < 0, "couldn't get idr")) + return id == -ENOSPC ? -EBUSY : id; + ctlr->bus_num = id; } INIT_LIST_HEAD(&ctlr->queue); spin_lock_init(&ctlr->queue_lock);