X-Received: by 2002:a17:90a:6944:b0:1bc:40a0:a12d with SMTP id j4-20020a17090a694400b001bc40a0a12dmr2410438pjm.138.1645507461352; Mon, 21 Feb 2022 21:24:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645507461; cv=none; d=google.com; s=arc-20160816; b=tB5B3AhGZkRFXTHIhFgrY3nxL+w/nHIQXhtLSY/QGEHlpL7CzFdXvVUz7q6e4VfZrp DtPR12wOsp62BsXVhuGyBVh2q4WsqrNrKt3CjDcfxafUzIIqfzFGlo3NWPwjEJR44ucg 1NzeMprDTkTZWs5pqGGHmxCWR7plJGsfKedqaSMZwl/MymhU8dztgRTEl1mq4gsB4szc UpFvMN7fgtwwnkuLqem8sr9BpSoUK6iOma4g6qNwh82xNutmn+WCLaMZdQ8+fVc0isGW uNEVdxj76jt+QhBTCwBrdIL+BKiaaokXVpCkoIPghu7+3+GaC5SlwrvBqbYXCp07wuKB 1+dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yFZyD/xsoWg/S0R33oq47fx2Ang45t7YDLbGipkmDBU=; b=y0NDELuKSzw754gTI/rEULALOstylvn6K+RxfwU0RyHGS+UjjzHSQwqLZTtVVrcSM1 gXn6HP9SWNNgddIjI1WNh8H8npP/jZwdoX+MW9/IXkgOGPTJePLd8GbF9poEeM+XBGs+ 0PsUetikwgNpeFzgdcsn/gfB/at1BFgm577JQO5w8+Rbqh3pURlkGzpYm4QwA+4dK/Gg 3c4ZI75VBdwn+0Nl0VbFXrANetKifPOCg5lK78ekSRERJDIJLol8G/qXwG83LMnzGzfw THxmNlLyqcHPLjOmbOSraiXfP/459pXDPYZHyyazjeJwyN1wCL1j7aJZl3qNCIb9k/nW ZT2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=owA9gnqT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p4si10869814pgs.294.2022.02.21.21.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:24:21 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=owA9gnqT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8DBF3102403; Mon, 21 Feb 2022 20:55:01 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380917AbiBUQjb (ORCPT + 99 others); Mon, 21 Feb 2022 11:39:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380793AbiBUQjK (ORCPT ); Mon, 21 Feb 2022 11:39:10 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98894237FF; Mon, 21 Feb 2022 08:38:39 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 83F0BC3549; Mon, 21 Feb 2022 16:29:18 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id E0190FF80E; Mon, 21 Feb 2022 16:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yFZyD/xsoWg/S0R33oq47fx2Ang45t7YDLbGipkmDBU=; b=owA9gnqTS5qqrRnkgIHNLJMrzZ/Xpguf/yNrSyIkJdRdPNBZiwWwffvpJqwydxsTlrBXIG 4GqmqKnGSJecFBvzF1zKDEtl5eBZeRrHKTEJUOR4Ditxxp0JQfi1GDtwYNiEkpy8n58X5w DQAeRKgHbiUu6XRKL+62CPJpJDXbEVaTvyyznf//QxXDeBvr77b8Ly3Wu8WwL+OrB5K8z7 YQglolFnIAL2wIUaxw/h3d3o4CM5DFQ+w9In8tyTRvHH3tMD+K/iw+4XYG6EDJjIadrXkj 0LGjKCnJEuueFOzQdKreE9C5LYJ22XL67mO3FM4EdsizWoorp/DFpab6nAqfPw== From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= Subject: [RFC 04/10] property: add a callback parameter to fwnode_property_match_string() Date: Mon, 21 Feb 2022 17:26:46 +0100 Message-Id: <20220221162652.103834-5-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function will be modified to be reused for fwnode_property_read_string_index(). In order to avoid copy/paste of existing code, split the existing function and pass a callback that will be executed once the string array has been retrieved. In order to reuse this function with other actions. Signed-off-by: Clément Léger --- drivers/base/property.c | 50 +++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 6ffb3ac4509c..cd1c30999fd9 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -410,10 +410,11 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string); * fwnode_property_match_string - find a string in an array and return index * @fwnode: Firmware node to get the property of * @propname: Name of the property holding the array - * @string: String to look for + * @cb: callback to execute on the string array + * @data: data to be passed to the callback * - * Find a given string in a string array and if it is found return the - * index back. + * Execute a given callback on a string array values and returns the callback + * return value. * * Return: %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -421,8 +422,10 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string); * %-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) +static int fwnode_property_string_match(const struct fwnode_handle *fwnode, + const char *propname, + int (*cb)(const char **, int, void *), + void *data) { const char **values; int nval, ret; @@ -442,13 +445,46 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode, if (ret < 0) goto out; + ret = cb(values, nval, data); +out: + kfree(values); + return ret; +} + +static int match_string_callback(const char **values, int nval, void *data) +{ + int ret; + const char *string = data; + ret = match_string(values, nval, string); if (ret < 0) ret = -ENODATA; -out: - kfree(values); + return ret; } + +/** + * fwnode_property_match_string - find a string in an array and return index + * @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_string_match(fwnode, propname, + match_string_callback, + (void *)string); +} EXPORT_SYMBOL_GPL(fwnode_property_match_string); /** -- 2.34.1