Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp826693ybm; Wed, 27 May 2020 08:56:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQkdqCkO0NhYcDKL4uqQPXZ6uBnlGLZxt1uLqKSwFwgWi7IP61fs5zwJUIm9GRuqmyXdLY X-Received: by 2002:a50:d7c7:: with SMTP id m7mr25275025edj.101.1590594981072; Wed, 27 May 2020 08:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590594981; cv=none; d=google.com; s=arc-20160816; b=xIMomBO+pDgygsvR/6Ljy+lhJlhFwd5u8j4zwcKMU9dbPNP6VWh2RU2MjaQmUrAK+D c6bK6Ca1lz6lyBkW8ZZupI2Wpq/UscIrriblgae2UXDlIyw0ThdMH21blyfdv/P47Ms2 HGKXppf9UymIsMmOkKuUhPdKRx/hf0lu2PYT++hXwIFVyw+MuDVDx8HBRoz6ZzCxB2Op 6kWt9MbXVCP1B3azlkQZsELJZK/XG1dUFcRiW4JjwP8Cf3IG26SUeZKLVhOL1EBe6aVl SF7aKI8Zf+IEMmb2SJE1xEypExbNLGg+wT0f9oxceyFnWu16nzcjYk8Fb/UlPZCfqYBm 867A== 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=u0EC7nHMcwdwOhRwTNZOvkmbPzyiUvvuBlNSJbFN3E4=; b=Vhf228DQX77U8no4xr7FIFkC2lGf+5ygXpzXK7eiCHtZid/zc7LVWHSMjY725r3IPz fmn54m23LQYB+PL+6IZrBelyoV/GIMt1Jp/QxcBHLCBmWvd1A9/hTQqZ6l7K2/Xp5PVW PEOXfXCn+qfbJuSAqOEVttb3zTJyLXl/v68qh7Mtyo8ZbyYJAG4lzJ8A2nDTRwRMD3p1 sRrLVw7xi1fMb3wCYXHbTNc/T57yR3LIwNevCgGEFJFFbih7kgjDhFWK+A5qdPW+H2a8 BhEbOfG7evxefgjUJOB5XTRpxtpXLGqiKJX97Ai0j1/Q0CXWb7YIitokCX658CXl6UI2 9ETA== 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 z11si2345959ejj.115.2020.05.27.08.55.57; Wed, 27 May 2020 08:56:21 -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 S1730255AbgE0OAe (ORCPT + 99 others); Wed, 27 May 2020 10:00:34 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:35962 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730223AbgE0OAc (ORCPT ); Wed, 27 May 2020 10:00:32 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 545F18030834; Wed, 27 May 2020 14:00:28 +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 LZtLme4p0vqb; Wed, 27 May 2020 17:00:27 +0300 (MSK) Date: Wed, 27 May 2020 17:00:27 +0300 From: Serge Semin To: Andy Shevchenko CC: Serge Semin , , Alexey Malahov , Thomas Bogendoerfer , Wolfram Sang , Jarkko Nikula , Frank Rowand , Rob Herring , , , Subject: Re: [PATCH] check: Add 10bit/slave i2c reg flags support Message-ID: <20200527140027.elc4vkbrzjrq4gqh@mobilestation> References: <20200527122525.6929-1-Sergey.Semin@baikalelectronics.ru> <20200527133656.GV1634618@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20200527133656.GV1634618@smile.fi.intel.com> 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 Wed, May 27, 2020 at 04:36:56PM +0300, Andy Shevchenko wrote: > On Wed, May 27, 2020 at 03:25:25PM +0300, Serge Semin wrote: > > 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 > > ... > > > + addr = reg & 0x3FFFFFFFU; > > + if ((reg & (1 << 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 & (1 << 31)) && addr > 0x7f) > > + FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\"", > > + addr); > > 1 << 31 is UB. Good point. Thanks. -Sergey > > -- > With Best Regards, > Andy Shevchenko > >