mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] nvmem: Fix read/write access to partition devices
@ 2019-09-27  8:34 Stefan Riedmueller
  2019-09-30 18:38 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Riedmueller @ 2019-09-27  8:34 UTC (permalink / raw)
  To: barebox

Partition devices are not directly associated with the nvmem instance but via
their master cdev. Thus reading and writing needs to be handled via the
master.

Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 drivers/nvmem/core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 25924872efa2..82e9d1996428 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -57,9 +57,14 @@ int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
 static ssize_t nvmem_cdev_read(struct cdev *cdev, void *buf, size_t count,
 			       loff_t offset, unsigned long flags)
 {
-	struct nvmem_device *nvmem = container_of(cdev, struct nvmem_device, cdev);
+	struct nvmem_device *nvmem;
 	ssize_t retlen;
 
+	if (!cdev->master)
+		nvmem = container_of(cdev, struct nvmem_device, cdev);
+	else
+		nvmem = container_of(cdev->master, struct nvmem_device, cdev);
+
 	dev_dbg(cdev->dev, "read ofs: 0x%08llx count: 0x%08zx\n",
 		offset, count);
 
@@ -71,9 +76,14 @@ static ssize_t nvmem_cdev_read(struct cdev *cdev, void *buf, size_t count,
 static ssize_t nvmem_cdev_write(struct cdev *cdev, const void *buf, size_t count,
 				loff_t offset, unsigned long flags)
 {
-	struct nvmem_device *nvmem = container_of(cdev, struct nvmem_device, cdev);
+	struct nvmem_device *nvmem;
 	ssize_t retlen;
 
+	if (!cdev->master)
+		nvmem = container_of(cdev, struct nvmem_device, cdev);
+	else
+		nvmem = container_of(cdev->master, struct nvmem_device, cdev);
+
 	dev_dbg(cdev->dev, "write ofs: 0x%08llx count: 0x%08zx\n",
 		offset, count);
 
-- 
2.7.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-09-30 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27  8:34 [PATCH] nvmem: Fix read/write access to partition devices Stefan Riedmueller
2019-09-30 18:38 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox