Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp915889ybm; Wed, 27 May 2020 11:04:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSJ0OkkjedKvXviFZ8GW3bGPxeDuoIPOYz2Tsh13LbKmCturNBTS880k4aLZ0VN2Fzurj0 X-Received: by 2002:a05:6402:203a:: with SMTP id ay26mr24087273edb.205.1590602645033; Wed, 27 May 2020 11:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590602645; cv=none; d=google.com; s=arc-20160816; b=eA/jYXSTwqdONBxec1QbQfupzrbQnEiwg+7hOrznJugHQzOacCkFqDajY9YpkMpDcu cMi94ewXvdYzVWjlhe2NOkkwRxiHTHWvRjEfpUAS7E5g+wdkkLGK26OZU8Kgwno2y/QP +xtaxU35CesdgBVdNM2L+yyygp9WJVQYRWA6zzz6DXHUnU0kR45+QfO00784hDLNXTOb pGALLCpLvYEw1PS9Y60qvFYWgjAf2/XpkkLGTn70flHd+319dVHaUWIF68dJzPcywotc 7Lg8h5kfkQ+kcb1FtsN1fJyYfBL7/kuayz5Vi6LXZlx3cdOxa2+ESbEbVB2Q/k4ANX1P fJRw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dUY6B9XU019/rKSWuFY5yfCtOxQZ3yr+Eqm1VPGfl7Q=; b=fWSWr6RMHKecnlErDTs3pStX4ZWoxysOrqyQmd0Sc39x7I6eBGzeUZ5BBnoqsg8Vq5 Vv4VYMqU63CU1w9qX9lkZR8aBXJidJuj5q6E4cz8E/F+kX3QZN8dSs09edFm6e7dx4Yw 1/EwRClaWEz2w7GfyHDT1yWI9eAfhDsbJgdDg7bhjFizW7qSovCuzn1WCNxxFq3LePJX pgjO+CoPmOg7j/DXY8IjSPVBH5ScvG3xe+VTR5my4M32T511RWGY+DiQG2sRvLIjMbJZ rCsHMvW8bXt/dQN8HjCcDji0dQGBYGBuX3LZQKlaTz0QCDKGIl0lDA/v9mmN+4XKIh7i UmDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y1si2144835edo.418.2020.05.27.11.03.41; Wed, 27 May 2020 11:04:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388858AbgE0OQA (ORCPT + 99 others); Wed, 27 May 2020 10:16:00 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:36084 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387722AbgE0OP7 (ORCPT ); Wed, 27 May 2020 10:15:59 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id BFA048030835; Wed, 27 May 2020 14:15:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at baikalelectronics.ru Received: from mail.baikalelectronics.ru ([127.0.0.1]) by localhost (mail.baikalelectronics.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c7gPw8_tpttc; Wed, 27 May 2020 17:15:56 +0300 (MSK) From: Serge Semin To: CC: Serge Semin , Serge Semin , Alexey Malahov , Thomas Bogendoerfer , Wolfram Sang , Jarkko Nikula , Andy Shevchenko , Frank Rowand , Rob Herring , , , Subject: [PATCH v2] check: Add 10bit/slave i2c reg flags support Date: Wed, 27 May 2020 17:15:17 +0300 Message-ID: <20200527141517.22677-1-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20200527122525.6929-1-Sergey.Semin@baikalelectronics.ru> References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Recently the I2C-controllers slave interface support was added to the kernel I2C subsystem. In this case Linux can be used as, for example, a I2C EEPROM machine. See [1] for details. Other than instantiating the EEPROM-slave device from user-space there is a way to declare the device in dts. In this case firstly the I2C bus controller must support the slave interface. Secondly I2C-slave sub-node of that controller must have "reg"-property with flag I2C_OWN_SLAVE_ADDRESS set (flag is declared in [2]). That flag is declared as (1 << 30), which when set makes dtc unhappy about too big address set for a I2C-slave: Warning (i2c_bus_reg): /example-2/i2c@1120000/eeprom@64: I2C bus unit address format error, expected "40000064" Warning (i2c_bus_reg): /example-2/i2c@1120000/eeprom@64:reg: I2C address must be less than 10-bits, got "0x40000064" Similar problem would have happened if we had set the 10-bit address flag I2C_TEN_BIT_ADDRESS in the "reg"-property. In order to fix the problem we suggest to alter the I2C-bus reg-check algorithm, so one would be aware of the upper bits set. Normally if no flag specified, the 7-bit address is expected in the "reg"-property. If I2C_TEN_BIT_ADDRESS is set, then the 10-bit address check will be performed. The I2C_OWN_SLAVE_ADDRESS flag will be just ignored. [1] kernel/Documentation/i2c/slave-interface.rst [2] kernel/include/dt-bindings/i2c/i2c.h Signed-off-by: Serge Semin Cc: Alexey Malahov Cc: Thomas Bogendoerfer Cc: Wolfram Sang Cc: Jarkko Nikula Cc: Andy Shevchenko Cc: Frank Rowand Cc: Rob Herring Cc: devicetree-compiler@vger.kernel.org Cc: devicetree@vger.kernel.org Cc: linux-i2c@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- Changelog v2: - Use unsigned numeric literal in the left-shit operation to avoid UB. --- checks.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/checks.c b/checks.c index 4b3c486f1399..7091d1bc38d2 100644 --- a/checks.c +++ b/checks.c @@ -1028,6 +1028,7 @@ static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node const char *unitname = get_unitname(node); char unit_addr[17]; uint32_t reg = 0; + uint32_t addr; int len; cell_t *cells = NULL; @@ -1044,17 +1045,21 @@ static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node } reg = fdt32_to_cpu(*cells); - snprintf(unit_addr, sizeof(unit_addr), "%x", reg); + addr = reg & 0x3FFFFFFFU; + snprintf(unit_addr, sizeof(unit_addr), "%x", addr); if (!streq(unitname, unit_addr)) FAIL(c, dti, node, "I2C bus unit address format error, expected \"%s\"", unit_addr); for (len = prop->val.len; len > 0; len -= 4) { reg = fdt32_to_cpu(*(cells++)); - if (reg > 0x3ff) + addr = reg & 0x3FFFFFFFU; + if ((reg & (1U << 31)) && addr > 0x3ff) FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"", - reg); - + addr); + else if (!(reg & (1U << 31)) && addr > 0x7f) + FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\"", + addr); } } WARNING(i2c_bus_reg, check_i2c_bus_reg, NULL, ®_format, &i2c_bus_bridge); -- 2.26.2