Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4897100imm; Tue, 21 Aug 2018 02:55:35 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwFiQ0MSQTcuBmnBLx1X2IQYfqsySp+25nm/eOB1u2FQCHDx+aBe/BCc/8joXE+ulJz4+On X-Received: by 2002:a63:1506:: with SMTP id v6-v6mr4412179pgl.150.1534845335410; Tue, 21 Aug 2018 02:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534845335; cv=none; d=google.com; s=arc-20160816; b=kq8CQDiuYtheIb2Gu7GxUafGNA8dpn6eJYn64RAV+hFDigRp/Y5JMJAoLyv42/R0V8 MuHf2IiwePfYT/9S4hm0YzoWCiu6IDvqWVH2LOb69Ys/4SktZlHk5aF+xlhFD+OYjlfV IS2bR7gxFs+fiax0UGXYQo0G7OaelO4D4zh0T/zPfUrlGa+dMGWtEH5LBQ8xchVVvQUi +Xpb5HIObz3YVb0NokxWC8kCvlNqkRO7z/8VLQbvIxWVTd8iTZXjY1SGVcGTWo5hnK88 lMbZVhxpKzTrobvquWJvjdEdAQuN2gA1dtcBYW8sNBP9/56pUqaY6YhxlqClkwe94JUc E6Rw== 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 :arc-authentication-results; bh=OpJCTqdOR5ZNK+jscvtWTH9zXq9XCQn9NKjyUwGgWeE=; b=MmTAy2NGFEHvsWKixwzDtDyxTlriCMjRpkcGCx5bVhiAuMYjrYPkShDfy4k+wvdPV3 qjJEJmIk07pVov589Pxhgy0D44q9nslYcsTQFvRrYeKMtc1nWVR+32WDi/3rWvFBzcSl 6ZBDIUYG88YYC/uXrW26/6H1x9P/tJu5rYJ55JKxdIyc5/XHffDnRD3TF58JCaU43uHc YNk8ICML8x8bJg0WMkN1z7e8BkDMvzSHzvAsgfJdbXSXaYpKFbRfp//URPzHkaqjIgyl Jok7m3+bQ2xHFIoi8FLdJZ7ZdHf1OQKpHzDyQ1qPIMdhy0MhIOxGbygBG0mSjSBI985a mKSg== 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 f13-v6si7828687pln.512.2018.08.21.02.55.20; Tue, 21 Aug 2018 02:55:35 -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 S1727091AbeHUNMf (ORCPT + 99 others); Tue, 21 Aug 2018 09:12:35 -0400 Received: from albert.telenet-ops.be ([195.130.137.90]:58780 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbeHUNMe (ORCPT ); Tue, 21 Aug 2018 09:12:34 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by albert.telenet-ops.be with bizsmtp id Rlt51y00J3XaVaC06lt5P6; Tue, 21 Aug 2018 11:53:05 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1fs3LV-0007Z3-2w; Tue, 21 Aug 2018 11:53:05 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1fs3LV-0007Cv-0W; Tue, 21 Aug 2018 11:53:05 +0200 From: Geert Uytterhoeven To: Mark Brown , Kirill Kapranov Cc: linux-spi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH -next] spi: Fix double IDR allocation with DT aliases Date: Tue, 21 Aug 2018 11:53:03 +0200 Message-Id: <20180821095303.27664-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the SPI bus number is provided by a DT alias, idr_alloc() is called twice, leading to: WARNING: CPU: 1 PID: 1 at drivers/spi/spi.c:2179 spi_register_controller+0x11c/0x5d8 couldn't get idr Fix this by moving the handling of fixed SPI bus numbers up, before the DT handling code fills in ctlr->bus_num. Fixes: 1a4327fbf4554d5b ("spi: fix IDR collision on systems with both fixed and dynamic SPI bus numbers") Signed-off-by: Geert Uytterhoeven --- Seen on e.g. r8a7791/koelsch, breaking both RSPI and MSIOF. --- drivers/spi/spi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index a00d006d4c3a1c5a..9da0bc5a036cfff6 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2143,8 +2143,17 @@ int spi_register_controller(struct spi_controller *ctlr) */ if (ctlr->num_chipselect == 0) return -EINVAL; - /* allocate dynamic bus number using Linux idr */ - if ((ctlr->bus_num < 0) && ctlr->dev.of_node) { + if (ctlr->bus_num >= 0) { + /* 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; + } else if (ctlr->dev.of_node) { + /* allocate dynamic bus number using Linux idr */ id = of_alias_get_id(ctlr->dev.of_node, "spi"); if (id >= 0) { ctlr->bus_num = id; @@ -2170,15 +2179,6 @@ 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.17.1