* [PATCH v3 0/2] dtc: Improve checks for i2c reg properties
@ 2020-05-28 8:56 Joel Stanley
2020-05-28 8:56 ` [PATCH v3 1/2] checks: Remove warning for I2C_OWN_SLAVE_ADDRESS Joel Stanley
[not found] ` <20200528085650.1417942-1-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
0 siblings, 2 replies; 7+ messages in thread
From: Joel Stanley @ 2020-05-28 8:56 UTC (permalink / raw)
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, David Gibson
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, Stephen Rothwell,
Arnd Bergmann
This is to fix a build warning in the Linux kernel caused by dtc
incorrectly warning about I2C_OWN_SLAVE_ADDRESS.
v3 fixes the 10 bit size check
v2 contains a second patch to check for 10 bit vs 7 bit addresses.
Joel Stanley (2):
checks: Remove warning for I2C_OWN_SLAVE_ADDRESS
checks: Improve i2c reg property checking
checks.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/2] checks: Remove warning for I2C_OWN_SLAVE_ADDRESS
2020-05-28 8:56 [PATCH v3 0/2] dtc: Improve checks for i2c reg properties Joel Stanley
@ 2020-05-28 8:56 ` Joel Stanley
[not found] ` <20200528085650.1417942-1-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
1 sibling, 0 replies; 7+ messages in thread
From: Joel Stanley @ 2020-05-28 8:56 UTC (permalink / raw)
To: devicetree-compiler, David Gibson
Cc: linux-kernel, Stephen Rothwell, Arnd Bergmann
dtc does a sanity check on reg properties that they are within the 10
bit address range for i2c slave addresses. In the case of multi-master
buses or devices that act as a slave, the binding may describe an
address that the bus will listen on as a device. Do not warn when this
flag is set.
See Documentation/devicetree/bindings/i2c/i2c.txt.
This fixes the following build warnings reported by Stephen and by Arnd:
arch/arm/boot/dts/aspeed-bmc-facebook-yosemitev2.dts:126.11-130.4:
Warning (i2c_bus_reg): /ahb/apb/bus@1e78a000/i2c-bus@80/ipmb1@10:
I2C bus unit address format error, expected "40000010"
arch/arm/boot/dts/aspeed-bmc-facebook-yosemitev2.dts:128.3-30:
Warning (i2c_bus_reg): /ahb/apb/bus@1e78a000/i2c-bus@80/ipmb1@10:reg:
I2C address must be less than 10-bits, got "0x40000010"
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
v2: Fix typo
---
checks.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/checks.c b/checks.c
index a8213c0e13a8..feb1721f2603 100644
--- a/checks.c
+++ b/checks.c
@@ -1022,6 +1022,8 @@ 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)
+
static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
{
struct property *prop;
@@ -1044,6 +1046,8 @@ 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;
snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
if (!streq(unitname, unit_addr))
FAIL(c, dti, node, "I2C bus unit address format error, expected \"%s\"",
@@ -1051,6 +1055,8 @@ static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node
for (len = prop->val.len; len > 0; len -= 4) {
reg = fdt32_to_cpu(*(cells++));
+ /* Ignore I2C_OWN_SLAVE_ADDRESS */
+ reg &= ~I2C_OWN_SLAVE_ADDRESS;
if (reg > 0x3ff)
FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"",
reg);
--
2.26.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/2] checks: Improve i2c reg property checking
[not found] ` <20200528085650.1417942-1-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
@ 2020-05-28 8:56 ` Joel Stanley
[not found] ` <20200528085650.1417942-3-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
2020-05-29 22:33 ` [PATCH v3 0/2] dtc: Improve checks for i2c reg properties Rob Herring
1 sibling, 1 reply; 7+ messages in thread
From: Joel Stanley @ 2020-05-28 8:56 UTC (permalink / raw)
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, David Gibson
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, Stephen Rothwell,
Arnd Bergmann
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 <joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
---
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)
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] dtc: Improve checks for i2c reg properties
[not found] ` <20200528085650.1417942-1-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
2020-05-28 8:56 ` [PATCH v3 2/2] checks: Improve i2c reg property checking Joel Stanley
@ 2020-05-29 22:33 ` Rob Herring
1 sibling, 0 replies; 7+ messages in thread
From: Rob Herring @ 2020-05-29 22:33 UTC (permalink / raw)
To: Joel Stanley
Cc: Devicetree Compiler, David Gibson,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Stephen Rothwell, Arnd Bergmann
On Thu, May 28, 2020 at 2:57 AM Joel Stanley <joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org> wrote:
>
> This is to fix a build warning in the Linux kernel caused by dtc
> incorrectly warning about I2C_OWN_SLAVE_ADDRESS.
>
> v3 fixes the 10 bit size check
> v2 contains a second patch to check for 10 bit vs 7 bit addresses.
>
> Joel Stanley (2):
> checks: Remove warning for I2C_OWN_SLAVE_ADDRESS
> checks: Improve i2c reg property checking
Reviewed-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
I'll sync the kernel copy when David applies.
Rob
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] checks: Improve i2c reg property checking
[not found] ` <20200528085650.1417942-3-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
@ 2020-06-02 8:01 ` Serge Semin
2020-06-02 8:28 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Serge Semin @ 2020-06-02 8:01 UTC (permalink / raw)
To: Joel Stanley
Cc: Serge Semin, Wolfram Sang, Andy Shevchenko, Rob Herring,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, David Gibson,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Stephen Rothwell,
Arnd Bergmann
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 <joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
> ---
> 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-XvqNBM/wLWRrdx17CPfAsdBPR1lH4CV8@public.gmane.org/
(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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] checks: Improve i2c reg property checking
2020-06-02 8:01 ` Serge Semin
@ 2020-06-02 8:28 ` Andy Shevchenko
[not found] ` <CAHp75VdkBbDhFSYQYxuej=XH1MYAq-p6AWZZRLpW_iKt9D31_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2020-06-02 8:28 UTC (permalink / raw)
To: Serge Semin
Cc: Joel Stanley, Serge Semin, Wolfram Sang, Andy Shevchenko,
Rob Herring, devicetree-compiler-u79uwXL29TY76Z2rM5mHXA,
David Gibson, Linux Kernel Mailing List, Stephen Rothwell,
Arnd Bergmann
On Tue, Jun 2, 2020 at 11:03 AM Serge Semin
<Sergey.Semin-UN2wsyeM1qLJ45LvJ/SUn8gurn75+9Lz@public.gmane.org> wrote:
> On Thu, May 28, 2020 at 06:26:50PM +0930, Joel Stanley wrote:
...
> > +#define I2C_TEN_BIT_ADDRESS (1 << 31)
>
> As Andy neatly pointed out here:
> https://lore.kernel.org/lkml/20200527133656.GV1634618-XvqNBM/wLWRrdx17CPfAsdBPR1lH4CV8@public.gmane.org/
> (1 << 31) is UB.
Thanks, Serge. Yes, we have to use 1U in the definitions (for 31 is
necessary, for the rest is for the sake of consistency).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] checks: Improve i2c reg property checking
[not found] ` <CAHp75VdkBbDhFSYQYxuej=XH1MYAq-p6AWZZRLpW_iKt9D31_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2020-06-04 7:14 ` David Gibson
0 siblings, 0 replies; 7+ messages in thread
From: David Gibson @ 2020-06-04 7:14 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Serge Semin, Joel Stanley, Serge Semin, Wolfram Sang,
Andy Shevchenko, Rob Herring,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA,
Linux Kernel Mailing List, Stephen Rothwell, Arnd Bergmann
[-- Attachment #1: Type: text/plain, Size: 941 bytes --]
On Tue, Jun 02, 2020 at 11:28:05AM +0300, Andy Shevchenko wrote:
> On Tue, Jun 2, 2020 at 11:03 AM Serge Semin
> <Sergey.Semin-UN2wsyeM1qLJ45LvJ/SUn8gurn75+9Lz@public.gmane.org> wrote:
> > On Thu, May 28, 2020 at 06:26:50PM +0930, Joel Stanley wrote:
>
> ...
>
> > > +#define I2C_TEN_BIT_ADDRESS (1 << 31)
> >
> > As Andy neatly pointed out here:
> > https://lore.kernel.org/lkml/20200527133656.GV1634618-XvqNBM/wLWRrdx17CPfAsWGXanvQGlWp@public.gmane.orgm/
> > (1 << 31) is UB.
>
> Thanks, Serge. Yes, we have to use 1U in the definitions (for 31 is
> necessary, for the rest is for the sake of consistency).
Joel, I know it seems trivial, but I'm a bit flat out right now. Can
you please resend with the 1U fix applied.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-06-04 7:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-28 8:56 [PATCH v3 0/2] dtc: Improve checks for i2c reg properties Joel Stanley
2020-05-28 8:56 ` [PATCH v3 1/2] checks: Remove warning for I2C_OWN_SLAVE_ADDRESS Joel Stanley
[not found] ` <20200528085650.1417942-1-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
2020-05-28 8:56 ` [PATCH v3 2/2] checks: Improve i2c reg property checking Joel Stanley
[not found] ` <20200528085650.1417942-3-joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
2020-06-02 8:01 ` Serge Semin
2020-06-02 8:28 ` Andy Shevchenko
[not found] ` <CAHp75VdkBbDhFSYQYxuej=XH1MYAq-p6AWZZRLpW_iKt9D31_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-06-04 7:14 ` David Gibson
2020-05-29 22:33 ` [PATCH v3 0/2] dtc: Improve checks for i2c reg properties Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).