Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1100448ybg; Tue, 2 Jun 2020 01:05:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwugJwEdWhBCADzwsWaT5lgNZN0oonmLCB2h6UnIpmKe4en7VtyGB+5c8DWyMN3gEpIDgbj X-Received: by 2002:a17:906:481b:: with SMTP id w27mr12785145ejq.27.1591085137103; Tue, 02 Jun 2020 01:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591085137; cv=none; d=google.com; s=arc-20160816; b=bx2XhbjiosvHglmT9lfJiJaXf89m6AszEFW/9MVbw8YM1e9z5wh7pbyismPlT3uA28 TCP6lbh46otMKz6E9ZeC0nundHJ5AqZ7BZwQg44Y+dDf3Fbr+3e+H8/QEBcnpduGH4PY cUbujbo5EYwSMmrkeYhEPJgVMHUTe9WbFYmCUqDgaAYd6SpnS1lNCEhEfQ86aTGm7kmQ kgtsist+o1INk53ErsEgn+/L3rkJdrEiOh7LyE0754ulempEuc4fNl5ypD83V7u7TtzR wEM5Rgne89ZUF4PziSX3a/4gmDhPbCmuftp+jXk9e/KIeAq9zpLxkOWw2cadaSFpg1rg MMvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=d+fBaE8SkVSyVqcmfq9Kr5IX8daUEd4ShpMIvLXzvdo=; b=1J9BzThyNmYz3aw5f8v0VVDQJrYQ+lESlF6khdE1Iyb8xB/VvO9CBT4KZ5vgq2U13o uptDcvc3G65V+bQPYSTrJxNrRngLTmfd0lr8UDso5akZnpOwYv6XeUxQRtCOWO0l4zQ8 PGKCY4CNtWOvJsEacvYJG6J4PJlZP8TED1TUWensxu4XDJNz10VEikzVnNVDg0DP5GwN DftCWIVAtM+0x7BA/Hql91yzXKIgDGE2oYl2UKIFf4q5U3hgLQzMEFQd46T5TQ1eGOB2 BLn6UaXc/4ryH7hUE6A4MJb87OpZBLLjbOAxBiULyB1i3Wuk3WRXifuQUUS2jLwS/5fJ NGnA== 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 a5si1092755edn.81.2020.06.02.01.05.14; Tue, 02 Jun 2020 01:05:37 -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 S1726160AbgFBIBN (ORCPT + 99 others); Tue, 2 Jun 2020 04:01:13 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:53954 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbgFBIBN (ORCPT ); Tue, 2 Jun 2020 04:01:13 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id D78A18030835; Tue, 2 Jun 2020 08:01:09 +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 cdmgq3OZHxmj; Tue, 2 Jun 2020 11:01:08 +0300 (MSK) Date: Tue, 2 Jun 2020 11:01:04 +0300 From: Serge Semin To: Joel Stanley CC: Serge Semin , Wolfram Sang , Andy Shevchenko , Rob Herring , , David Gibson , , Stephen Rothwell , Arnd Bergmann Subject: Re: [PATCH v3 2/2] checks: Improve i2c reg property checking Message-ID: <20200602080104.4vqobktck357j52v@mobilestation> References: <20200528085650.1417942-1-joel@jms.id.au> <20200528085650.1417942-3-joel@jms.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20200528085650.1417942-3-joel@jms.id.au> 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 On Thu, May 28, 2020 at 06:26:50PM +0930, Joel Stanley wrote: > The i2c bindings in the kernel tree describe support for 10 bit > addressing, which must be indicated with the I2C_TEN_BIT_ADDRESS flag. > When this is set the address can be up to 10 bits. When it is not set > the address is a maximum of 7 bits. > > See Documentation/devicetree/bindings/i2c/i2c.txt. > > Take into account this flag when checking the address is valid. > > Signed-off-by: Joel Stanley > --- > v2: Mask reg when checking the 10-bit size > --- > checks.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/checks.c b/checks.c > index feb1721f2603..3fe979a63290 100644 > --- a/checks.c > +++ b/checks.c > @@ -1023,6 +1023,7 @@ static void check_i2c_bus_bridge(struct check *c, struct dt_info *dti, struct no > WARNING(i2c_bus_bridge, check_i2c_bus_bridge, NULL, &addr_size_cells); > > #define I2C_OWN_SLAVE_ADDRESS (1 << 30) > +#define I2C_TEN_BIT_ADDRESS (1 << 31) As Andy neatly pointed out here: https://lore.kernel.org/lkml/20200527133656.GV1634618@smile.fi.intel.com/ (1 << 31) is UB. -Sergey > > static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node *node) > { > @@ -1057,10 +1058,13 @@ static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node > reg = fdt32_to_cpu(*(cells++)); > /* Ignore I2C_OWN_SLAVE_ADDRESS */ > reg &= ~I2C_OWN_SLAVE_ADDRESS; > - if (reg > 0x3ff) > + > + if ((reg & I2C_TEN_BIT_ADDRESS) && ((reg & ~I2C_TEN_BIT_ADDRESS) > 0x3ff)) > FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"", > reg); > - > + else if (reg > 0x7f) > + FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property", > + reg); > } > } > WARNING(i2c_bus_reg, check_i2c_bus_reg, NULL, ®_format, &i2c_bus_bridge); > -- > 2.26.2 >