From: srini@kernel.org
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Loic Poulain <loic.poulain@oss.qualcomm.com>,
Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH 02/14] nvmem: return -EOPNOTSUPP to in-kernel users on missing callbacks
Date: Wed, 29 Jul 2026 10:46:35 +0100 [thread overview]
Message-ID: <20260729094647.111468-3-srini@kernel.org> (raw)
In-Reply-To: <20260729094647.111468-1-srini@kernel.org>
From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
__nvmem_reg_read/write() currently return -EINVAL if the relevant
callback is not present. User-space helpers again check the presence
of the callbacks to see if they should return -EPERM.
Ahead of adding SRCU synchronization: change the error code returned to
in-kernel users to -EOPNOTSUPP which is more indicative of the actual
reason for the failure.
Remove the checks from the sysfs attribute callbacks as these are not
visible without the required callbacks.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Tested-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
drivers/nvmem/core.c | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 703f760ad35e..ea17374209ba 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -55,10 +55,10 @@ static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
void *val, size_t bytes)
{
- if (nvmem->reg_read)
- return nvmem->reg_read(nvmem->priv, offset, val, bytes);
+ if (!nvmem->reg_read)
+ return -EOPNOTSUPP;
- return -EINVAL;
+ return nvmem->reg_read(nvmem->priv, offset, val, bytes);
}
static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
@@ -66,14 +66,14 @@ static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
{
int ret;
- if (nvmem->reg_write) {
- 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);
- return ret;
- }
+ if (!nvmem->reg_write)
+ return -EOPNOTSUPP;
+
+ 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);
- return -EINVAL;
+ return ret;
}
static int nvmem_access_with_keepouts(struct nvmem_device *nvmem,
@@ -231,13 +231,12 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
count = round_down(count, nvmem->word_size);
- if (!nvmem->reg_read)
- return -EPERM;
-
rc = nvmem_reg_read(nvmem, pos, buf, count);
-
- if (rc)
+ if (rc) {
+ if (rc == -EOPNOTSUPP)
+ return -EPERM;
return rc;
+ }
return count;
}
@@ -264,13 +263,15 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
count = round_down(count, nvmem->word_size);
- if (!nvmem->reg_write || nvmem->read_only)
+ if (nvmem->read_only)
return -EPERM;
rc = nvmem_reg_write(nvmem, pos, buf, count);
-
- if (rc)
+ if (rc) {
+ if (rc == -EOPNOTSUPP)
+ return -EPERM;
return rc;
+ }
return count;
}
--
2.53.0
next prev parent reply other threads:[~2026-07-29 9:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 9:46 [PATCH 00/14] nvmem: updates for 7.3 srini
2026-07-29 9:46 ` [PATCH 01/14] nvmem: remove unused field from struct nvmem_device srini
2026-07-29 9:46 ` srini [this message]
2026-07-29 9:46 ` [PATCH 03/14] nvmem: check the return value of gpiod_set_value_cansleep() srini
2026-07-29 9:46 ` [PATCH 04/14] nvmem: simplify locking with guard() srini
2026-07-29 9:46 ` [PATCH 05/14] nvmem: remove unneeded __nvmem_device_put() srini
2026-07-29 9:46 ` [PATCH 06/14] nvmem: split out the reg_read/write() callbacks out of struct nvmem_device srini
2026-07-29 9:46 ` [PATCH 07/14] nvmem: simplify nvmem_sysfs_remove_compat() srini
2026-07-29 9:46 ` [PATCH 08/14] nvmem: remove duplicated reference counting srini
2026-07-29 9:46 ` [PATCH 09/14] nvmem: protect nvmem_device::ops with SRCU srini
2026-07-29 9:46 ` [PATCH 10/14] eeprom: move nvmem EEPROM drivers to drivers/nvmem/ srini
2026-07-29 9:46 ` [PATCH 11/14] nvmem: airoha: add ARM64 dependency srini
2026-07-29 9:46 ` [PATCH 12/14] nvmem: brcm_nvram: reject empty NVRAM partition srini
2026-07-29 9:46 ` [PATCH 13/14] nvmem: brcm_nvram: fix out-of-bounds access on malformed flash data srini
2026-07-29 9:46 ` [PATCH 14/14] dt-bindings: nvmem: qfprom: Add ipq5210 & ipq9650 compatible srini
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=20260729094647.111468-3-srini@kernel.org \
--to=srini@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
/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