diff mbox series

[01/16] dm: core: Add helper to compare node names

Message ID 20210309122748.31842-2-kishon@ti.com
State New
Headers show
Series TI/Cadence: Add Sierra/Torrent SERDES driver | expand

Commit Message

Kishon Vijay Abraham I March 9, 2021, 12:27 p.m. UTC
Add helper to compare node names.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

---
 drivers/core/ofnode.c | 13 +++++++++++++
 include/dm/ofnode.h   |  9 +++++++++
 2 files changed, 22 insertions(+)

-- 
2.17.1

Comments

Simon Glass March 12, 2021, 4:45 a.m. UTC | #1
Hi Kishon,

On Tue, 9 Mar 2021 at 05:27, Kishon Vijay Abraham I <kishon@ti.com> wrote:
>

> Add helper to compare node names.

>

> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

> ---

>  drivers/core/ofnode.c | 13 +++++++++++++

>  include/dm/ofnode.h   |  9 +++++++++

>  2 files changed, 22 insertions(+)

>

> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c

> index fa0bd2a9c4..4e196d680e 100644

> --- a/drivers/core/ofnode.c

> +++ b/drivers/core/ofnode.c

> @@ -18,6 +18,19 @@

>  #include <linux/ioport.h>

>  #include <asm/global_data.h>

>

> +bool ofnode_name_eq(ofnode node, const char *name)

> +{

> +       const char *node_name;

> +       size_t len;

> +

> +       assert(ofnode_valid(node));

> +

> +       node_name = ofnode_get_name(node);

> +       len = strchrnul(node_name, '@') - node_name;

> +

> +       return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);


Can you use !strncmp() instead of == 0 ?

> +}

> +

>  int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)

>  {

>         return ofnode_read_u32_index(node, propname, 0, outp);

> diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h

> index 2c0597c407..86a139276b 100644

> --- a/include/dm/ofnode.h

> +++ b/include/dm/ofnode.h

> @@ -231,6 +231,15 @@ static inline ofnode ofnode_root(void)

>         return node;

>  }

>

> +/**

> + * ofnode_name_eq() - Check if the node name is equivalent to a given name

> + *


How about a comment indicating this ignores the unit address?

> + * @node:      valid node reference that has to be compared

> + * @name:      name that has to be compared with the node name

> + * @return 1 if matches, 0 if it doesn't match

> + */

> +bool ofnode_name_eq(ofnode node, const char *name);

> +

>  /**

>   * ofnode_read_u32() - Read a 32-bit integer from a property

>   *

> --

> 2.17.1

>


Please add a test for this in test/dm

Regards,
SImon
Kishon Vijay Abraham I March 22, 2021, 5:06 a.m. UTC | #2
Hi Simon,

On 12/03/21 10:15 am, Simon Glass wrote:
> Hi Kishon,

> 

> On Tue, 9 Mar 2021 at 05:27, Kishon Vijay Abraham I <kishon@ti.com> wrote:

>>

>> Add helper to compare node names.

>>

>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

>> ---

>>  drivers/core/ofnode.c | 13 +++++++++++++

>>  include/dm/ofnode.h   |  9 +++++++++

>>  2 files changed, 22 insertions(+)

>>

>> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c

>> index fa0bd2a9c4..4e196d680e 100644

>> --- a/drivers/core/ofnode.c

>> +++ b/drivers/core/ofnode.c

>> @@ -18,6 +18,19 @@

>>  #include <linux/ioport.h>

>>  #include <asm/global_data.h>

>>

>> +bool ofnode_name_eq(ofnode node, const char *name)

>> +{

>> +       const char *node_name;

>> +       size_t len;

>> +

>> +       assert(ofnode_valid(node));

>> +

>> +       node_name = ofnode_get_name(node);

>> +       len = strchrnul(node_name, '@') - node_name;

>> +

>> +       return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);

> 

> Can you use !strncmp() instead of == 0 ?

> 

>> +}

>> +

>>  int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)

>>  {

>>         return ofnode_read_u32_index(node, propname, 0, outp);

>> diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h

>> index 2c0597c407..86a139276b 100644

>> --- a/include/dm/ofnode.h

>> +++ b/include/dm/ofnode.h

>> @@ -231,6 +231,15 @@ static inline ofnode ofnode_root(void)

>>         return node;

>>  }

>>

>> +/**

>> + * ofnode_name_eq() - Check if the node name is equivalent to a given name

>> + *

> 

> How about a comment indicating this ignores the unit address?

> 

>> + * @node:      valid node reference that has to be compared

>> + * @name:      name that has to be compared with the node name

>> + * @return 1 if matches, 0 if it doesn't match

>> + */

>> +bool ofnode_name_eq(ofnode node, const char *name);

>> +

>>  /**

>>   * ofnode_read_u32() - Read a 32-bit integer from a property

>>   *

>> --

>> 2.17.1

>>

> 

> Please add a test for this in test/dm


Thanks for reviewing! Will fix it in my next revision.

Thanks
Kishon
diff mbox series

Patch

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index fa0bd2a9c4..4e196d680e 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -18,6 +18,19 @@ 
 #include <linux/ioport.h>
 #include <asm/global_data.h>
 
+bool ofnode_name_eq(ofnode node, const char *name)
+{
+	const char *node_name;
+	size_t len;
+
+	assert(ofnode_valid(node));
+
+	node_name = ofnode_get_name(node);
+	len = strchrnul(node_name, '@') - node_name;
+
+	return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
+}
+
 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
 {
 	return ofnode_read_u32_index(node, propname, 0, outp);
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 2c0597c407..86a139276b 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -231,6 +231,15 @@  static inline ofnode ofnode_root(void)
 	return node;
 }
 
+/**
+ * ofnode_name_eq() - Check if the node name is equivalent to a given name
+ *
+ * @node:	valid node reference that has to be compared
+ * @name:	name that has to be compared with the node name
+ * @return 1 if matches, 0 if it doesn't match
+ */
+bool ofnode_name_eq(ofnode node, const char *name);
+
 /**
  * ofnode_read_u32() - Read a 32-bit integer from a property
  *