devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* case sensitivity for devicetree node names
@ 2016-06-10 20:05 Frank Rowand
       [not found] ` <575B1D84.2010703-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Frank Rowand @ 2016-06-10 20:05 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, David Gibson,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

I had assumed that devicetree node names were case sensitive. But a recent
email thread asserted that they were not, which made me curious.

dtc treats node names as case sensitive:

$ cat test_node_case_1.dts

/dts-v1/;

/ {
	node-x {
		prop_a = < 1 >;
	};
};

/ {
	node-X {
		prop_a = < 2 >;
	};
};

$ cat test_node_case_2.dts

/dts-v1/;

/ {
	node-x {
		prop_a = < 1 >;
	};
};

/ {
	node-x {
		prop_a = < 2 >;
	};
};

$ dtc -O dts test_node_case_1.dts
/dts-v1/;

/ {

	node-x {
		prop_a = <0x1>;
	};

	node-X {
		prop_a = <0x2>;
	};
};

$ dtc -O dts test_node_case_2.dts
/dts-v1/;

/ {

	node-x {
		prop_a = <0x2>;
	};
};


But the Linux kernel source code defines of_node_cmp() as:

  include/linux/of.h:

  /* Default string compare functions, Allow arch asm/prom.h to override */
  #if !defined(of_compat_cmp)
  #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))

arch/sparc/include/asm/prom.h uses strcmp() instead of strcasecmp().

Examples of using of_node_cmp() to check for a node name can be found,
for example, of_find_node_by_name().

Is case insensitivity for node names a bug in the Linux kernel, or desired
for some reason?

-Frank

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found] ` <575B1D84.2010703-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-06-10 21:38   ` Rob Herring
       [not found]     ` <CAL_JsqKw8dVp5y487fo6_mwZfeN6ww8HiYnsudnB8afBrv2oMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2016-06-11 19:38   ` Frank Rowand
  2016-06-14  1:10   ` David Gibson
  2 siblings, 1 reply; 12+ messages in thread
From: Rob Herring @ 2016-06-10 21:38 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Grant Likely, David Gibson,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On Fri, Jun 10, 2016 at 3:05 PM, Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> I had assumed that devicetree node names were case sensitive. But a recent
> email thread asserted that they were not, which made me curious.

News to me. Got a pointer?

Rob

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]     ` <CAL_JsqKw8dVp5y487fo6_mwZfeN6ww8HiYnsudnB8afBrv2oMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-06-10 22:02       ` Frank Rowand
  0 siblings, 0 replies; 12+ messages in thread
From: Frank Rowand @ 2016-06-10 22:02 UTC (permalink / raw)
  To: Rob Herring
  Cc: Grant Likely, David Gibson,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 06/10/16 14:38, Rob Herring wrote:
> On Fri, Jun 10, 2016 at 3:05 PM, Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> I had assumed that devicetree node names were case sensitive. But a recent
>> email thread asserted that they were not, which made me curious.
> 
> News to me. Got a pointer?
> 
> Rob
> 

http://lkml.iu.edu/hypermail/linux/kernel/1606.1/02457.html

Subject: RE: [RESEND PATCH v2 1/2] device property: Add function to search
for named child of device
From: "Opensource [Adam Thomson]" <Adam.Thomson.Opensource-WBD+wuPFNBhBDgjK7y7TUQ@public.gmane.org>
Date: Fri, 10 Jun 2016 09:58:39 +0000


Snippet:

>
> Why do you use strcasecmp() here?

DT node names are case insensitive. The of.h header does provide a helper macro
which is equivalent to this, but that macro is part of the '#ifdef CONFIG_OF'
block. If I were to use it then it would cause non-DT builds to fail. I opted
for strcasecmp() directly as I didn't think for just this one scenario it made
sense to reorganise the of.h header with regards to the helper macros. Of course
if there are other opinions on this then am happy to listen.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found] ` <575B1D84.2010703-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2016-06-10 21:38   ` Rob Herring
@ 2016-06-11 19:38   ` Frank Rowand
       [not found]     ` <575C68A1.1020701-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2016-06-14  1:10   ` David Gibson
  2 siblings, 1 reply; 12+ messages in thread
From: Frank Rowand @ 2016-06-11 19:38 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Rob Herring, Grant Likely, David Gibson,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Paul Mackerras,
	Michael Ellerman, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

Hi Ben,

(and adding other powerpc folks)

On 06/10/16 13:05, Frank Rowand wrote:
> I had assumed that devicetree node names were case sensitive. But a recent
> email thread asserted that they were not, which made me curious.
> 
> dtc treats node names as case sensitive:
> 
> $ cat test_node_case_1.dts
> 
> /dts-v1/;
> 
> / {
> 	node-x {
> 		prop_a = < 1 >;
> 	};
> };
> 
> / {
> 	node-X {
> 		prop_a = < 2 >;
> 	};
> };
> 
> $ cat test_node_case_2.dts
> 
> /dts-v1/;
> 
> / {
> 	node-x {
> 		prop_a = < 1 >;
> 	};
> };
> 
> / {
> 	node-x {
> 		prop_a = < 2 >;
> 	};
> };
> 
> $ dtc -O dts test_node_case_1.dts
> /dts-v1/;
> 
> / {
> 
> 	node-x {
> 		prop_a = <0x1>;
> 	};
> 
> 	node-X {
> 		prop_a = <0x2>;
> 	};
> };
> 
> $ dtc -O dts test_node_case_2.dts
> /dts-v1/;
> 
> / {
> 
> 	node-x {
> 		prop_a = <0x2>;
> 	};
> };
> 
> 
> But the Linux kernel source code defines of_node_cmp() as:
> 
>   include/linux/of.h:
> 
>   /* Default string compare functions, Allow arch asm/prom.h to override */
>   #if !defined(of_compat_cmp)
>   #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
> 
> arch/sparc/include/asm/prom.h uses strcmp() instead of strcasecmp().
> 
> Examples of using of_node_cmp() to check for a node name can be found,
> for example, of_find_node_by_name().
> 
> Is case insensitivity for node names a bug in the Linux kernel, or desired
> for some reason?
> 
> -Frank
> 

I chased through the history and found a 2.6.0-test5 announcement
which noted the patch from you which adds:

  of_find_node_by_path()
  of_find_node_by_name()
  of_find_node_by_type()
  of_find_compatible_node()

(And the patch is commit 394edd852a14 in the git recreation
of bitkeeper days, which is found at
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git)

That version of the functions uses a case insensitive compare for
devicetree node names.

Do you remember why you chose to not use a case sensitive compare?

Thanks,

-Frank

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]     ` <575C68A1.1020701-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-06-11 22:05       ` Benjamin Herrenschmidt
       [not found]         ` <1465682743.19533.18.camel-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Benjamin Herrenschmidt @ 2016-06-11 22:05 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Rob Herring, Grant Likely, David Gibson,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Paul Mackerras,
	Michael Ellerman, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Sat, 2016-06-11 at 12:38 -0700, Frank Rowand wrote:
> I chased through the history and found a 2.6.0-test5 announcement
> which noted the patch from you which adds:
> 
>   of_find_node_by_path()
>   of_find_node_by_name()
>   of_find_node_by_type()
>   of_find_compatible_node()
> 
> (And the patch is commit 394edd852a14 in the git recreation
> of bitkeeper days, which is found at
> git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git)
> 
> That version of the functions uses a case insensitive compare for
> devicetree node names.
> 
> Do you remember why you chose to not use a case sensitive compare?

From memory, there were inconsistency in case on various earlier
machines (notably old macs). I think that's the main reason.

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]         ` <1465682743.19533.18.camel-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
@ 2016-06-12 18:39           ` Frank Rowand
       [not found]             ` <575DAC69.5010804-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Frank Rowand @ 2016-06-12 18:39 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Rob Herring, Grant Likely, David Gibson,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Paul Mackerras,
	Michael Ellerman, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On 06/11/16 15:05, Benjamin Herrenschmidt wrote:
> On Sat, 2016-06-11 at 12:38 -0700, Frank Rowand wrote:
>> I chased through the history and found a 2.6.0-test5 announcement
>> which noted the patch from you which adds:
>>
>>   of_find_node_by_path()
>>   of_find_node_by_name()
>>   of_find_node_by_type()
>>   of_find_compatible_node()
>>
>> (And the patch is commit 394edd852a14 in the git recreation
>> of bitkeeper days, which is found at
>> git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git)
>>
>> That version of the functions uses a case insensitive compare for
>> devicetree node names.
>>
>> Do you remember why you chose to not use a case sensitive compare?
> 
>>From memory, there were inconsistency in case on various earlier
> machines (notably old macs). I think that's the main reason.
> 
> Cheers,
> Ben.

Is there a kernel config option (or a small set of config options)
that would identify the affected machines?  It would be ok if
the option(s) also included some non-affected machines.  That
way we could use the case insensitive compare for a small
set of machines.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]             ` <575DAC69.5010804-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-06-12 21:56               ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 12+ messages in thread
From: Benjamin Herrenschmidt @ 2016-06-12 21:56 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Rob Herring, Grant Likely, David Gibson,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Paul Mackerras,
	Michael Ellerman, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Sun, 2016-06-12 at 11:39 -0700, Frank Rowand wrote:
> 
> Is there a kernel config option (or a small set of config options)
> that would identify the affected machines?  It would be ok if
> the option(s) also included some non-affected machines.  That
> way we could use the case insensitive compare for a small
> set of machines.

Why do we want this ? Are there people really wanting to rely on case
difference between nodes ? That sounds fishy...

If you really want to do that, then CONFIG_PPC_PMAC would be your
test I suppose.

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found] ` <575B1D84.2010703-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2016-06-10 21:38   ` Rob Herring
  2016-06-11 19:38   ` Frank Rowand
@ 2016-06-14  1:10   ` David Gibson
       [not found]     ` <20160614011021.GD4882-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
  2 siblings, 1 reply; 12+ messages in thread
From: David Gibson @ 2016-06-14  1:10 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Rob Herring, Grant Likely,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 2560 bytes --]

On Fri, Jun 10, 2016 at 01:05:24PM -0700, Frank Rowand wrote:
> I had assumed that devicetree node names were case sensitive. But a recent
> email thread asserted that they were not, which made me curious.
> 
> dtc treats node names as case sensitive:
> 
> $ cat test_node_case_1.dts
> 
> /dts-v1/;
> 
> / {
> 	node-x {
> 		prop_a = < 1 >;
> 	};
> };
> 
> / {
> 	node-X {
> 		prop_a = < 2 >;
> 	};
> };
> 
> $ cat test_node_case_2.dts
> 
> /dts-v1/;
> 
> / {
> 	node-x {
> 		prop_a = < 1 >;
> 	};
> };
> 
> / {
> 	node-x {
> 		prop_a = < 2 >;
> 	};
> };
> 
> $ dtc -O dts test_node_case_1.dts
> /dts-v1/;
> 
> / {
> 
> 	node-x {
> 		prop_a = <0x1>;
> 	};
> 
> 	node-X {
> 		prop_a = <0x2>;
> 	};
> };
> 
> $ dtc -O dts test_node_case_2.dts
> /dts-v1/;
> 
> / {
> 
> 	node-x {
> 		prop_a = <0x2>;
> 	};
> };
> 
> 
> But the Linux kernel source code defines of_node_cmp() as:
> 
>   include/linux/of.h:
> 
>   /* Default string compare functions, Allow arch asm/prom.h to override */
>   #if !defined(of_compat_cmp)
>   #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
> 
> arch/sparc/include/asm/prom.h uses strcmp() instead of strcasecmp().
> 
> Examples of using of_node_cmp() to check for a node name can be found,
> for example, of_find_node_by_name().
> 
> Is case insensitivity for node names a bug in the Linux kernel, or desired
> for some reason?

Hmm.. a bit embarrassingly, I've never really thought about this in
all the years I've been doing dtc - I also pretty much just assumed
it was case-sensitive.

I haven't been able to find something in IEEE 1275 definitively saying
one way or the other - it's not exactly easy to search for since
"case" gives you hundreds or thousands of irrelevant hits of the form
"in the case of blah".

I do recall that there was a semantic difference between vendor
prefixes in uppercase (they were supposed to be stock tickers) and
those in lowercase (those were freeform).  That suggests that property
names at least were expected to be case sensitive.

Here's my inclination for how to treat this in dtc for the time being:
    1) Leave the bulk of dtc case sensitive, as now
    2) Add a new check which will generate an error if there are node
       names which differ only in case.

Any objections to that plan?

-- 
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: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]     ` <20160614011021.GD4882-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
@ 2016-06-14  3:53       ` Frank Rowand
       [not found]         ` <575F7FC1.5040508-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Frank Rowand @ 2016-06-14  3:53 UTC (permalink / raw)
  To: David Gibson
  Cc: Rob Herring, Grant Likely,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 06/13/16 18:10, David Gibson wrote:
> On Fri, Jun 10, 2016 at 01:05:24PM -0700, Frank Rowand wrote:
>> I had assumed that devicetree node names were case sensitive. But a recent
>> email thread asserted that they were not, which made me curious.
>>
>> dtc treats node names as case sensitive:
>>
>> $ cat test_node_case_1.dts
>>
>> /dts-v1/;
>>
>> / {
>> 	node-x {
>> 		prop_a = < 1 >;
>> 	};
>> };
>>
>> / {
>> 	node-X {
>> 		prop_a = < 2 >;
>> 	};
>> };
>>
>> $ cat test_node_case_2.dts
>>
>> /dts-v1/;
>>
>> / {
>> 	node-x {
>> 		prop_a = < 1 >;
>> 	};
>> };
>>
>> / {
>> 	node-x {
>> 		prop_a = < 2 >;
>> 	};
>> };
>>
>> $ dtc -O dts test_node_case_1.dts
>> /dts-v1/;
>>
>> / {
>>
>> 	node-x {
>> 		prop_a = <0x1>;
>> 	};
>>
>> 	node-X {
>> 		prop_a = <0x2>;
>> 	};
>> };
>>
>> $ dtc -O dts test_node_case_2.dts
>> /dts-v1/;
>>
>> / {
>>
>> 	node-x {
>> 		prop_a = <0x2>;
>> 	};
>> };
>>
>>
>> But the Linux kernel source code defines of_node_cmp() as:
>>
>>   include/linux/of.h:
>>
>>   /* Default string compare functions, Allow arch asm/prom.h to override */
>>   #if !defined(of_compat_cmp)
>>   #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
>>
>> arch/sparc/include/asm/prom.h uses strcmp() instead of strcasecmp().
>>
>> Examples of using of_node_cmp() to check for a node name can be found,
>> for example, of_find_node_by_name().
>>
>> Is case insensitivity for node names a bug in the Linux kernel, or desired
>> for some reason?
> 
> Hmm.. a bit embarrassingly, I've never really thought about this in
> all the years I've been doing dtc - I also pretty much just assumed
> it was case-sensitive.
> 
> I haven't been able to find something in IEEE 1275 definitively saying
> one way or the other - it's not exactly easy to search for since
> "case" gives you hundreds or thousands of irrelevant hits of the form
> "in the case of blah".

One reference in 1275 that I just happened to notice this morning is
in "3.2.1.1 Node names":

   Each node in the device tree is identified by a node name using the following notation:

      driver-name@unit-addres:device-arguments

   The driver name field is a sequence of between one and 31 letters, digits, and punctuation characters from the set
   ",._+-". Uppercase and lowercase characters are distinct.

I am reading "Uppercase and lowercase characters are distinct" to mean that
node names are case sensitive.


> I do recall that there was a semantic difference between vendor
> prefixes in uppercase (they were supposed to be stock tickers) and
> those in lowercase (those were freeform).  That suggests that property
> names at least were expected to be case sensitive.
> 
> Here's my inclination for how to treat this in dtc for the time being:
>     1) Leave the bulk of dtc case sensitive, as now
>     2) Add a new check which will generate an error if there are node
>        names which differ only in case.
> 
> Any objections to that plan?

I think that the kernel should match the current behavior of dtc.

I agree with "1)".

I don't think that "2)" is required.  I think it is a really dumb idea for
anyone to create a dts with node names that differ only in case.  But I
don't think it is the compiler's job to protect people from being dumb.
An analogue would be the C language and compilers.  The C compiler doesn't
error on a program that has variables "foo" and "Foo".

My current thought is to create a Linux kernel RFC patch that 

1) changes of_node_cmp() and friends to something like:

   #ifdef CONFIG_OF_CASE_BROKEN
   #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
   #else
   #define of_node_cmp(s1, s2) strcmp((s1), (s2))
   #endif

2) remove the sparc definition of of_node_cmp() and friends.

3) Change the Kconfig entry for CONFIG_PPC_PMAC to select
   CONFIG_OF_CASE_BROKEN

Then let the patch sit in the -next tree for two releases to
try to shake out any issues.  Any other case broken platform
could then select or set CONFIG_OF_CASE_BROKEN if the dts
and/or code can't be reasonably fixed.

I have a patch series (a few kernel printks and a userspace
program to parse the console output) that shows 1) which
properties the kernel attempts to access but do not exist
in a given device tree and 2) which properties are in a
given device tree but the kernel does _not_ attempt to
access.  I could probably extend that to do the same checks
for node names.  The patch series is not quite ready for
prime-time, but I could make it easily available for
anyone who is trying to figure out why my proposed
kernel patch breaks a system's boot.  Then it becomes
a case by case choice of whether to fix the devicetrees or
modify the kernel to also check for the incorrect case node.

-Frank

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]         ` <575F7FC1.5040508-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-06-14  5:10           ` David Gibson
       [not found]             ` <20160614051028.GL4882-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: David Gibson @ 2016-06-14  5:10 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Rob Herring, Grant Likely,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 5715 bytes --]

On Mon, Jun 13, 2016 at 08:53:37PM -0700, Frank Rowand wrote:
> On 06/13/16 18:10, David Gibson wrote:
> > On Fri, Jun 10, 2016 at 01:05:24PM -0700, Frank Rowand wrote:
> >> I had assumed that devicetree node names were case sensitive. But a recent
> >> email thread asserted that they were not, which made me curious.
> >>
> >> dtc treats node names as case sensitive:
> >>
> >> $ cat test_node_case_1.dts
> >>
> >> /dts-v1/;
> >>
> >> / {
> >> 	node-x {
> >> 		prop_a = < 1 >;
> >> 	};
> >> };
> >>
> >> / {
> >> 	node-X {
> >> 		prop_a = < 2 >;
> >> 	};
> >> };
> >>
> >> $ cat test_node_case_2.dts
> >>
> >> /dts-v1/;
> >>
> >> / {
> >> 	node-x {
> >> 		prop_a = < 1 >;
> >> 	};
> >> };
> >>
> >> / {
> >> 	node-x {
> >> 		prop_a = < 2 >;
> >> 	};
> >> };
> >>
> >> $ dtc -O dts test_node_case_1.dts
> >> /dts-v1/;
> >>
> >> / {
> >>
> >> 	node-x {
> >> 		prop_a = <0x1>;
> >> 	};
> >>
> >> 	node-X {
> >> 		prop_a = <0x2>;
> >> 	};
> >> };
> >>
> >> $ dtc -O dts test_node_case_2.dts
> >> /dts-v1/;
> >>
> >> / {
> >>
> >> 	node-x {
> >> 		prop_a = <0x2>;
> >> 	};
> >> };
> >>
> >>
> >> But the Linux kernel source code defines of_node_cmp() as:
> >>
> >>   include/linux/of.h:
> >>
> >>   /* Default string compare functions, Allow arch asm/prom.h to override */
> >>   #if !defined(of_compat_cmp)
> >>   #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
> >>
> >> arch/sparc/include/asm/prom.h uses strcmp() instead of strcasecmp().
> >>
> >> Examples of using of_node_cmp() to check for a node name can be found,
> >> for example, of_find_node_by_name().
> >>
> >> Is case insensitivity for node names a bug in the Linux kernel, or desired
> >> for some reason?
> > 
> > Hmm.. a bit embarrassingly, I've never really thought about this in
> > all the years I've been doing dtc - I also pretty much just assumed
> > it was case-sensitive.
> > 
> > I haven't been able to find something in IEEE 1275 definitively saying
> > one way or the other - it's not exactly easy to search for since
> > "case" gives you hundreds or thousands of irrelevant hits of the form
> > "in the case of blah".
> 
> One reference in 1275 that I just happened to notice this morning is
> in "3.2.1.1 Node names":
> 
>    Each node in the device tree is identified by a node name using the following notation:
> 
>       driver-name@unit-addres:device-arguments
> 
>    The driver name field is a sequence of between one and 31 letters, digits, and punctuation characters from the set
>    ",._+-". Uppercase and lowercase characters are distinct.
> 
> I am reading "Uppercase and lowercase characters are distinct" to mean that
> node names are case sensitive.

Yes, that's my reading as well.

> > I do recall that there was a semantic difference between vendor
> > prefixes in uppercase (they were supposed to be stock tickers) and
> > those in lowercase (those were freeform).  That suggests that property
> > names at least were expected to be case sensitive.
> > 
> > Here's my inclination for how to treat this in dtc for the time being:
> >     1) Leave the bulk of dtc case sensitive, as now
> >     2) Add a new check which will generate an error if there are node
> >        names which differ only in case.
> > 
> > Any objections to that plan?
> 
> I think that the kernel should match the current behavior of dtc.
> 
> I agree with "1)".
> 
> I don't think that "2)" is required.  I think it is a really dumb idea for
> anyone to create a dts with node names that differ only in case.  But I
> don't think it is the compiler's job to protect people from being dumb.
> An analogue would be the C language and compilers.  The C compiler doesn't
> error on a program that has variables "foo" and "Foo".

Hmm.. actually I think protecting you from being dumb is exactly the
purpose of compiler warnings.  Now that you found that quote from
1275, which is pretty definitive as far as I'm concerned, I'd expect
to reduce that error to a warning (by default).

> My current thought is to create a Linux kernel RFC patch that 
> 
> 1) changes of_node_cmp() and friends to something like:
> 
>    #ifdef CONFIG_OF_CASE_BROKEN
>    #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
>    #else
>    #define of_node_cmp(s1, s2) strcmp((s1), (s2))
>    #endif
> 
> 2) remove the sparc definition of of_node_cmp() and friends.
> 
> 3) Change the Kconfig entry for CONFIG_PPC_PMAC to select
>    CONFIG_OF_CASE_BROKEN
> 
> Then let the patch sit in the -next tree for two releases to
> try to shake out any issues.  Any other case broken platform
> could then select or set CONFIG_OF_CASE_BROKEN if the dts
> and/or code can't be reasonably fixed.
> 
> I have a patch series (a few kernel printks and a userspace
> program to parse the console output) that shows 1) which
> properties the kernel attempts to access but do not exist
> in a given device tree and 2) which properties are in a
> given device tree but the kernel does _not_ attempt to
> access.  I could probably extend that to do the same checks
> for node names.  The patch series is not quite ready for
> prime-time, but I could make it easily available for
> anyone who is trying to figure out why my proposed
> kernel patch breaks a system's boot.  Then it becomes
> a case by case choice of whether to fix the devicetrees or
> modify the kernel to also check for the incorrect case node.
> 
> -Frank

-- 
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: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]             ` <20160614051028.GL4882-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
@ 2016-06-14  5:29               ` Frank Rowand
       [not found]                 ` <575F963F.8090105-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Frank Rowand @ 2016-06-14  5:29 UTC (permalink / raw)
  To: David Gibson
  Cc: Rob Herring, Grant Likely,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 06/13/16 22:10, David Gibson wrote:
> On Mon, Jun 13, 2016 at 08:53:37PM -0700, Frank Rowand wrote:
>> On 06/13/16 18:10, David Gibson wrote:

< snip >

>>> Here's my inclination for how to treat this in dtc for the time being:
>>>     1) Leave the bulk of dtc case sensitive, as now
>>>     2) Add a new check which will generate an error if there are node
>>>        names which differ only in case.
>>>
>>> Any objections to that plan?
>>
>> I think that the kernel should match the current behavior of dtc.
>>
>> I agree with "1)".
>>
>> I don't think that "2)" is required.  I think it is a really dumb idea for
>> anyone to create a dts with node names that differ only in case.  But I
>> don't think it is the compiler's job to protect people from being dumb.
>> An analogue would be the C language and compilers.  The C compiler doesn't
>> error on a program that has variables "foo" and "Foo".
> 
> Hmm.. actually I think protecting you from being dumb is exactly the
> purpose of compiler warnings.  Now that you found that quote from
> 1275, which is pretty definitive as far as I'm concerned, I'd expect
> to reduce that error to a warning (by default).

A warning is ok by me.

-Frank

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: case sensitivity for devicetree node names
       [not found]                 ` <575F963F.8090105-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-06-14  6:05                   ` David Gibson
  0 siblings, 0 replies; 12+ messages in thread
From: David Gibson @ 2016-06-14  6:05 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Rob Herring, Grant Likely,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 1787 bytes --]

On Mon, Jun 13, 2016 at 10:29:35PM -0700, Frank Rowand wrote:
> On 06/13/16 22:10, David Gibson wrote:
> > On Mon, Jun 13, 2016 at 08:53:37PM -0700, Frank Rowand wrote:
> >> On 06/13/16 18:10, David Gibson wrote:
> 
> < snip >
> 
> >>> Here's my inclination for how to treat this in dtc for the time being:
> >>>     1) Leave the bulk of dtc case sensitive, as now
> >>>     2) Add a new check which will generate an error if there are node
> >>>        names which differ only in case.
> >>>
> >>> Any objections to that plan?
> >>
> >> I think that the kernel should match the current behavior of dtc.
> >>
> >> I agree with "1)".
> >>
> >> I don't think that "2)" is required.  I think it is a really dumb idea for
> >> anyone to create a dts with node names that differ only in case.  But I
> >> don't think it is the compiler's job to protect people from being dumb.
> >> An analogue would be the C language and compilers.  The C compiler doesn't
> >> error on a program that has variables "foo" and "Foo".
> > 
> > Hmm.. actually I think protecting you from being dumb is exactly the
> > purpose of compiler warnings.  Now that you found that quote from
> > 1275, which is pretty definitive as far as I'm concerned, I'd expect
> > to reduce that error to a warning (by default).
> 
> A warning is ok by me.

Ok, I'll implement that when I get a chance.

Note that in most cases there's no fundamental distinction between dtc
errors and dtc warnings - it's just a question of whether they're
flagged as "error" or "warning" level in the check table.

-- 
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: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-06-14  6:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-10 20:05 case sensitivity for devicetree node names Frank Rowand
     [not found] ` <575B1D84.2010703-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-06-10 21:38   ` Rob Herring
     [not found]     ` <CAL_JsqKw8dVp5y487fo6_mwZfeN6ww8HiYnsudnB8afBrv2oMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-10 22:02       ` Frank Rowand
2016-06-11 19:38   ` Frank Rowand
     [not found]     ` <575C68A1.1020701-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-06-11 22:05       ` Benjamin Herrenschmidt
     [not found]         ` <1465682743.19533.18.camel-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
2016-06-12 18:39           ` Frank Rowand
     [not found]             ` <575DAC69.5010804-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-06-12 21:56               ` Benjamin Herrenschmidt
2016-06-14  1:10   ` David Gibson
     [not found]     ` <20160614011021.GD4882-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-14  3:53       ` Frank Rowand
     [not found]         ` <575F7FC1.5040508-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-06-14  5:10           ` David Gibson
     [not found]             ` <20160614051028.GL4882-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-14  5:29               ` Frank Rowand
     [not found]                 ` <575F963F.8090105-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-06-14  6:05                   ` David Gibson

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).