From: Joy Chakraborty <joychakr@google.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Dan Carpenter <dan.carpenter@linaro.org>
Cc: linux-kernel@vger.kernel.org, Joy Chakraborty <joychakr@google.com>
Subject: [PATCH] nvmem: core: WARN_ONCE on nvmem reg_read/write() returning positive values
Date: Thu, 25 Jul 2024 11:21:26 +0000 [thread overview]
Message-ID: <20240725112126.415071-1-joychakr@google.com> (raw)
Nvmem core currently expects 0 to be returned on successful read/write
and negative for failure from nvmem producers.
Warn incase any nvmem producer returns positive values which might
happen if any producer ends up returning the number of bytes read or
written.
Signed-off-by: Joy Chakraborty <joychakr@google.com>
---
drivers/nvmem/core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index e1ec3b7200d7..0a42e6a0e8bb 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -58,10 +58,13 @@ static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
void *val, size_t bytes)
{
+ int ret = -EINVAL;
+
if (nvmem->reg_read)
- return nvmem->reg_read(nvmem->priv, offset, val, bytes);
+ ret = nvmem->reg_read(nvmem->priv, offset, val, bytes);
- return -EINVAL;
+ WARN_ONCE(ret > 0, "nvmem reg_read should not return positive value, please return 0 on success");
+ return ret;
}
static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
@@ -73,6 +76,7 @@ static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
ret = nvmem->reg_write(nvmem->priv, offset, val, bytes);
gpiod_set_value_cansleep(nvmem->wp_gpio, 1);
+ WARN_ONCE(ret > 0, "nvmem reg_write should not return positive value, please return 0 on success");
return ret;
}
--
2.45.2.1089.g2a221341d9-goog
next reply other threads:[~2024-07-25 11:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-25 11:21 Joy Chakraborty [this message]
2024-07-25 17:48 ` Dan Carpenter
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=20240725112126.415071-1-joychakr@google.com \
--to=joychakr@google.com \
--cc=dan.carpenter@linaro.org \
--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
all inboxes | Powered by JetHome®