[PATCH 3/4] Provide per-file private data for bin sysfs files

From: Thomas Schlichter
Date: Sat Oct 17 2009 - 06:39:11 EST


For binary sysfs files, provide a per-file private field in struct bin_buffer.
To be easily accessible, it is located on head of the struct. Additionally add
a release() callback that may be used to e.g. free the private data on file
release.

Signed-off-by: Thomas Schlichter <thomas.schlichter@xxxxxx>
---
fs/sysfs/bin.c | 10 +++++++++-
include/linux/sysfs.h | 3 +++
2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index 60c702b..c0575a3 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -37,6 +37,7 @@
static DEFINE_MUTEX(sysfs_bin_lock);

struct bin_buffer {
+ void *private;
struct mutex mutex;
void *buffer;
int mmapped;
@@ -438,14 +439,21 @@ static int open(struct inode * inode, struct file * file)
static int release(struct inode * inode, struct file * file)
{
struct bin_buffer *bb = file->private_data;
+ struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
+ struct bin_attribute *attr = attr_sd->s_bin_attr.bin_attr;
+ struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
+ int rc = 0;

+ if (attr->release)
+ rc = attr->release(kobj, attr, file);
+
mutex_lock(&sysfs_bin_lock);
hlist_del(&bb->list);
mutex_unlock(&sysfs_bin_lock);

kfree(bb->buffer);
kfree(bb);
- return 0;
+ return rc;
}

const struct file_operations bin_fops = {
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 9d68fed..751ea68 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -19,6 +19,7 @@

struct kobject;
struct module;
+struct file;

/* FIXME
* The *owner field is no longer used.
@@ -72,6 +73,8 @@ struct bin_attribute {
char *, loff_t, size_t);
int (*mmap)(struct kobject *, struct bin_attribute *attr,
struct vm_area_struct *vma);
+ int (*release)(struct kobject *, struct bin_attribute *attr,
+ struct file *file);
};

struct sysfs_ops {
--
1.6.5.1


--Boundary-00=_sVh3KtzLMtBveK/--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/