Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4758853rwb; Tue, 8 Aug 2023 13:24:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWWSng76aCYTfDmdF/rL+kwt2D4u7qzq2pfSk2KM8Qvl/C7CNEr4eqwkdSRmrKkpieKmMm X-Received: by 2002:a17:902:e5c2:b0:1bc:4df5:8bfe with SMTP id u2-20020a170902e5c200b001bc4df58bfemr999642plf.20.1691526290584; Tue, 08 Aug 2023 13:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691526290; cv=none; d=google.com; s=arc-20160816; b=rELz+OGhDYUVHeE9osCxJ9EjoibOW89mnRDmzdN6eroZAoVXI58JVAzLjIVpo4kZs6 6n0gMTYi76fX3ixjFVhrDG6GIfiEMa3T/mnh9YjXQacttiGQG/DzlBy2FBdMMRKPp37Y UL9jUAujRqR2usN6biOzk3uMFENU8c4rCDGOMoaEZZ5I2wukVwfivtDEl2QmgXKgHVjY WKEUTLtdr5AabUao/7PQZqASBEXrs+JhgED+0QRhVcQna5+FVnEfK2uF/KEwspbaYxK9 skD7yLh5b94NfRlyEXdAe5xMI0j1jKn2PHWK6EmCTmOdLArO+wL++1zCVD4kKmn7zCgJ eg1w== 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=kSUwhc3WCxkgbqYCYEC8hXELTz2zfJJmYVX4vCFiXWA=; fh=pEdA8+/af95LJlWFD5rBB7RG10kRMWALDQ/52TY9s20=; b=Nxqq7n/ag8BuzaWZI3QMvYry2CcXHuh8eQwPtDaXkSRWfKOJUjHhg/IoWVYZT1cgND bmnSfywBAYo7JcbNqcA71IvbF/la3nnNh4IsXwAy3GMUsxSgLpmZHUC2hmrzlHfBNuVS 6hfGmgXHs7U/6GwEBhmZNMztTVRcL9gmaNz5EPgjuCuXKYmxFlIaKLb3Kq9MecL6CqLo 0eDfvPssfgPCmxPznFiEMbI1s7yy2GpUGlmwYKPhA+dloKk9TaEdv9Zkk/HF7WzHwFXK IogvGQpaOM/uk1FybX8dR0t5z66JhdYB/r7LlZUbZwv0Ho+GONpwfZMPrph3OWsF+INj UkHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V1ksRFGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij22-20020a170902ab5600b001a677821130si5094915plb.13.2023.08.08.13.24.37; Tue, 08 Aug 2023 13:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V1ksRFGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235169AbjHHR7Z (ORCPT + 99 others); Tue, 8 Aug 2023 13:59:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235191AbjHHR7C (ORCPT ); Tue, 8 Aug 2023 13:59:02 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344F62CC49; Tue, 8 Aug 2023 09:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691512012; x=1723048012; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T9G9Kn2Yy64VyUf7GtnFfOpnJ3qoI3E0S57PnbQfz9w=; b=V1ksRFGmzFjbJsQiNxh0/I0qCGpVUC3CxC0Q2gRnFJ6MHU7unZO161+k 4Z6MWS+FQiH5Fy526et9OY/YIXzZVeKjT8VaGHJkRORbD0QmJh67cdw6T XVYadLZHsu4K/VS5D/Uuth6QJl/Ue+LzMzIL9gCesPzlFl+CqL8iYyIM1 4/fDhrXMxuUV9FBsWhvWiYiVi3tTjqXbcmN0SL9qzu87oNKx+v3Y/hcQZ v6oys+meLsM4JI2sHSris/9kH7HnU6qWF8O1QE4Ene20SL7OWAUXlbNC6 feXNOC4BilSz0gvGY3cesNyzIyw0UdFPb6trIdtFTR1pB0Y8a1mS/XIm+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="457260962" X-IronPort-AV: E=Sophos;i="6.01,156,1684825200"; d="scan'208";a="457260962" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2023 09:25:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="821449150" X-IronPort-AV: E=Sophos;i="6.01,156,1684825200"; d="scan'208";a="821449150" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 08 Aug 2023 09:24:55 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 42942385; Tue, 8 Aug 2023 19:28:03 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Greg Kroah-Hartman , Antoniu Miclaus , Jonathan Cameron , Gerald Loacker , Gwendal Grignou , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron Subject: [PATCH v1 2/6] device property: Add fwnode_property_match_property_string() Date: Tue, 8 Aug 2023 19:27:56 +0300 Message-Id: <20230808162800.61651-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230808162800.61651-1-andriy.shevchenko@linux.intel.com> References: <20230808162800.61651-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham 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 Sometimes the users want to match the single value string property against an array of predefined strings. Create a helper for them. Signed-off-by: Andy Shevchenko --- drivers/base/property.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/property.h | 12 ++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 3bb9505f1631..8f8e2a6816bc 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -498,6 +498,41 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_property_match_string); +/** + * fwnode_property_match_property_string - find a property string value in an array and return index + * @fwnode: Firmware node to get the property of + * @propname: Name of the property holding the string value + * @array: String array to search in + * @n: Size of the @array + * + * Find a property string value in a given @array and if it is found return + * the index back. + * + * Return: index, starting from %0, if the string value was found in the @array (success), + * %-ENOENT when the string value was not found in the @array, + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the property does not have a value, + * %-EPROTO or %-EILSEQ if the property is not a string, + * %-ENXIO if no suitable firmware interface is present. + */ +int fwnode_property_match_property_string(const struct fwnode_handle *fwnode, + const char *propname, const char * const *array, size_t n) +{ + const char *string; + int ret; + + ret = fwnode_property_read_string(fwnode, propname, &string); + if (ret) + return ret; + + ret = match_string(array, n, string); + if (ret < 0) + ret = -ENOENT; + + return ret; +} +EXPORT_SYMBOL_GPL(fwnode_property_match_property_string); + /** * 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 8c3c6685a2ae..11f3ad6814f2 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -97,6 +97,18 @@ static inline bool device_is_compatible(const struct device *dev, const char *co return fwnode_device_is_compatible(dev_fwnode(dev), compat); } +int fwnode_property_match_property_string(const struct fwnode_handle *fwnode, + const char *propname, + const char * const *array, size_t n); + +static inline +int device_property_match_property_string(const struct device *dev, + const char *propname, + const char * const *array, size_t n) +{ + return fwnode_property_match_property_string(dev_fwnode(dev), propname, array, n); +} + int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, const char *prop, const char *nargs_prop, unsigned int nargs, unsigned int index, -- 2.40.0.1.gaa8946217a0b