From: Lucas Stach <l.stach@pengutronix.de>
To: Andrey Smirnov <andrew.smirnov@gmail.com>, barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] nvmem: Introduce nvmem_cell_get_and_read()
Date: Wed, 27 Jun 2018 11:05:34 +0200 [thread overview]
Message-ID: <1530090334.22468.15.camel@pengutronix.de> (raw)
In-Reply-To: <20180627035842.17858-1-andrew.smirnov@gmail.com>
Am Dienstag, den 26.06.2018, 20:58 -0700 schrieb Andrey Smirnov:
> Introduce nvmem_cell_get_and_read() that combines getting a NVMEM cell
> by name and reading its contents.
>
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> drivers/nvmem/core.c | 23 +++++++++++++++++++++++
> include/linux/nvmem-consumer.h | 10 ++++++++++
> 2 files changed, 33 insertions(+)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 53b934bb3..c785de125 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -750,3 +750,26 @@ int nvmem_device_write(struct nvmem_device *nvmem,
> > return bytes;
> }
> EXPORT_SYMBOL_GPL(nvmem_device_write);
> +
> +void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
> > + size_t bytes)
> +{
> > + struct nvmem_cell *cell;
> > + void *value;
> > + size_t len;
> +
> > + cell = of_nvmem_cell_get(np, cell_name);
> > + if (IS_ERR(cell))
> > + return cell;
> +
> > + value = nvmem_cell_read(cell, &len);
> > + if (!IS_ERR(value) && len != bytes) {
> > + kfree(value);
> > + value = ERR_PTR(-EINVAL);
> > + }
> +
> > + nvmem_cell_put(cell);
> +
> > + return value;
> +}
> +EXPORT_SYMBOL_GPL(nvmem_cell_get_and_read);
> \ No newline at end of file
I'm sure you are tired by me nitpicking on this. ;)
I really like this helper, as it makes the consumer code look much
nicer, as seen in patch 2.
Regards,
Lucas
> diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
> index 606cadb49..0ec2f05b9 100644
> --- a/include/linux/nvmem-consumer.h
> +++ b/include/linux/nvmem-consumer.h
> @@ -32,6 +32,9 @@ struct nvmem_cell_info {
> struct nvmem_cell *nvmem_cell_get(struct device_d *dev, const char *name);
> void nvmem_cell_put(struct nvmem_cell *cell);
> void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
> +void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
> > + size_t bytes);
> +
> int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
>
> /* direct nvmem device read/write interface */
> @@ -55,6 +58,13 @@ static inline char *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
> > return ERR_PTR(-ENOSYS);
> }
>
> +static inline void *nvmem_cell_get_and_read(struct device_node *np,
> > + const char *cell_name,
> > + size_t bytes)
> +{
> > + return ERR_PTR(-ENOSYS);
> +}
> +
> static inline int nvmem_cell_write(struct nvmem_cell *cell,
> > const char *buf, size_t len)
> {
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-06-27 9:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-27 3:58 Andrey Smirnov
2018-06-27 3:58 ` [PATCH 2/2] ARM: rdu2: Fetch MAC address info from RAVE SP EEPROM Andrey Smirnov
2018-06-27 9:05 ` Lucas Stach [this message]
2018-06-27 16:57 ` [PATCH 1/2] nvmem: Introduce nvmem_cell_get_and_read() Andrey Smirnov
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=1530090334.22468.15.camel@pengutronix.de \
--to=l.stach@pengutronix.de \
--cc=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.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