From nobody Tue Apr 7 01:54:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 222DBC433F5 for ; Sun, 9 Oct 2022 16:22:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbiJIQWm (ORCPT ); Sun, 9 Oct 2022 12:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbiJIQWk (ORCPT ); Sun, 9 Oct 2022 12:22:40 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D84B6275E8 for ; Sun, 9 Oct 2022 09:22:38 -0700 (PDT) X-QQ-mid: bizesmtp63t1665332548tes0qihh Received: from localhost.localdomain ( [58.247.70.42]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 10 Oct 2022 00:22:27 +0800 (CST) X-QQ-SSF: 01100000002000G0Z000B00A0000000 X-QQ-FEAT: lJ9dImo9Gpf3qGfbbuHdLhphkStRzvkHM9DXOuUIZfz36X3NYtmefNP6oLQqq wNuMooggk9A2IuyJ1zXGo7vuKqhCkZGh7mhUYYEdGlOCGKx28tzZOFFl08XlnnJ1TTzln8p l1dr9FuZFm+uUDWJdUIEfSWodW5dugGvDsM+o6jZgv8n8sfDeKYW5mmyAJMrtk3PX3TB0Xe dVyRoc7/SH6g703CLELjDr9mHT5C2gBSzY3sFlSCFo4PvqrBpv3X74b9ehbOUax28PP6NFD Gwzv0Sao995Mk+n7+UlToHzZHhbDWH9q79ydy7/6E+00IS7xgEJGbf6qoPmyZ2eV2F/QbVX s0t+HX4KIJcpxa5T/KQxUqNhfGZ+T3A5ncbVFuvIqo9H1RK1Cb7Pff0XqrjqA== X-QQ-GoodBg: 0 From: Soha Jin To: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , linux-kernel@vger.kernel.org, Soha Jin Subject: [PATCH 1/3] string: add match_string_nocase() for case-insensitive match Date: Mon, 10 Oct 2022 00:21:53 +0800 Message-Id: <20221009162155.1318-2-soha@lohu.info> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009162155.1318-1-soha@lohu.info> References: <20221009162155.1318-1-soha@lohu.info> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:lohu.info:qybglogicsvr:qybglogicsvr3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Sometimes we want to make a case-insensitive comparison with strings, like checking compatible devices in fwnode properties, so this commit abstracts match_string to __match_string with a compare function. The original match_string will call __match_string with strcmp, and the new match_string_nocase will call it with strcasecmp. Signed-off-by: Soha Jin --- include/linux/string.h | 31 ++++++++++++++++++++++++++++++- lib/string_helpers.c | 10 ++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/include/linux/string.h b/include/linux/string.h index cf7607b32102..fcfa67f598f5 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -183,9 +183,38 @@ extern char **argv_split(gfp_t gfp, const char *str, i= nt *argcp); extern void argv_free(char **argv); =20 extern bool sysfs_streq(const char *s1, const char *s2); -int match_string(const char * const *array, size_t n, const char *string); +int __match_string(const char * const *array, size_t n, const char *string, + int (*cmp)(const char *, const char *)); int __sysfs_match_string(const char * const *array, size_t n, const char *= s); =20 +/** + * match_string - matches given string in an array + * @_a: array of strings + * @_n: number of strings in the array + * @_s: string to match with + * + * Helper for __match_string(). Look for a string in an array of strings u= p to + * the n-th element in the array with a case-sensitive compare. + * + * Return: + * index of a @string in the @array if matches, or %-EINVAL otherwise. + */ +#define match_string(_a, _n, _s) __match_string(_a, _n, _s, strcmp) + +/** + * match_string_nocase - matches given string in an array + * @_a: array of strings + * @_n: number of strings in the array + * @_s: string to match with + * + * Helper for __match_string(). Look for a string in an array of strings u= p to + * the n-th element in the array with a case-insensitive compare. + * + * Return: + * index of a @string in the @array if matches, or %-EINVAL otherwise. + */ +#define match_string_nocase(_a, _n, _s) __match_string(_a, _n, _s, strcase= cmp) + /** * sysfs_match_string - matches given string in an array * @_a: array of strings diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 230020a2e076..52949adfdfe4 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -910,10 +910,11 @@ bool sysfs_streq(const char *s1, const char *s2) EXPORT_SYMBOL(sysfs_streq); =20 /** - * match_string - matches given string in an array + * __match_string - matches given string in an array * @array: array of strings * @n: number of strings in the array or -1 for NULL terminated arrays * @string: string to match with + * @cmp: compare function * * This routine will look for a string in an array of strings up to the * n-th element in the array or until the first NULL element. @@ -926,7 +927,8 @@ EXPORT_SYMBOL(sysfs_streq); * Return: * index of a @string in the @array if matches, or %-EINVAL otherwise. */ -int match_string(const char * const *array, size_t n, const char *string) +int __match_string(const char * const *array, size_t n, const char *string, + int (*cmp)(const char *, const char *)) { int index; const char *item; @@ -935,13 +937,13 @@ int match_string(const char * const *array, size_t n,= const char *string) item =3D array[index]; if (!item) break; - if (!strcmp(item, string)) + if (!cmp(item, string)) return index; } =20 return -EINVAL; } -EXPORT_SYMBOL(match_string); +EXPORT_SYMBOL(__match_string); =20 /** * __sysfs_match_string - matches given string in an array --=20 2.30.2 From nobody Tue Apr 7 01:54:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3D87C433F5 for ; Sun, 9 Oct 2022 16:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230110AbiJIQWp (ORCPT ); Sun, 9 Oct 2022 12:22:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbiJIQWm (ORCPT ); Sun, 9 Oct 2022 12:22:42 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.67.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4561275E8 for ; Sun, 9 Oct 2022 09:22:41 -0700 (PDT) X-QQ-mid: bizesmtp63t1665332550tg3l1ber Received: from localhost.localdomain ( [58.247.70.42]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 10 Oct 2022 00:22:29 +0800 (CST) X-QQ-SSF: 01100000002000G0Z000B00A0000000 X-QQ-FEAT: D6RqbDSxuq5upTGykcxJAyaU0dOQRvgi1FDhmiv9RN+CCAo9tdPA2XbwycMqh 7vJ/26RKv+2ZX6fmHP9bPJpbDa4P8nuqdhXofUHZBx8Xxc2R+ql9kDEEdM/MUsJPnNNz3S+ ev8ruIsNSlwzwZtuR8QfNMA2bMqKea5yLw6+0aCJSf8PEVJNwyaFi5JEEsYVD8uzUqq8UnT GImgSaEtOF8oh552BYSMJ7z8FNFjy5bD7MCzkvsyqq0OmdKGyVbIQoEctsbKtgm+7ySsUak zrU+IybcMOEirI0TOhOsn1cfDRWiTx480PXRzD3XtaHhkX5XIj2w8dGWby8Mmg59yLQV6Ur sHX0No2j0dQJbVR+ih/0jw+luXXruH8szzw9XbyQ/Y7xYvjzs8= X-QQ-GoodBg: 0 From: Soha Jin To: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , linux-kernel@vger.kernel.org, Soha Jin Subject: [PATCH 2/3] device property: add {device,fwnode}_property_match_string_nocase() Date: Mon, 10 Oct 2022 00:21:54 +0800 Message-Id: <20221009162155.1318-3-soha@lohu.info> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009162155.1318-1-soha@lohu.info> References: <20221009162155.1318-1-soha@lohu.info> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:lohu.info:qybglogicsvr:qybglogicsvr3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" device_property_match_string_nocase and fwnode_property_match_string_nocase are used to do case-insensitive match with match_string_nocase. Signed-off-by: Soha Jin --- drivers/base/property.c | 92 ++++++++++++++++++++++++++++++++-------- include/linux/property.h | 6 +++ 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 4d6278a84868..5e579b915e77 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -242,6 +242,30 @@ int device_property_match_string(struct device *dev, c= onst char *propname, } EXPORT_SYMBOL_GPL(device_property_match_string); =20 +/** + * device_property_match_string_nocase - find a string in an array and ret= urn + * index with case-insensitive comparison + * @dev: Device to get the property of + * @propname: Name of the property holding the array + * @string: String to look for + * + * Find a given string in a string array and if it is found return the + * index back. + * + * Return: %0 if the property was found (success), + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the property does not have a value, + * %-EPROTO if the property is not an array of strings, + * %-ENXIO if no suitable firmware interface is present. + */ +int device_property_match_string_nocase(struct device *dev, + const char *propname, const char *string) +{ + return fwnode_property_match_string_nocase(dev_fwnode(dev), propname, + string); +} +EXPORT_SYMBOL_GPL(device_property_match_string_nocase); + static int fwnode_property_read_int_array(const struct fwnode_handle *fwno= de, const char *propname, unsigned int elem_size, void *val, @@ -441,23 +465,9 @@ int fwnode_property_read_string(const struct fwnode_ha= ndle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_property_read_string); =20 -/** - * fwnode_property_match_string - find a string in an array and return ind= ex - * @fwnode: Firmware node to get the property of - * @propname: Name of the property holding the array - * @string: String to look for - * - * Find a given string in a string array and if it is found return the - * index back. - * - * Return: %0 if the property was found (success), - * %-EINVAL if given arguments are not valid, - * %-ENODATA if the property does not have a value, - * %-EPROTO if the property is not an array of strings, - * %-ENXIO if no suitable firmware interface is present. - */ -int fwnode_property_match_string(const struct fwnode_handle *fwnode, - const char *propname, const char *string) +int fwnode_property_do_match_string(const struct fwnode_handle *fwnode, + const char *propname, const char *string, + int (*cmp)(const char *, const char *)) { const char **values; int nval, ret; @@ -477,15 +487,61 @@ int fwnode_property_match_string(const struct fwnode_= handle *fwnode, if (ret < 0) goto out; =20 - ret =3D match_string(values, nval, string); + ret =3D __match_string(values, nval, string, cmp); if (ret < 0) ret =3D -ENODATA; out: kfree(values); return ret; } + +/** + * fwnode_property_match_string - find a string in an array and return ind= ex + * @fwnode: Firmware node to get the property of + * @propname: Name of the property holding the array + * @string: String to look for + * + * Find a given string in a string array and if it is found return the + * index back. + * + * Return: %0 if the property was found (success), + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the property does not have a value, + * %-EPROTO if the property is not an array of strings, + * %-ENXIO if no suitable firmware interface is present. + */ +int fwnode_property_match_string(const struct fwnode_handle *fwnode, + const char *propname, const char *string) +{ + return fwnode_property_do_match_string(fwnode, propname, string, + strcmp); +} EXPORT_SYMBOL_GPL(fwnode_property_match_string); =20 +/** + * fwnode_property_match_string_nocase - find a string in an array and ret= urn + * index with case-insensitive comparison + * @fwnode: Firmware node to get the property of + * @propname: Name of the property holding the array + * @string: String to look for + * + * Find a given string in a string array and if it is found return the + * index back. + * + * Return: %0 if the property was found (success), + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the property does not have a value, + * %-EPROTO if the property is not an array of strings, + * %-ENXIO if no suitable firmware interface is present. + */ +int fwnode_property_match_string_nocase(const struct fwnode_handle *fwnode, + const char *propname, const char *string) +{ + return fwnode_property_do_match_string(fwnode, propname, string, + strcasecmp); +} +EXPORT_SYMBOL_GPL(fwnode_property_match_string_nocase); + /** * fwnode_property_get_reference_args() - Find a reference with arguments * @fwnode: Firmware node where to look for the reference diff --git a/include/linux/property.h b/include/linux/property.h index 117cc200c656..dbe747f3e3be 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -49,6 +49,9 @@ int device_property_read_string(struct device *dev, const= char *propname, const char **val); int device_property_match_string(struct device *dev, const char *propname, const char *string); +int device_property_match_string_nocase(struct device *dev, + const char *propname, + const char *string); =20 bool fwnode_device_is_available(const struct fwnode_handle *fwnode); bool fwnode_property_present(const struct fwnode_handle *fwnode, @@ -72,6 +75,9 @@ int fwnode_property_read_string(const struct fwnode_handl= e *fwnode, const char *propname, const char **val); int fwnode_property_match_string(const struct fwnode_handle *fwnode, const char *propname, const char *string); +int fwnode_property_match_string_nocase(const struct fwnode_handle *fwnode, + const char *propname, + const char *string); int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, const char *prop, const char *nargs_prop, unsigned int nargs, unsigned int index, --=20 2.30.2 From nobody Tue Apr 7 01:54:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD46EC433F5 for ; Sun, 9 Oct 2022 16:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbiJIQXB (ORCPT ); Sun, 9 Oct 2022 12:23:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbiJIQWs (ORCPT ); Sun, 9 Oct 2022 12:22:48 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CB92B19D for ; Sun, 9 Oct 2022 09:22:45 -0700 (PDT) X-QQ-mid: bizesmtp63t1665332553tg3dgxz5 Received: from localhost.localdomain ( [58.247.70.42]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 10 Oct 2022 00:22:32 +0800 (CST) X-QQ-SSF: 01100000002000G0Z000B00A0000000 X-QQ-FEAT: xqT8U4SkSphFgcFPh5JRStQ/GKaIUXNKUgQ68cyZGIRbaqdoULKWb5GOFKtg3 cIxNITCqwXcs2VsfBb/8vGApOIm4U/q4iBSp4mnq580tWgEyhuNcM467J2T2LbqZIGr2LDd r8gOhflJ9f5AWNhMgGTlC+Vsvht1MO5wG/fdSV9ZPLt8DxrrRBLCPZVPoz2MvhuNCjLM7ub SU3BswYGhbXsOkGIe28jEHuduxNT1hd8xCuFaD3TYmGN0yjj7y8JjxPxkQrnE/zdXV45b7v iSugb/5UZ1tITubb34afvTMkCYAy7Aejtd3s9MBxgyjbQxFeN5vL2mkUFhvmm6CNXOKnq24 M3kLYO9wu89Vq6zgnk/39flVPvR2IW9mxUZaCWG6wqRPUdfKnmpcco43mrsfA== X-QQ-GoodBg: 0 From: Soha Jin To: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , linux-kernel@vger.kernel.org, Soha Jin Subject: [PATCH 3/3] device property: add fwnode_is_compatible() for compatible match Date: Mon, 10 Oct 2022 00:21:55 +0800 Message-Id: <20221009162155.1318-4-soha@lohu.info> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009162155.1318-1-soha@lohu.info> References: <20221009162155.1318-1-soha@lohu.info> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:lohu.info:qybglogicsvr:qybglogicsvr3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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); } =20 +static inline bool fwnode_is_compatible(const struct fwnode_handle *fwnode, + const char *compat) +{ + return fwnode_property_match_string_nocase(fwnode, "compatible", + compat) >=3D 0; +} + struct software_node; =20 /** --=20 2.30.2