linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmem: ensure sysfs writes handle write-protect pin
@ 2020-04-27 18:39 Michael Auchter
  2020-04-28 11:55 ` Srinivas Kandagatla
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Auchter @ 2020-04-27 18:39 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: Khouloud Touil, Michael Auchter, linux-kernel

Commit 2a127da461a9d8d97782d6e82b227041393eb4d2 added support for
handling write-protect pins to the nvmem core, and commit
1c89074bf85068d1b86f2e0f0c2110fdd9b83c9f retrofitted the at24 driver to
use this support.

These changes broke write() on the nvmem sysfs attribute for eeproms
which utilize a write-protect pin, as the write callback invokes the
nvmem device's reg_write callback directly which no longer handles
changing the state of the write-protect pin.

Change the read and write callbacks for the sysfs attribute to invoke
nvmme_reg_read/nvmem_reg_write helpers which handle this, rather than
calling reg_read/reg_write directly.

Signed-off-by: Michael Auchter <michael.auchter@ni.com>
---
 drivers/nvmem/core.c | 52 ++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 05c6ae4b0b97..a8300202a7fb 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -66,6 +66,30 @@ static LIST_HEAD(nvmem_lookup_list);
 
 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);
+
+	return -EINVAL;
+}
+
+static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
+			   void *val, size_t bytes)
+{
+	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;
+	}
+
+	return -EINVAL;
+}
+
 #ifdef CONFIG_NVMEM_SYSFS
 static const char * const nvmem_type_str[] = {
 	[NVMEM_TYPE_UNKNOWN] = "Unknown",
@@ -122,7 +146,7 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
 	if (!nvmem->reg_read)
 		return -EPERM;
 
-	rc = nvmem->reg_read(nvmem->priv, pos, buf, count);
+	rc = nvmem_reg_read(nvmem, pos, buf, count);
 
 	if (rc)
 		return rc;
@@ -159,7 +183,7 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
 	if (!nvmem->reg_write)
 		return -EPERM;
 
-	rc = nvmem->reg_write(nvmem->priv, pos, buf, count);
+	rc = nvmem_reg_write(nvmem, pos, buf, count);
 
 	if (rc)
 		return rc;
@@ -311,30 +335,6 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem,
 
 #endif /* CONFIG_NVMEM_SYSFS */
 
-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);
-
-	return -EINVAL;
-}
-
-static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
-			   void *val, size_t bytes)
-{
-	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;
-	}
-
-	return -EINVAL;
-}
-
 static void nvmem_release(struct device *dev)
 {
 	struct nvmem_device *nvmem = to_nvmem_device(dev);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvmem: ensure sysfs writes handle write-protect pin
  2020-04-27 18:39 [PATCH] nvmem: ensure sysfs writes handle write-protect pin Michael Auchter
@ 2020-04-28 11:55 ` Srinivas Kandagatla
  0 siblings, 0 replies; 2+ messages in thread
From: Srinivas Kandagatla @ 2020-04-28 11:55 UTC (permalink / raw)
  To: Michael Auchter; +Cc: Khouloud Touil, linux-kernel



On 27/04/2020 19:39, Michael Auchter wrote:
> Commit 2a127da461a9d8d97782d6e82b227041393eb4d2 added support for
> handling write-protect pins to the nvmem core, and commit
> 1c89074bf85068d1b86f2e0f0c2110fdd9b83c9f retrofitted the at24 driver to
> use this support.
> 
> These changes broke write() on the nvmem sysfs attribute for eeproms
> which utilize a write-protect pin, as the write callback invokes the
> nvmem device's reg_write callback directly which no longer handles
> changing the state of the write-protect pin.
> 
> Change the read and write callbacks for the sysfs attribute to invoke
> nvmme_reg_read/nvmem_reg_write helpers which handle this, rather than
> calling reg_read/reg_write directly.
> 
> Signed-off-by: Michael Auchter <michael.auchter@ni.com>
> ---
>   drivers/nvmem/core.c | 52 ++++++++++++++++++++++----------------------
>   1 file changed, 26 insertions(+), 26 deletions(-)
> 

Applied fixes tag:
  Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")


--srini

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-28 11:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 18:39 [PATCH] nvmem: ensure sysfs writes handle write-protect pin Michael Auchter
2020-04-28 11:55 ` Srinivas Kandagatla

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).