[PATCH 3/3] device property: add fwnode_is_compatible() for compatible match

Soha Jin posted 3 patches 3 years, 5 months ago
[PATCH 3/3] device property: add fwnode_is_compatible() for compatible match
Posted by Soha Jin 3 years, 5 months ago
fwnode_is_compatible is a shortcut to check if a device is compatible with
a compat string in fwnode property "compatible". This function is similar
to of_device_is_compatible.

Signed-off-by: Soha Jin <soha@lohu.info>
---
 include/linux/property.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/linux/property.h b/include/linux/property.h
index dbe747f3e3be..776e4a8bc379 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -252,6 +252,13 @@ fwnode_property_string_array_count(const struct fwnode_handle *fwnode,
 	return fwnode_property_read_string_array(fwnode, propname, NULL, 0);
 }
 
+static inline bool fwnode_is_compatible(const struct fwnode_handle *fwnode,
+					const char *compat)
+{
+	return fwnode_property_match_string_nocase(fwnode, "compatible",
+						   compat) >= 0;
+}
+
 struct software_node;
 
 /**
-- 
2.30.2
Re: [PATCH 3/3] device property: add fwnode_is_compatible() for compatible match
Posted by Greg Kroah-Hartman 3 years, 5 months ago
On Mon, Oct 10, 2022 at 12:21:55AM +0800, Soha Jin wrote:
> fwnode_is_compatible is a shortcut to check if a device is compatible with
> a compat string in fwnode property "compatible". This function is similar
> to of_device_is_compatible.
> 
> Signed-off-by: Soha Jin <soha@lohu.info>
> ---
>  include/linux/property.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/include/linux/property.h b/include/linux/property.h
> index dbe747f3e3be..776e4a8bc379 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -252,6 +252,13 @@ fwnode_property_string_array_count(const struct fwnode_handle *fwnode,
>  	return fwnode_property_read_string_array(fwnode, propname, NULL, 0);
>  }
>  
> +static inline bool fwnode_is_compatible(const struct fwnode_handle *fwnode,
> +					const char *compat)
> +{
> +	return fwnode_property_match_string_nocase(fwnode, "compatible",
> +						   compat) >= 0;

Who would mistype "compatible" in a case insensitive way?

Why can't you fix the firmware to be correct instead of forcing the
operating system to fix it for them?

thanks,

greg k-h