Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1782310imm; Thu, 27 Sep 2018 02:23:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV60WYD+37Ao7KJnPifvCnVWHOMT774dDN3G24U+gTTK2teqUE4R33LMHTTC3rcsPz6fij42R X-Received: by 2002:a63:66c3:: with SMTP id a186-v6mr60771pgc.330.1538040192541; Thu, 27 Sep 2018 02:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538040192; cv=none; d=google.com; s=arc-20160816; b=e3WR9smDnRN0fjKKju4E3JbHVb02QvFeI6jOL/askK/2eubusyez5Z9i4uE3VQhQWp CmDXg3jGO9M6ellKBUTZZ4f7kQil/SsFmxVWwcPkDOGYOykMKWXA/k3/D/xQDwTS2OXO iReq+SiWSuihvYeMk6NvhU5gFMeN89Vmm/ndZh/TL8TOjgH9yObTCQe7q62UEhF5CTjx LNAVFRg/HgJNSCKY8IU6wQaRm2sG0xWpLjg7wiVgO1jWjcnjSOBrk6bQhWO7ZG3S/c1I uJGTrvtPIKUmZSdKZSDTPBZ/Qw1o6Ec7OC5MkD7khNvb2yo62vu7lqbjW8YDUcpUxGAY MKMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=wzO2z3CW4deVtUlRc/IJfhKLqvP6gNJEKdB2mfTks4s=; b=mc4PSjhpYIg/CXDfhwkSpd3kdd8v0Bi+H5o5LiYul+c2jyalpT/z66FuZy86zqWXp4 XOCQvGETZ9XWRXIebUdbXIWfb3U9omr+4+jM5EE7goC19OnLK+w/EP3JrpJJ98BVGCqx j5hbCHK6zJpwVRW+y9Jc4iAN2n+t9O+6rqVuz7x0Y/Ow4BE1O/KU4jrQLXbypuaMXZ6U rvtSfMnSuPMW+f7qgoSPe7ftQLYslZSnqooEpI4vKbalvldmRKgpY5ij3+sViNbUcGq8 PzDk+KOROoQXltNKYioRxHdCMe7pwDtPniSyBaGaSoi0XX92gZSmNJj6LKsDfszdrnE9 MHzw== ARC-Authentication-Results: i=1; mx.google.com; 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 m193-v6si1919979pfc.312.2018.09.27.02.22.57; Thu, 27 Sep 2018 02:23:12 -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; 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 S1728393AbeI0PkF (ORCPT + 99 others); Thu, 27 Sep 2018 11:40:05 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56524 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727026AbeI0PkF (ORCPT ); Thu, 27 Sep 2018 11:40:05 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1DDC51113; Thu, 27 Sep 2018 09:22:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kirill Kapranov , Mark Brown Subject: [PATCH 4.14 31/64] spi: fix IDR collision on systems with both fixed and dynamic SPI bus numbers Date: Thu, 27 Sep 2018 11:03:48 +0200 Message-Id: <20180927090254.569426729@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090249.801943776@linuxfoundation.org> References: <20180927090249.801943776@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kirill Kapranov commit 1a4327fbf4554d5b78d75b19a13d40d6de220159 upstream. 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 Signed-off-by: Mark Brown Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2135,6 +2135,15 @@ int spi_register_controller(struct spi_c 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);