public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Antoniu Miclaus <antoniu.miclaus@analog.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Gerald Loacker <gerald.loacker@wolfvision.net>,
	Gwendal Grignou <gwendal@chromium.org>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, Daniel Scally <djrscally@gmail.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>
Subject: Re: [PATCH v1 2/6] device property: Add fwnode_property_match_property_string()
Date: Wed, 9 Aug 2023 18:59:44 +0100	[thread overview]
Message-ID: <20230809185944.1ae78e34@jic23-huawei> (raw)
In-Reply-To: <20230808162800.61651-3-andriy.shevchenko@linux.intel.com>

On Tue,  8 Aug 2023 19:27:56 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> 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 <andriy.shevchenko@linux.intel.com>
> ---
>  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)

Hi Andy,

Whilst I'm not 100% sold on adding ever increasing complexity to what we
match, this one feels like a common enough thing to be worth providing.

Looking at the usecases I wonder if it would be better to pass in
an unsigned int *ret which is only updated on a match?

That way the common properties approach of not checking the return value
if we have an optional property would apply.

e.g. patch 3 would end up with a block that looks like:

	st->input_mode = ADMV1014_IQ_MODE;
	device_property_match_property_string(&spi->dev, "adi,input-mode",
					      input_mode_names,
					      ARRAY_SIZE(input_mode_names),
					      &st->input_mode);

Only neat and tidy if the thing being optionally read into is an unsigned int
though (otherwise you still need a local variable)

Jonathan


> +{
> +	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,


  reply	other threads:[~2023-08-09 17:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08 16:27 [PATCH v1 0/6] iio: Introduce and use device_property_match_property_string() Andy Shevchenko
2023-08-08 16:27 ` [PATCH v1 1/6] device property: Use fwnode_property_string_array_count() Andy Shevchenko
2023-10-17 19:14   ` Rafael J. Wysocki
2023-08-08 16:27 ` [PATCH v1 2/6] device property: Add fwnode_property_match_property_string() Andy Shevchenko
2023-08-09 17:59   ` Jonathan Cameron [this message]
2023-08-10 13:26     ` Andy Shevchenko
2023-08-28 18:01       ` Jonathan Cameron
2023-10-17 19:19         ` Rafael J. Wysocki
2023-10-17 19:43           ` Andy Shevchenko
2023-10-18 19:37             ` Jonathan Cameron
2023-10-19 12:05               ` Andy Shevchenko
2023-08-08 16:27 ` [PATCH v1 3/6] iio: frequency: adf4377: Switch to device_property_match_property_string() Andy Shevchenko
2023-08-08 16:27 ` [PATCH v1 4/6] iio: frequency: admv1014: " Andy Shevchenko
2023-08-08 16:27 ` [PATCH v1 5/6] iio: magnetometer: tmag5273: " Andy Shevchenko
2023-08-08 16:28 ` [PATCH v1 6/6] iio: proximity: sx9324: " Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230809185944.1ae78e34@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=antoniu.miclaus@analog.com \
    --cc=djrscally@gmail.com \
    --cc=gerald.loacker@wolfvision.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=gwendal@chromium.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=lars@metafoo.de \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox