[2/3] dt-bindings: net: sun8i-emac: Fix snps,dwmac.yaml inheritance

Message ID 20221125202008.64595-3-samuel@sholland.org
State New
Headers
Series dt-bindings: net: sunxi: Fix binding validation issues |

Commit Message

Samuel Holland Nov. 25, 2022, 8:20 p.m. UTC
  The sun8i-emac binding extends snps,dwmac.yaml, and should accept all
properties defined there, including "mdio", "resets", and "reset-names".
However, validation currently fails for these properties because the
local binding sets "unevaluatedProperties: false", and snps,dwmac.yaml
is only included inside an allOf block. Fix this by referencing
snps,dwmac.yaml at the top level.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 .../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml     | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Krzysztof Kozlowski Nov. 26, 2022, 1:26 p.m. UTC | #1
On 25/11/2022 21:20, Samuel Holland wrote:
> The sun8i-emac binding extends snps,dwmac.yaml, and should accept all
> properties defined there, including "mdio", "resets", and "reset-names".
> However, validation currently fails for these properties because the

validation does not fail:
make dt_binding_check -> no problems

Maybe you meant that DTS do not pass dtbs_check?


> local binding sets "unevaluatedProperties: false", and snps,dwmac.yaml
> is only included inside an allOf block. Fix this by referencing
> snps,dwmac.yaml at the top level.

There is nothing being fixed here...

> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
> 
>  .../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml     | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> index 1432fda3b603..34a47922296d 100644
> --- a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> +++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> @@ -10,6 +10,8 @@ maintainers:
>    - Chen-Yu Tsai <wens@csie.org>
>    - Maxime Ripard <mripard@kernel.org>
>  
> +$ref: "snps,dwmac.yaml#"
> +
>  properties:
>    compatible:
>      oneOf:
> @@ -60,7 +62,6 @@ required:
>    - syscon
>  
>  allOf:
> -  - $ref: "snps,dwmac.yaml#"
>    - if:
>        properties:
>          compatible:

Best regards,
Krzysztof
  
Krzysztof Kozlowski Nov. 26, 2022, 2:15 p.m. UTC | #2
On 25/11/2022 21:20, Samuel Holland wrote:
> The sun8i-emac binding extends snps,dwmac.yaml, and should accept all
> properties defined there, including "mdio", "resets", and "reset-names".
> However, validation currently fails for these properties because the
> local binding sets "unevaluatedProperties: false", and snps,dwmac.yaml
> is only included inside an allOf block. Fix this by referencing
> snps,dwmac.yaml at the top level.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
> 
>  .../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml     | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 

I must admit you're right that this hides the warning from dtbs_check,
but not because something in allOf should not be included. The problem
is how disabled nodes are being parsed here by referenced schema
(snps,dwmac.yaml) and probably is a bug in dtschema package.


Best regards,
Krzysztof
  
Andre Przywara Nov. 26, 2022, 2:28 p.m. UTC | #3
On Sat, 26 Nov 2022 14:26:25 +0100
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

Hi,

> On 25/11/2022 21:20, Samuel Holland wrote:
> > The sun8i-emac binding extends snps,dwmac.yaml, and should accept all
> > properties defined there, including "mdio", "resets", and "reset-names".
> > However, validation currently fails for these properties because the  
> 
> validation does not fail:
> make dt_binding_check -> no problems
> 
> Maybe you meant that DTS do not pass dtbs_check?

Yes, that's what he meant: If a board actually doesn't have Ethernet
configured, dt-validate complains. I saw this before, but didn't find
any solution.
An example is: $ dt-validate ... sun50i-a64-pinephone-1.2.dtb
arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dtb:
  ethernet@1c30000: Unevaluated properties are not allowed ('resets', 'reset-names', 'mdio' were unexpected)
  From schema: Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml

Why exactly is beyond me, but this patch removes this message.

Cheers,
Andre


> > local binding sets "unevaluatedProperties: false", and snps,dwmac.yaml
> > is only included inside an allOf block. Fix this by referencing
> > snps,dwmac.yaml at the top level.  
> 
> There is nothing being fixed here...
> 
> > 
> > Signed-off-by: Samuel Holland <samuel@sholland.org>
> > ---
> > 
> >  .../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml     | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> > index 1432fda3b603..34a47922296d 100644
> > --- a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> > +++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> > @@ -10,6 +10,8 @@ maintainers:
> >    - Chen-Yu Tsai <wens@csie.org>
> >    - Maxime Ripard <mripard@kernel.org>
> >  
> > +$ref: "snps,dwmac.yaml#"
> > +
> >  properties:
> >    compatible:
> >      oneOf:
> > @@ -60,7 +62,6 @@ required:
> >    - syscon
> >  
> >  allOf:
> > -  - $ref: "snps,dwmac.yaml#"
> >    - if:
> >        properties:
> >          compatible:  
> 
> Best regards,
> Krzysztof
> 
>
  
Krzysztof Kozlowski Nov. 26, 2022, 2:48 p.m. UTC | #4
On 26/11/2022 15:28, Andre Przywara wrote:
> On Sat, 26 Nov 2022 14:26:25 +0100
> Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> 
> Hi,
> 
>> On 25/11/2022 21:20, Samuel Holland wrote:
>>> The sun8i-emac binding extends snps,dwmac.yaml, and should accept all
>>> properties defined there, including "mdio", "resets", and "reset-names".
>>> However, validation currently fails for these properties because the  
>>
>> validation does not fail:
>> make dt_binding_check -> no problems
>>
>> Maybe you meant that DTS do not pass dtbs_check?
> 
> Yes, that's what he meant: If a board actually doesn't have Ethernet
> configured, dt-validate complains. I saw this before, but didn't find
> any solution.
> An example is: $ dt-validate ... sun50i-a64-pinephone-1.2.dtb
> arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dtb:
>   ethernet@1c30000: Unevaluated properties are not allowed ('resets', 'reset-names', 'mdio' were unexpected)
>   From schema: Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> 
> Why exactly is beyond me, but this patch removes this message.

I don't think this should be fixed like this. That's the problem of
dtschema (not ignoring fully disabled nodes) and such patch only moves
from one correct syntax to another correct syntax, which fixes dtschema
problem, but changes nothing here.

Best regards,
Krzysztof
  
Rob Herring Dec. 1, 2022, 3:45 a.m. UTC | #5
On Sat, Nov 26, 2022 at 03:48:33PM +0100, Krzysztof Kozlowski wrote:
> On 26/11/2022 15:28, Andre Przywara wrote:
> > On Sat, 26 Nov 2022 14:26:25 +0100
> > Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> > 
> > Hi,
> > 
> >> On 25/11/2022 21:20, Samuel Holland wrote:
> >>> The sun8i-emac binding extends snps,dwmac.yaml, and should accept all
> >>> properties defined there, including "mdio", "resets", and "reset-names".
> >>> However, validation currently fails for these properties because the  
> >>
> >> validation does not fail:
> >> make dt_binding_check -> no problems
> >>
> >> Maybe you meant that DTS do not pass dtbs_check?
> > 
> > Yes, that's what he meant: If a board actually doesn't have Ethernet
> > configured, dt-validate complains. I saw this before, but didn't find
> > any solution.
> > An example is: $ dt-validate ... sun50i-a64-pinephone-1.2.dtb
> > arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dtb:
> >   ethernet@1c30000: Unevaluated properties are not allowed ('resets', 'reset-names', 'mdio' were unexpected)
> >   From schema: Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> > 
> > Why exactly is beyond me, but this patch removes this message.
> 
> I don't think this should be fixed like this. That's the problem of
> dtschema (not ignoring fully disabled nodes) and such patch only moves
> from one correct syntax to another correct syntax, which fixes dtschema
> problem, but changes nothing here.

Humm, it looks to me like the 'phy-mode' required in snps,dwmac.yaml 
causes the problem, but I can't get a minimized example to fail. 
Something in 'required' shouldn't matter. Definitely seems like an issue 
in the jsonschema package. I'll keep looking at it.

Rob
  
Rob Herring Dec. 1, 2022, 6:10 p.m. UTC | #6
On Wed, Nov 30, 2022 at 9:45 PM Rob Herring <robh@kernel.org> wrote:
>
> On Sat, Nov 26, 2022 at 03:48:33PM +0100, Krzysztof Kozlowski wrote:
> > On 26/11/2022 15:28, Andre Przywara wrote:
> > > On Sat, 26 Nov 2022 14:26:25 +0100
> > > Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> > >
> > > Hi,
> > >
> > >> On 25/11/2022 21:20, Samuel Holland wrote:
> > >>> The sun8i-emac binding extends snps,dwmac.yaml, and should accept all
> > >>> properties defined there, including "mdio", "resets", and "reset-names".
> > >>> However, validation currently fails for these properties because the
> > >>
> > >> validation does not fail:
> > >> make dt_binding_check -> no problems
> > >>
> > >> Maybe you meant that DTS do not pass dtbs_check?
> > >
> > > Yes, that's what he meant: If a board actually doesn't have Ethernet
> > > configured, dt-validate complains. I saw this before, but didn't find
> > > any solution.
> > > An example is: $ dt-validate ... sun50i-a64-pinephone-1.2.dtb
> > > arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dtb:
> > >   ethernet@1c30000: Unevaluated properties are not allowed ('resets', 'reset-names', 'mdio' were unexpected)
> > >   From schema: Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
> > >
> > > Why exactly is beyond me, but this patch removes this message.
> >
> > I don't think this should be fixed like this. That's the problem of
> > dtschema (not ignoring fully disabled nodes) and such patch only moves
> > from one correct syntax to another correct syntax, which fixes dtschema
> > problem, but changes nothing here.
>
> Humm, it looks to me like the 'phy-mode' required in snps,dwmac.yaml
> causes the problem, but I can't get a minimized example to fail.
> Something in 'required' shouldn't matter. Definitely seems like an issue
> in the jsonschema package. I'll keep looking at it.

TLDR: A fix in dtschema for this will be in place soon.

I've simplified this down to:
{
    "$schema": "https://json-schema.org/draft/2019-09/schema",

    "unevaluatedProperties": false,
    "allOf":[
        {
            "properties": {
                "foo": true,
                "bar": true
            },
            "required": [ "foo" ]
        }
    ]
}

An instance { "bar": 1 } will fail due to the 'required' failing. When
you have a subschema (what's under 'allOf'), then it all has to pass
to be 'evaluated'. This seems inconsistent to me, but the json-schema
folks say it is operating as intended.

I've got 2 possible fixes. One is to just ignore unevaluatedProperties
errors on disabled nodes like is already done for 'required'. This
means disabled nodes can have any unknown property or child node added
which isn't great. The other way overrides 'required' validation to
always pass on disabled nodes. This would be better, but there are
some exceptions we need to still fail. 'oneOf' with N entries of
'required' to say 1 of N properties must be present for example.
Excluding each one of these cases will be fragile, so probably going
with the first fix.

Rob
  

Patch

diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
index 1432fda3b603..34a47922296d 100644
--- a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
+++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml
@@ -10,6 +10,8 @@  maintainers:
   - Chen-Yu Tsai <wens@csie.org>
   - Maxime Ripard <mripard@kernel.org>
 
+$ref: "snps,dwmac.yaml#"
+
 properties:
   compatible:
     oneOf:
@@ -60,7 +62,6 @@  required:
   - syscon
 
 allOf:
-  - $ref: "snps,dwmac.yaml#"
   - if:
       properties:
         compatible: