Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1773280imm; Thu, 27 Sep 2018 02:12:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV630SOcaSd/b8Amz6o/dKokgyCFWmPL1acCy6J7VNJoIkQiPYyXZ4FsD9R3f8L3N3XbmvPdc X-Received: by 2002:a62:a9d:: with SMTP id 29-v6mr9685331pfk.60.1538039578961; Thu, 27 Sep 2018 02:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039578; cv=none; d=google.com; s=arc-20160816; b=xCx60Lhfx1callOyggWAdX272BntmyTCB7v9gTsDmTLPGRDQzpTNDhQbMbS45qoVW/ rIIodqvS9jIUcMuy2QIo5E3xoKCvsc0LiIScLonzVG4LYTaSRVYD1vEq8RgULMP1STDf SPzCMUuJ8eHk/nwTheoi9bd9cYgOJ0TXJdojQtkqfe4NP4Xb63xyQYglL5EiGjg8wNQc cVk1lZutzWOM0ZrGIXAAWu974njZdL84nJBE5B7Ngs04tlRZO/BmSXrjFFtWpcEqjzhZ d2AIVdtWtOutGk191iB7/ECftlZU1Aku5NjRV/wdOki0qaksJOBkRI1KksLI7/JREn/u LOGA== 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=9HVsfUki6EicVPAlQSPTeNlqdJKuOa0gQyCpsyxwx9c=; b=Nq16G76wq4J6sVP8LaJMs3VVYTuw+/5MSezTOFT4WPjn9X529qaJ4vojpe90iPdYu/ TqnvrzhLsJLci3sC6ldBj7fbtsGTJzXjrdJEd6u+MoPot9NowfZimy25aUeYJ7jlE4v1 tAP4Plq0y4YMdvnim7dv+urQBGmLPjLPQxXtsDpp7zUt4JQwlcN54Hdw4wgc0IKJtnkM oWvOR4hiNQNHSnu3GlXF48lm+lNKBrKOXuQOt4oGuzNRnWKRDFerkGx+4D6QgR/HIFzA ETDXaSSRDi1iskCrLoArCF1a0sYtC7STB9qml+OisLUxkOJLMmXbGR7oFAfA4T1JYNwR gW5Q== 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 l185-v6si1532466pgl.270.2018.09.27.02.12.43; Thu, 27 Sep 2018 02:12:58 -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 S1728442AbeI0P1y (ORCPT + 99 others); Thu, 27 Sep 2018 11:27:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55166 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727294AbeI0P1x (ORCPT ); Thu, 27 Sep 2018 11:27:53 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 341D310A4; Thu, 27 Sep 2018 09:10:37 +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.18 46/88] spi: fix IDR collision on systems with both fixed and dynamic SPI bus numbers Date: Thu, 27 Sep 2018 11:03:27 +0200 Message-Id: <20180927090306.382094027@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090300.631426620@linuxfoundation.org> References: <20180927090300.631426620@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.18-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 @@ -2170,6 +2170,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);