mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suman Anna <s-anna@ti.com>
To: Mathieu Poirier <mathieu.poirier@linaro.org>, <ohad@wizery.com>,
	<bjorn.andersson@linaro.org>
Cc: <arnaud.pouliquen@st.com>, <linux-remoteproc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 2/3] rpmsg: core: Add support to retrieve name extension
Date: Mon, 8 Jun 2020 17:47:19 -0500	[thread overview]
Message-ID: <632db4a1-74e0-edc4-78ca-53109f11ace8@ti.com> (raw)
In-Reply-To: <20200515205642.13529-3-mathieu.poirier@linaro.org>

Hi Mathieu,

On 5/15/20 3:56 PM, Mathieu Poirier wrote:
> After adding support for rpmsg device name extension, this patch
> provides a function that returns the extension portion of an rpmsg
> device name.  That way users of the name extension functionality don't
> have to write the same boiler plate code to extract the information.
> 
> Suggested-by: Suman Anna <s-anna@ti.com>;
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> Acked-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>

With the below minor nits fixed,

Acked-by: Suman Anna <s-anna@ti.com>

> ---
>   drivers/rpmsg/rpmsg_core.c | 95 ++++++++++++++++++++++++++++++++++++++
>   include/linux/rpmsg.h      | 13 ++++++
>   2 files changed, 108 insertions(+)
> 
> diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
> index 5e01e8dede6b..9583eb936607 100644
> --- a/drivers/rpmsg/rpmsg_core.c
> +++ b/drivers/rpmsg/rpmsg_core.c
> @@ -439,6 +439,101 @@ static int rpmsg_dev_match(struct device *dev, struct device_driver *drv)
>   	return of_driver_match_device(dev, drv);
>   }
>   
> +/**
> + * rpmsg_device_get_name_extension() - get the name extension of a rpmsg device
> + * @rpdev: the rpmsg device to work with
> + * @skip: how many characters in the extension should be skipped over
> + *
> + * With function rpmsg_id_match() allowing for extension of the base driver name
> + * in order to differentiate services, this function returns the extension part
> + * of an rpmsg device name.  As such and with the following rpmsg driver device
> + * id table and rpmsg device names:
> + *
> + * static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
> + *      { .name = "rpmsg-client-sample" },
> + *      { },
> + * }
> + *
> + * rpdev1->id.name == "rpmsg-client-sample";
> + * rpdev2->id.name == "rpmsg-client-sample_instance0";
> + *
> + * Calling rpmsg_device_get_name_extension() will yields the following:
> + *
> + * rpmsg_device_get_name_extension(rpdev1, 0) == NULL;
> + * rpmsg_device_get_name_extension(rpdev2, 0) == "_instance0";
> + * rpmsg_device_get_name_extension(rpdev2, 1) == "instance0";
> + *
> + *

can drop the additional blank line here,

> + * Return: The name extension if found, NULL if the name of the RPMSG device
> + *	   equals the name of the RPMSG driver and an error if no match is
> + *	   found or a validation problem has occurred.
> + */
> +const char *rpmsg_device_get_name_extension(struct rpmsg_device *rpdev,
> +					    unsigned int skip)
> +{
> +	const char *drv_name, *dev_name, *extension;
> +	const struct rpmsg_device_id *ids;
> +	struct device *dev = &rpdev->dev;
> +	struct rpmsg_driver *rpdrv;
> +	bool match = false;
> +	unsigned int i;
> +
> +	if (!dev->driver)
> +		return ERR_PTR(-EINVAL);
> +
> +	rpdrv = to_rpmsg_driver(dev->driver);
> +
> +	/*
> +	 * No point in going further if the device doesn't have name or
> +	 * the driver doesn't have a table to work with.
> +	 */
> +	if (!rpdev->id.name[0] || !rpdrv->id_table)
> +		return ERR_PTR(-EINVAL);
> +
> +	ids = rpdrv->id_table;
> +	dev_name = rpdev->id.name;
> +
> +	/*
> +	 * See if any name in the driver's table match the beginning
> +	 * of the rpmsg device's name.
> +	 */
> +	for (i = 0; ids[i].name[0]; i++) {
> +		drv_name = ids[i].name;
> +		if (strncmp(drv_name,
> +			    dev_name, strlen(drv_name)) == 0) {

This does fit on the same line, so no need to use multi-lines for this.

regards
Suman

> +			match = true;
> +			break;
> +		}
> +	}
> +
> +	/*
> +	 * A match was not found, return an error to differentiate with cases
> +	 * where a match was found but the name has no extension (see below).
> +	 */
> +	if (!match)
> +		return ERR_PTR(-ENOENT);
> +
> +	 /* No name extension to return if device and driver are the same */
> +	if (strlen(dev_name) == strlen(drv_name))
> +		return NULL;
> +
> +	/*
> +	 * Make sure we were not requested to skip past the end
> +	 * of the device name.
> +	 */
> +	if (strlen(drv_name) + skip >= strlen(dev_name))
> +		return ERR_PTR(-EINVAL);
> +
> +	/*
> +	 * Move past the base name published by the driver and
> +	 * skip any extra characters if needed.
> +	 */
> +	extension = dev_name + strlen(drv_name) + skip;
> +
> +	return extension;
> +}
> +EXPORT_SYMBOL(rpmsg_device_get_name_extension);
> +
>   static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env)
>   {
>   	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
> diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h
> index 9fe156d1c018..9537b95ad30a 100644
> --- a/include/linux/rpmsg.h
> +++ b/include/linux/rpmsg.h
> @@ -135,6 +135,9 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
>   __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
>   			poll_table *wait);
>   
> +const char *rpmsg_device_get_name_extension(struct rpmsg_device *dev,
> +					    unsigned int skip);
> +
>   #else
>   
>   static inline int register_rpmsg_device(struct rpmsg_device *dev)
> @@ -242,6 +245,16 @@ static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept,
>   	return 0;
>   }
>   
> +static inline
> +const char *rpmsg_device_get_name_extension(struct rpmsg_device *dev,
> +					    unsigned int skip)
> +{
> +	/* This shouldn't be possible */
> +	WARN_ON(1);
> +
> +	return NULL;
> +}
> +
>   #endif /* IS_ENABLED(CONFIG_RPMSG) */
>   
>   /* use a macro to avoid include chaining to get THIS_MODULE */
> 


  reply	other threads:[~2020-06-08 22:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15 20:56 [PATCH v6 0/3] rpmsg: core: Add support for " Mathieu Poirier
2020-05-15 20:56 ` [PATCH v6 1/3] rpmsg: core: Add wildcard match for name service Mathieu Poirier
2020-06-08 21:11   ` Suman Anna
2020-05-15 20:56 ` [PATCH v6 2/3] rpmsg: core: Add support to retrieve name extension Mathieu Poirier
2020-06-08 22:47   ` Suman Anna [this message]
2020-05-15 20:56 ` [PATCH v6 3/3] sample: rpmsg: Print out RPMSG device " Mathieu Poirier
2020-05-15 21:09 ` [PATCH v6 0/3] rpmsg: core: Add support for " Bjorn Andersson
2020-05-20 14:49   ` Arnaud POULIQUEN
2020-06-08 22:33     ` Suman Anna

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=632db4a1-74e0-edc4-78ca-53109f11ace8@ti.com \
    --to=s-anna@ti.com \
    --cc=arnaud.pouliquen@st.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=ohad@wizery.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

all inboxes | Powered by JetHome®