linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Bartosz Golaszewski <brgl@bgdev.pl>,
	"David S . Miller" <davem@davemloft.net>,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Arnd Bergmann <arnd@arndb.de>, Jonathan Corbet <corbet@lwn.net>,
	Sekhar Nori <nsekhar@ti.com>, Kevin Hilman <khilman@kernel.org>,
	David Lechner <david@lechnology.com>,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	Andrew Lunn <andrew@lunn.ch>, Alban Bedel <albeu@free.fr>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	Chen-Yu Tsai <wens@csie.org>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [PATCH v2 13/16] nvmem: add support for cell lookups from machine code
Date: Mon, 10 Sep 2018 08:32:30 +0100	[thread overview]
Message-ID: <484b6ec5-cd8e-e5c5-0c5c-2f11c504ea1c@linaro.org> (raw)
In-Reply-To: <20180907100750.14564-14-brgl@bgdev.pl>



On 07/09/18 11:07, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> Add a way for machine code users to associate devices with nvmem cells.
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>   drivers/nvmem/core.c          | 143 +++++++++++++++++++++++++++-------
>   include/linux/nvmem-machine.h |  16 ++++
>   2 files changed, 132 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index da7a9d5beb33..9e2f9c993a07 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -62,6 +62,9 @@ static DEFINE_IDA(nvmem_ida);
>   static DEFINE_MUTEX(nvmem_cell_mutex);
>   static LIST_HEAD(nvmem_cell_tables);
>   
> +static DEFINE_MUTEX(nvmem_lookup_mutex);
> +static LIST_HEAD(nvmem_lookup_list);
> +
>   static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
>   
>   #ifdef CONFIG_DEBUG_LOCK_ALLOC
> @@ -285,6 +288,18 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>   	return to_nvmem_device(d);
>   }
>   
> +static struct nvmem_device *nvmem_find(const char *name)
> +{
> +	struct device *d;
> +
> +	d = bus_find_device_by_name(&nvmem_bus_type, NULL, name);
> +
> +	if (!d)
> +		return NULL;
> +
> +	return to_nvmem_device(d);
> +}
> +
This is removed and added back in same patch, you should consider 
positioning the caller if possible to avoid any un-necessary changes.

>   static void nvmem_cell_drop(struct nvmem_cell *cell)
>   {
>   	mutex_lock(&nvmem_mutex);
> @@ -421,6 +436,21 @@ nvmem_find_cell_by_index(struct nvmem_device *nvmem, int index)
>   	return cell;
>   }
>   
> +static struct nvmem_cell *
> +nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
> +{
> +	struct nvmem_cell *cell = ERR_PTR(-ENOENT);
> +	struct nvmem_cell_lookup *lookup;
> +	struct nvmem_device *nvmem;
> +	const char *dev_id;
> +
> +	if (!dev)
> +		return ERR_PTR(-EINVAL);
> +
> +	dev_id = dev_name(dev);
> +
> +	mutex_lock(&nvmem_lookup_mutex);
> +
> +	list_for_each_entry(lookup, &nvmem_lookup_list, node) {
> +		if ((strcmp(lookup->dev_id, dev_id) == 0) &&
> +		    (strcmp(lookup->con_id, con_id) == 0)) {
> +			/* This is the right entry. */
> +			nvmem = __nvmem_device_get(NULL, lookup->nvmem_name);
> +			if (!nvmem) {
> +				/* Provider may not be registered yet. */
> +				cell = ERR_PTR(-EPROBE_DEFER);
> +				goto out;
> +			}
> +
> +			cell = nvmem_find_cell_by_name(nvmem,
> +						       lookup->cell_name);
> +			if (!cell)
> +				goto out;
Here nvmem refcount has already increased, you should probably fix this!
> +		}
> +	}
> +
> +out:
> +	mutex_unlock(&nvmem_lookup_mutex);
> +	return cell;
> +}

...

> diff --git a/include/linux/nvmem-machine.h b/include/linux/nvmem-machine.h

Should be part of nvmem-consumer.h.

> index 1e199dfaacab..7859c08934d5 100644
> --- a/include/linux/nvmem-machine.h
> +++ b/include/linux/nvmem-machine.h
> @@ -26,16 +26,32 @@ struct nvmem_cell_table {
>   	struct list_head	node;
>   };
>   
> +struct nvmem_cell_lookup {
> +	const char		*nvmem_name;
> +	const char		*cell_name;
> +	const char		*dev_id;
> +	const char		*con_id;
> +	struct list_head	node;
> +};

Consider adding kerneldoc to this structure.

> +
>   #if IS_ENABLED(CONFIG_NVMEM)
>   
>   void nvmem_add_cell_table(struct nvmem_cell_table *table);
>   void nvmem_del_cell_table(struct nvmem_cell_table *table);
>   
> +void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries);
> +void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries);
> +
>   #else /* CONFIG_NVMEM */
>   
>   static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
>   static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
>   
> +static inline void
> +nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
> +static inline void
> +nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
> +
>   #endif /* CONFIG_NVMEM */
>   
>   #endif  /* ifndef _LINUX_NVMEM_MACHINE_H */
> 

  reply	other threads:[~2018-09-10  7:32 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-07 10:07 [PATCH v2 00/16] nvmem: rework of the subsystem for non-DT users Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 01/16] nvmem: remove unused APIs Bartosz Golaszewski
2018-09-10  7:32   ` Srinivas Kandagatla
2018-09-10  7:58     ` Bartosz Golaszewski
2018-09-10  8:09       ` Srinivas Kandagatla
2018-09-10  8:43         ` Bartosz Golaszewski
2018-09-10  9:55           ` Srinivas Kandagatla
2018-09-10 11:31             ` Bartosz Golaszewski
2018-09-10 11:47               ` Srinivas Kandagatla
2018-09-10 12:18                 ` Boris Brezillon
2018-09-10 12:22                   ` Bartosz Golaszewski
2018-09-10 13:23                     ` Srinivas Kandagatla
2018-09-07 10:07 ` [PATCH v2 02/16] nvmem: remove the global cell list Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 03/16] nvmem: use kref Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 04/16] nvmem: lpc18xx_eeprom: use devm_nvmem_register() Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 05/16] nvmem: sunxi_sid: " Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 06/16] nvmem: mxs-ocotp: " Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 07/16] nvmem: change the signature of nvmem_unregister() Bartosz Golaszewski
2018-09-10  7:33   ` Srinivas Kandagatla
2018-09-07 10:07 ` [PATCH v2 08/16] nvmem: provide nvmem_dev_name() Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 09/16] nvmem: remove the name field from struct nvmem_device Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 10/16] nvmem: add a notifier chain Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 11/16] nvmem: add support for cell info Bartosz Golaszewski
2018-09-10  7:32   ` Srinivas Kandagatla
2018-09-10  7:36     ` Boris Brezillon
2018-09-10  8:53       ` Srinivas Kandagatla
2018-09-07 10:07 ` [PATCH v2 12/16] nvmem: resolve cells from DT at registration time Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 13/16] nvmem: add support for cell lookups from machine code Bartosz Golaszewski
2018-09-10  7:32   ` Srinivas Kandagatla [this message]
2018-09-10  8:17     ` Bartosz Golaszewski
2018-09-10  8:23       ` Boris Brezillon
2018-09-10  8:55         ` Srinivas Kandagatla
2018-09-10  9:45           ` Bartosz Golaszewski
2018-09-10  9:49             ` Boris Brezillon
2018-09-10  9:50             ` Srinivas Kandagatla
2018-09-10 11:26               ` Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 14/16] Documentation: nvmem: document cell tables and lookup entries Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 15/16] nvmem: use SPDX license identifiers Bartosz Golaszewski
2018-09-07 10:07 ` [PATCH v2 16/16] nvmem: make the naming of arguments in nvmem_cell_get() consistent Bartosz Golaszewski
2018-09-10  7:54 ` [PATCH v2 00/16] nvmem: rework of the subsystem for non-DT users Srinivas Kandagatla
2018-09-10  8:24   ` Bartosz Golaszewski
2018-09-10 10:02     ` Srinivas Kandagatla
2018-09-10 14:58       ` Bartosz Golaszewski

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=484b6ec5-cd8e-e5c5-0c5c-2f11c504ea1c@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=akpm@linux-foundation.org \
    --cc=albeu@free.fr \
    --cc=andrew@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=bgolaszewski@baylibre.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=brgl@bgdev.pl \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=david@lechnology.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=khilman@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.ripard@bootlin.com \
    --cc=mchehab+samsung@kernel.org \
    --cc=nsekhar@ti.com \
    --cc=wens@csie.org \
    /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;
as well as URLs for NNTP newsgroup(s).