From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] nvmem: make id optional for of_nvmem_device_get()
Date: Mon, 18 Jan 2021 21:55:28 +0100 [thread overview]
Message-ID: <20210118205528.9797-4-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20210118205528.9797-1-m.felsch@pengutronix.de>
Port upstream linux commit
8<----------------------------------------------------------------------
commit d4e7fef1a9a5d2bf3f859ba9f50f4d5409a09ab0
Author: Alban Bedel <albeu@free.fr>
Date: Mon Jan 28 15:55:03 2019 +0000
nvmem: core: Properly handle connection ID in of_nvmem_device_get()
of_nvmem_device_get() would crash if NULL was passed as a connection
ID. Rework this to use the usual sementic of assuming the first
connection when no connection ID is given.
Furthermore of_nvmem_device_get() would return -EINVAL when it failed
to resolve the connection, making it impossible to properly implement
an optional connection. Return -ENOENT instead to let the caller know
that the connection doesn't exists.
Signed-off-by: Alban Bedel <albeu@free.fr>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8<----------------------------------------------------------------------
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/nvmem/core.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index b9af31f4b5..9b55f47b4c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -284,13 +284,14 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
{
struct device_node *nvmem_np;
- int index;
+ int index = 0;
- index = of_property_match_string(np, "nvmem-names", id);
+ if (id)
+ index = of_property_match_string(np, "nvmem-names", id);
nvmem_np = of_parse_phandle(np, "nvmem", index);
if (!nvmem_np)
- return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOENT);
return __nvmem_device_get(nvmem_np, NULL, NULL);
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-01-18 20:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-18 20:55 [PATCH 1/4] nvmem: sync stub return values with linux code Marco Felsch
2021-01-18 20:55 ` [PATCH 2/4] nvmem: add missing stubs Marco Felsch
2021-01-18 20:55 ` [PATCH 3/4] nvmem: make nvmem_device_write/read public Marco Felsch
2021-01-18 20:55 ` Marco Felsch [this message]
2021-01-19 10:15 ` [PATCH 1/4] nvmem: sync stub return values with linux code Sascha Hauer
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=20210118205528.9797-4-m.felsch@pengutronix.de \
--to=m.felsch@pengutronix.de \
--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