Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3405376imm; Mon, 13 Aug 2018 11:05:25 -0700 (PDT) X-Google-Smtp-Source: AA+uWPybexB/okW51Jsae7qvLNREUqUx2Dop735nhi2JUXMu9hFjFSIRWjFXi7qN6Ib798iFU0VB X-Received: by 2002:a62:21cc:: with SMTP id o73-v6mr20128126pfj.21.1534183525103; Mon, 13 Aug 2018 11:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534183525; cv=none; d=google.com; s=arc-20160816; b=wkC9w+JNzLHV6LOpU5zojDLUkt3T/Ga4CSWYNdq6hk16cVD4E/9amHFp8StR5NLFNE U2I5XStWoMv4FzvAcGgd124/RvJFTfGCaeWH0wMXWXr4a4V9IETr0GzzXpNL5ivfuYEw BF2Y4Q1ZVPc+FDKGR2gEz7YzO6sK+BpuBmV+laHEkbqBTwdM/wlPeMrX3XMyuCbZLks5 d+xtxYZZYj5gbCWintLiFWWK4oa2GpB7iPWl1C2yI3jWsN093VF/a+LCLTrxVhxiyx9V 0EDf06eJdABVqIMijlk9aOKh7eM+pw4oXhEcThYohknldfe7Y1mzrSoSCsgALqdWc0Kg SDHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=39UePiHbFAVZbtidvD6EHE0giUzBprqe5hJufJEqkqs=; b=oAXBZ5b34P+d7Nxe3VMIukDzu7TqCZ450hSkVs0z/r1tgc8qPCgU716ajSYMfvKh+4 Lthj3sT5OabjyQd6UOmh9hq5HgiU1GDb+1xfx6Ut3Fwt0yRuJfkppTOVWAbdtlhAgY2N O4M5u5phsJGwgYkSuF833J4y49WVOanIneX/u1HgvdTPTYPr3oGIoenkNMeN8F2UnKX+ 6iUEVNraiQW5x7bWrix2PBjJoKhBSM+ABcfFdAyUtU8szLBI+/8Tij5cBpeJ/N6kQDa4 4QxbUWaARn3/kGfC37m6NDjTduJabYZMxweMWAzP1VwDHR1wJ6/JLi61CQ138+cP+Koi EYHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@compulab.co.il header.s=default header.b=itbMgepe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p64-v6si18228512pga.25.2018.08.13.11.05.09; Mon, 13 Aug 2018 11:05:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@compulab.co.il header.s=default header.b=itbMgepe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729891AbeHMUOn (ORCPT + 99 others); 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.11.0