* [PATCH] drivers/of: Improve documentation on match string
@ 2024-09-10 14:24 Miquel Sabaté Solà
2024-09-11 16:43 ` Rob Herring
0 siblings, 1 reply; 3+ messages in thread
From: Miquel Sabaté Solà @ 2024-09-10 14:24 UTC (permalink / raw)
To: robh; +Cc: saravanak, devicetree, linux-kernel, Miquel Sabaté Solà
The description of the function now explicitly states that it's
an *exact* match for the given string (i.e. not a submatch). It also
better states all the possible return values.
Moreover, this commit also makes sure that -ENODATA is returned if
prop->length is zero, just like it's done in other functions such as
'of_property_read_string'.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
---
drivers/of/property.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/of/property.c b/drivers/of/property.c
index 164d77cb9445..1ff51d93178f 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -452,12 +452,17 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
/**
* of_property_match_string() - Find string in a list and return index
- * @np: pointer to node containing string list property
+ * @np: pointer to the node containing the string list property
* @propname: string list property name
- * @string: pointer to string to search for in string list
+ * @string: pointer to the string to search for in the string list
*
- * This function searches a string list property and returns the index
- * of a specific string value.
+ * Search for an exact match of string in a device node property which is a
+ * list of strings.
+ *
+ * Return: the index of the first occurrence of the string on success, -EINVAL
+ * if the property does not exist, -ENODATA if the property does not have a
+ * value, and -EILSEQ if the string is not null-terminated within the length of
+ * the property data.
*/
int of_property_match_string(const struct device_node *np, const char *propname,
const char *string)
@@ -469,7 +474,7 @@ int of_property_match_string(const struct device_node *np, const char *propname,
if (!prop)
return -EINVAL;
- if (!prop->value)
+ if (!prop->value || !prop->length)
return -ENODATA;
p = prop->value;
--
2.46.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers/of: Improve documentation on match string
2024-09-10 14:24 [PATCH] drivers/of: Improve documentation on match string Miquel Sabaté Solà
@ 2024-09-11 16:43 ` Rob Herring
2024-09-11 20:44 ` Miquel Sabaté Solà
0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2024-09-11 16:43 UTC (permalink / raw)
To: Miquel Sabaté Solà; +Cc: saravanak, devicetree, linux-kernel
On Tue, Sep 10, 2024 at 04:24:22PM +0200, Miquel Sabaté Solà wrote:
> The description of the function now explicitly states that it's
> an *exact* match for the given string (i.e. not a submatch). It also
> better states all the possible return values.
>
> Moreover, this commit also makes sure that -ENODATA is returned if
> prop->length is zero, just like it's done in other functions such as
> 'of_property_read_string'.
'also' in a commit message is a sign this should be 2 commits. However,
more below.
>
> Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
> ---
> drivers/of/property.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index 164d77cb9445..1ff51d93178f 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -452,12 +452,17 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
>
> /**
> * of_property_match_string() - Find string in a list and return index
> - * @np: pointer to node containing string list property
> + * @np: pointer to the node containing the string list property
> * @propname: string list property name
> - * @string: pointer to string to search for in string list
> + * @string: pointer to the string to search for in the string list
> *
> - * This function searches a string list property and returns the index
> - * of a specific string value.
> + * Search for an exact match of string in a device node property which is a
> + * list of strings.
> + *
> + * Return: the index of the first occurrence of the string on success, -EINVAL
> + * if the property does not exist, -ENODATA if the property does not have a
> + * value, and -EILSEQ if the string is not null-terminated within the length of
> + * the property data.
> */
> int of_property_match_string(const struct device_node *np, const char *propname,
> const char *string)
> @@ -469,7 +474,7 @@ int of_property_match_string(const struct device_node *np, const char *propname,
>
> if (!prop)
> return -EINVAL;
> - if (!prop->value)
> + if (!prop->value || !prop->length)
This is redundant. If length is 0, then 'end' will be equal to p and
we'll return -ENODATA.
> return -ENODATA;
>
> p = prop->value;
> --
> 2.46.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers/of: Improve documentation on match string
2024-09-11 16:43 ` Rob Herring
@ 2024-09-11 20:44 ` Miquel Sabaté Solà
0 siblings, 0 replies; 3+ messages in thread
From: Miquel Sabaté Solà @ 2024-09-11 20:44 UTC (permalink / raw)
To: Rob Herring; +Cc: saravanak, devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2636 bytes --]
On dc., de set. 11 2024, Rob Herring wrote:
> On Tue, Sep 10, 2024 at 04:24:22PM +0200, Miquel Sabaté Solà wrote:
>> The description of the function now explicitly states that it's
>> an *exact* match for the given string (i.e. not a submatch). It also
>> better states all the possible return values.
>>
>> Moreover, this commit also makes sure that -ENODATA is returned if
>> prop->length is zero, just like it's done in other functions such as
>> 'of_property_read_string'.
>
> 'also' in a commit message is a sign this should be 2 commits. However,
> more below.
>
>>
>> Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
>> ---
>> drivers/of/property.c | 15 ++++++++++-----
>> 1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/of/property.c b/drivers/of/property.c
>> index 164d77cb9445..1ff51d93178f 100644
>> --- a/drivers/of/property.c
>> +++ b/drivers/of/property.c
>> @@ -452,12 +452,17 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
>>
>> /**
>> * of_property_match_string() - Find string in a list and return index
>> - * @np: pointer to node containing string list property
>> + * @np: pointer to the node containing the string list property
>> * @propname: string list property name
>> - * @string: pointer to string to search for in string list
>> + * @string: pointer to the string to search for in the string list
>> *
>> - * This function searches a string list property and returns the index
>> - * of a specific string value.
>> + * Search for an exact match of string in a device node property which is a
>> + * list of strings.
>> + *
>> + * Return: the index of the first occurrence of the string on success, -EINVAL
>> + * if the property does not exist, -ENODATA if the property does not have a
>> + * value, and -EILSEQ if the string is not null-terminated within the length of
>> + * the property data.
>> */
>> int of_property_match_string(const struct device_node *np, const char *propname,
>> const char *string)
>> @@ -469,7 +474,7 @@ int of_property_match_string(const struct device_node *np, const char *propname,
>>
>> if (!prop)
>> return -EINVAL;
>> - if (!prop->value)
>> + if (!prop->value || !prop->length)
>
> This is redundant. If length is 0, then 'end' will be equal to p and
> we'll return -ENODATA.
>
Yikes, I missed it... You are totally right, sorry about that.
>> return -ENODATA;
>>
>> p = prop->value;
>> --
>> 2.46.0
>>
Thanks for the review. I will submit a new version of the patch just
with the documentation part.
Thanks!
Miquel
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-11 20:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10 14:24 [PATCH] drivers/of: Improve documentation on match string Miquel Sabaté Solà
2024-09-11 16:43 ` Rob Herring
2024-09-11 20:44 ` Miquel Sabaté Solà
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).