linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alban Bedel <albeu@free.fr>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: linux-kernel@vger.kernel.org, Alban Bedel <albeu@free.fr>
Subject: [PATCH 5/8] nvmem: core: Properly handle connection ID in of_nvmem_device_get()
Date: Sun,  6 Jan 2019 20:28:17 +0100	[thread overview]
Message-ID: <20190106192820.12558-6-albeu@free.fr> (raw)
In-Reply-To: <20190106192820.12558-1-albeu@free.fr>

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>
---
 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 a7556b20cff4..28e01a9876c6 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -839,13 +839,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);
 }
-- 
2.19.1


  parent reply	other threads:[~2019-01-06 19:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-06 19:28 [PATCH 0/8] nvmem: Various small fixes and improvements Alban Bedel
2019-01-06 19:28 ` [PATCH 1/8] nvmem: core: Set the provider read-only when no write callback is given Alban Bedel
2019-01-06 19:28 ` [PATCH 2/8] nvmem: core: Fix of_nvmem_cell_get() for optional cells Alban Bedel
2019-01-06 19:28 ` [PATCH 3/8] nvmem: Add nvmem_cell_get_optional and devm_nvmem_cell_get_optional Alban Bedel
2019-01-15 12:40   ` Srinivas Kandagatla
2019-01-16 18:26     ` Alban
2019-01-17 10:20       ` Srinivas Kandagatla
2019-01-06 19:28 ` [PATCH 4/8] nvmem: core: Fix cell lookup when no cell is found Alban Bedel
2019-01-06 19:28 ` Alban Bedel [this message]
2019-01-06 19:28 ` [PATCH 6/8] nvmem: core: Always reference the device returned by nvmem_device_get() Alban Bedel
2019-01-06 19:28 ` [PATCH 7/8] nvmem: core: Fix device reference leak Alban Bedel
2019-01-06 19:28 ` [PATCH 8/8] nvmem: core: Avoid useless iterations in nvmem_cell_get_from_lookup() Alban Bedel
2019-01-15 12:40 ` [PATCH 0/8] nvmem: Various small fixes and improvements Srinivas Kandagatla

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=20190106192820.12558-6-albeu@free.fr \
    --to=albeu@free.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srinivas.kandagatla@linaro.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).