[PATCH master 1/3] cdev: return error code from cdev_close
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed May 15 01:05:05 PDT 2024
cdev_operations::close can fail and thus cdev_close should pass along
the error code to the users instead of discarding it.
Do that, so users like devfs close() can start propagating this error.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
fs/devfs-core.c | 11 ++++++++---
include/driver.h | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 376c62be9eab..21e5c2dc969a 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -224,12 +224,17 @@ struct cdev *cdev_open_by_name(const char *name, unsigned long flags)
return cdev;
}
-void cdev_close(struct cdev *cdev)
+int cdev_close(struct cdev *cdev)
{
- if (cdev->ops->close)
- cdev->ops->close(cdev);
+ if (cdev->ops->close) {
+ int ret = cdev->ops->close(cdev);
+ if (ret)
+ return ret;
+ }
cdev->open--;
+
+ return 0;
}
ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
diff --git a/include/driver.h b/include/driver.h
index 5a3e46e99e14..3401ab4f07f4 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -529,7 +529,7 @@ struct cdev *cdev_create_loop(const char *path, ulong flags, loff_t offset);
void cdev_remove_loop(struct cdev *cdev);
int cdev_open(struct cdev *, unsigned long flags);
int cdev_fdopen(struct cdev *cdev, unsigned long flags);
-void cdev_close(struct cdev *cdev);
+int cdev_close(struct cdev *cdev);
int cdev_flush(struct cdev *cdev);
ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags);
ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags);
--
2.39.2
More information about the barebox
mailing list