[PATCH 5/9] cdev: allow to open a struct cdev
Sascha Hauer
s.hauer at pengutronix.de
Wed Jul 10 06:52:04 EDT 2013
cdev_open() opens a cdev by name. This introduces cdev_do_open which
allows to open a cdev when the cdev is already found by other means.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
fs/devfs-core.c | 16 +++++++++++-----
include/driver.h | 1 +
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index a2bea93..816f244 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -70,6 +70,14 @@ int cdev_find_free_index(const char *basename)
return -EBUSY; /* all indexes are used */
}
+int cdev_do_open(struct cdev *cdev, unsigned long flags)
+{
+ if (cdev->ops->open)
+ return cdev->ops->open(cdev, flags);
+
+ return 0;
+}
+
struct cdev *cdev_open(const char *name, unsigned long flags)
{
struct cdev *cdev = cdev_by_name(name);
@@ -78,11 +86,9 @@ struct cdev *cdev_open(const char *name, unsigned long flags)
if (!cdev)
return NULL;
- if (cdev->ops->open) {
- ret = cdev->ops->open(cdev, flags);
- if (ret)
- return NULL;
- }
+ ret = cdev_do_open(cdev, flags);
+ if (ret)
+ return NULL;
return cdev;
}
diff --git a/include/driver.h b/include/driver.h
index 353af3a..7ac2eef 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -460,6 +460,7 @@ int devfs_remove(struct cdev *);
int cdev_find_free_index(const char *);
struct cdev *cdev_by_name(const char *filename);
struct cdev *cdev_open(const char *name, unsigned long flags);
+int cdev_do_open(struct cdev *, unsigned long flags);
void 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);
--
1.8.3.2
More information about the barebox
mailing list