diff mbox series

[v2,1/2] device property: Introduce fwnode_device_is_compatible() helper

Message ID 20221005152947.71696-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series gpiolib: more cleanups to get rid of of_node | expand

Commit Message

Andy Shevchenko Oct. 5, 2022, 3:29 p.m. UTC
The fwnode_device_is_compatible() helper searches for the
given string in the "compatible" string array property and,
if found, returns true.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/property.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Sakari Ailus Oct. 5, 2022, 9:05 p.m. UTC | #1
Hi Andy,

On Wed, Oct 05, 2022 at 06:29:46PM +0300, Andy Shevchenko wrote:
> The fwnode_device_is_compatible() helper searches for the
> given string in the "compatible" string array property and,
> if found, returns true.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  include/linux/property.h | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/property.h b/include/linux/property.h
> index 1c26d263d5e4..701570423943 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -55,7 +55,6 @@ int device_property_read_string(struct device *dev, const char *propname,
>  int device_property_match_string(struct device *dev,
>  				 const char *propname, const char *string);
>  
> -bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
>  bool fwnode_property_present(const struct fwnode_handle *fwnode,
>  			     const char *propname);
>  int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
> @@ -77,6 +76,15 @@ int fwnode_property_read_string(const struct fwnode_handle *fwnode,
>  				const char *propname, const char **val);
>  int fwnode_property_match_string(const struct fwnode_handle *fwnode,
>  				 const char *propname, const char *string);
> +
> +bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
> +
> +static inline
> +bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat)
> +{
> +	return fwnode_property_match_string(fwnode, "compatible", compat) >= 0;

fwnode_property_match_string() returns zero on success, therefore >= 0 is
not needed. I'd just use !fwnode_property_match_string(...).

For both patches:

Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

> +}
> +
>  int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
>  				       const char *prop, const char *nargs_prop,
>  				       unsigned int nargs, unsigned int index,
Andy Shevchenko Oct. 6, 2022, 12:34 p.m. UTC | #2
On Wed, Oct 05, 2022 at 09:05:54PM +0000, Sakari Ailus wrote:
> On Wed, Oct 05, 2022 at 06:29:46PM +0300, Andy Shevchenko wrote:

...

> fwnode_property_match_string() returns zero on success, therefore >= 0 is
> not needed. I'd just use !fwnode_property_match_string(...).

No, it's bug in the documentation, thanks to rising an attention,
I forgot to send a fix for it earlier.

> For both patches:
> 
> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Thanks, but as stated above the condition in my patch is correct.
It seems due to documentation bug we have some kind of "buggy" code,
luckily not too many to fix.

That said, I'm not going to resend this until PPC (Freescale) maintainers
ask for it. Yang, what's your vision on this series?
diff mbox series

Patch

diff --git a/include/linux/property.h b/include/linux/property.h
index 1c26d263d5e4..701570423943 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -55,7 +55,6 @@  int device_property_read_string(struct device *dev, const char *propname,
 int device_property_match_string(struct device *dev,
 				 const char *propname, const char *string);
 
-bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
 bool fwnode_property_present(const struct fwnode_handle *fwnode,
 			     const char *propname);
 int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
@@ -77,6 +76,15 @@  int fwnode_property_read_string(const struct fwnode_handle *fwnode,
 				const char *propname, const char **val);
 int fwnode_property_match_string(const struct fwnode_handle *fwnode,
 				 const char *propname, const char *string);
+
+bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
+
+static inline
+bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat)
+{
+	return fwnode_property_match_string(fwnode, "compatible", compat) >= 0;
+}
+
 int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
 				       const char *prop, const char *nargs_prop,
 				       unsigned int nargs, unsigned int index,