Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7478067imm; Tue, 28 Aug 2018 12:48:31 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYWL8qFOI/YiZdY5HvhwAsM299DeorK5tOsLuBdY1v7nioMuBTjnjXj4ozMFv0IqcXMsmCV X-Received: by 2002:a63:3105:: with SMTP id x5-v6mr2847766pgx.323.1535485711460; Tue, 28 Aug 2018 12:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535485711; cv=none; d=google.com; s=arc-20160816; b=UF1rBaFLsMKOmjP/uh0/+QCW9Bv9JXQ+ie1/Dy2LC72SVM5iM5AEZ8wWQI3HQxhkOR RiBnmKv1xoJPUO0YGBiBi6DFmcYQFmbdLwDJO76UCuldbc4+EcRSdHWG3pfoUC0AbFCA 3LrweGTSqEu4s35oW17Y50oqM8DfX1vucT9s+l2MNczSvgBSE6mfXyrmcHNfBRBDL5Gm Eba+kDfwm90lUwVeGRd4Sfg7EaP+FIjHiE83Uuuz3sIH0JhuYVTb60PYih1LF4tDdWae YHQDpky5V1LMyX2fDv7WDZRMbt6kFQNCLLQiEOeRbgydZDeKmo2ex/MFnEljTYpLFzeU wCmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature :arc-authentication-results; bh=lwb87Jhqu1uE9HzpIkOY4FkFJVP/FN8HaEYUGV8lel8=; b=qCubg0O9xitgVKc/si/aiJ0nOjLAMgOoKmNsj9avoaWSWu3E/0jAoSFe+RvnWkIJvP WHaIVxnpo2dssEr3+mv5gGNR1EPn8FYOwA3ywUwtGLcaWOoCy2dAf8FVLRmWqD4ouWNT vJ1GaXSJk9jbXmQIcu1IcPlYEpASVZ1Q/GP4h0SVUdDxseLE8S1B74lRPeFZ+XkH8Tq7 GCvv/k5tS16FNKnd4q1RzMZWndQBLIQFZoAJ9x91bU1eGvjYlEfR9y5ZjzVY+gVCFcvP mUrQK1o5W9KReVsK3zttTRhIZLFjDfNYTGJp2W94nYdNHCJSr/02KNWxQbL26xaRF2jS vJRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@compulab.co.il header.s=default header.b="ERZUCpc/"; 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 7-v6si1764774pgw.207.2018.08.28.12.48.15; Tue, 28 Aug 2018 12:48:31 -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="ERZUCpc/"; 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 S1727135AbeH1XkT (ORCPT + 99 others); Tue, 28 Aug 2018 19:40:19 -0400 Received: from softlayer.compulab.co.il ([50.23.254.55]:42618 "EHLO compulab.co.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726807AbeH1XkS (ORCPT ); Tue, 28 Aug 2018 19:40:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=compulab.co.il; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:References:In-Reply-To:Message-ID:Cc:To:From:Date:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=lwb87Jhqu1uE9HzpIkOY4FkFJVP/FN8HaEYUGV8lel8=; b=ERZUCpc/HYHqs2cHsm6DtCgKYl dxDKfVy13I4IfBAhm7W8RBjqmQ62X+1kG/mxwwJazNpR3DPOymmjjKqF93F7R8jwkDY4EdhfVxSGV hnYIIkG35pBM7zF929r0AnEEpXQidDsATbdQRhhjjLfhz113mKy/yyWFeLLjeVBWwV/XsjkYZsxCx 13Q1SQOr5NBIMkRYxnjWJ45vzPUCAKpLMFM4YPAtXn0wMMOzs53vb/dlrREl2DoqdJFlyXtgsdp8d GrZ2Y49Vfw63ikOLslKdYQ96p3Dekt2intnP3pC95XT5McQjcnUGmBFWtZJibTSAGJdN2iwJbO1Lg pZoUjilw==; Received: from [37.142.126.90] (port=34931 helo=zimbra-mta.compulab.co.il) by softlayer.compulab.co.il with esmtp (Exim 4.87) (envelope-from ) id 1fujxD-0005dh-QD; Tue, 28 Aug 2018 22:47:08 +0300 Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 943C6482AF6; Tue, 28 Aug 2018 22:47:06 +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 8Wjb7u8twOET; Tue, 28 Aug 2018 22:47:06 +0300 (IDT) Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 36513482AFF; Tue, 28 Aug 2018 22:47:06 +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 YynNUlXvutUZ; Tue, 28 Aug 2018 22:47:06 +0300 (IDT) Received: from zimbra01.compulab.co.il (zimbra01.compulab.co.il [192.168.10.66]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id EED20482AF6; Tue, 28 Aug 2018 22:47:05 +0300 (IDT) Date: Tue, 28 Aug 2018 22:47:05 +0300 (IDT) From: Kirill kapranov To: Mark Brown Cc: Geert Uytterhoeven , linux-spi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, festevam@gmail.com, linux@roeck-us.net Message-ID: <2024176715.614.1535485625914.JavaMail.root@compulab.co.il> In-Reply-To: <20180826132415.GB2414@sirena.org.uk> References: <20180821095303.27664-1-geert+renesas@glider.be> <35fbd3ae-3ac3-f6ef-874b-3d99c4d4d29a@compulab.co.il> <20180823102121.GC5207@sirena.org.uk> <20180826132415.GB2414@sirena.org.uk> Subject: Re: [PATCH -next] spi: Fix double IDR allocation with DT aliases MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.11.10] X-Mailer: Zimbra 8.0.1_GA_5438 (ZimbraWebClient - FF52 (Linux)/8.0.1_GA_5438) Thread-Topic: Fix double IDR allocation with DT aliases Thread-Index: sLpuLnC6fKJGIEy7uj/+imKItdx31g== 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 > Right, that clearly wasn't an intended effect, though - should be using > the max of the big constant and the maximum static ID. Due to difficulties of enumeration of all device in a system, I propose to assign safe sub-range for dynamic IDs in the upper-half of ID range the following way. NOTE-0: This patch has to be applied after Geert's patch, which fixes double call of idr_alloc. (above in the thread). Many thanks, Geert! NOTE-1: The best solution, IMHO, would be migration to property_get_* functions, declared in linux/property.h [PATCH] Eliminate possibility of conflict between static and dynamic IDs For systems without DT support allocate dynamical bus ID in a safe sub-range (if given), otherwise in upper half of the range so as to avoid possible conflict between statically and dynamically allocated IDs. Signed-off-by: Kirill Kapranov --- drivers/spi/Kconfig | 8 ++++++++ drivers/spi/spi.c | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 671d078349cc..7498fae0113b 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -47,6 +47,14 @@ config SPI_MASTER if SPI_MASTER +config SPI_MASTER_DYN_BUS_NUM_FIRST + int "First dynamically assigned SPI bus ID" if EXPERT + default 0 + help + This value can be used as the beginning of sub-range for dynamic + allocation of SPI bus ID in case of absence of DT. If -1 chosen, the + sub-range will be allocated in upper half of the SPI bus ID range. + config SPI_MEM bool "SPI memory extension" help diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9da0bc5a036c..3ac0cf0ab49c 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -49,6 +49,18 @@ #include "internals.h" +#ifndef CHAR_BIT +#define CHAR_BIT 8 /* Normally in */ +#endif +#if !defined(CONFIG_SPI_MASTER_DYN_BUS_NUM_FIRST) || \ + CONFIG_SPI_MASTER_DYN_BUS_NUM_FIRST < 0 +//Half of the biggest signed int of this size +#define SPI_DYN_FIRST_NUM (((1 << \ + (sizeof(((struct spi_controller*)0)->bus_num) * CHAR_BIT - 1)) - 1) / 2) +#else +#define SPI_DYN_FIRST_NUM CONFIG_SPI_MASTER_DYN_BUS_NUM_FIRST +#endif + static DEFINE_IDR(spi_master_idr); static void spidev_release(struct device *dev) @@ -2167,7 +2179,15 @@ int spi_register_controller(struct spi_controller *ctlr) } if (ctlr->bus_num < 0) { first_dynamic = of_alias_get_highest_id("spi"); - if (first_dynamic < 0) + + if (first_dynamic == -ENOSYS) + /* + * In case of system without DT support, allocate + * dynamic bus ID in safe range, higher than the bound, + * to avoid conflict between static and dynamic ID + */ + first_dynamic = SPI_DYN_FIRST_NUM; + else if (first_dynamic < 0) first_dynamic = 0; else first_dynamic++; -- 2.11.0