summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2024-02-15 08:47:51 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-02-16 12:04:42 +0100
commitd84c3daf13145dacced3f32e56ef006e824059c5 (patch)
treef11bc7a4f0929ecc04f3b0decd2f07c6c9dd3640
parent1db4fae6e97cbd57f10e179daa2f65dd34566113 (diff)
downloadbarebox-d84c3daf1314.tar.gz
barebox-d84c3daf1314.tar.xz
fs: move cdev open count to cdev_open()/cdev_close()
All code opening a cdev goes through cdev_open(), so open counting must be done there and not in devfs_open() which itself only calls cdev_open(). Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20240215074757.960200-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--fs/devfs-core.c13
-rw-r--r--fs/devfs.c4
2 files changed, 11 insertions, 6 deletions
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index c7187e3c01..87d4591d99 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -175,8 +175,15 @@ int cdev_find_free_index(const char *basename)
int cdev_open(struct cdev *cdev, unsigned long flags)
{
- if (cdev->ops->open)
- return cdev->ops->open(cdev, flags);
+ int ret;
+
+ if (cdev->ops->open) {
+ ret = cdev->ops->open(cdev, flags);
+ if (ret)
+ return ret;
+ }
+
+ cdev->open++;
return 0;
}
@@ -221,6 +228,8 @@ void cdev_close(struct cdev *cdev)
{
if (cdev->ops->close)
cdev->ops->close(cdev);
+
+ cdev->open--;
}
ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
diff --git a/fs/devfs.c b/fs/devfs.c
index c30ae4f384..c8ddbbdab0 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -114,8 +114,6 @@ static int devfs_open(struct device *_dev, FILE *f, const char *filename)
return ret;
}
- cdev->open++;
-
return 0;
}
@@ -130,8 +128,6 @@ static int devfs_close(struct device *_dev, FILE *f)
return ret;
}
- cdev->open--;
-
return 0;
}