Currently, sysfs_ops is fetched during sysfs_open_file() and cached in
sysfs_buffer->ops to be used while the file is open. This patch
removes the caching and makes each operation directly fetch sysfs_ops.
This patch doesn't introduce any behavior difference and is to prepare
for merging regular and bin file supports.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
struct sysfs_buffer {
size_t count;
char *page;
struct sysfs_buffer {
size_t count;
char *page;
- const struct sysfs_ops *ops;
struct mutex mutex;
int event;
struct list_head list;
};
struct mutex mutex;
int event;
struct list_head list;
};
+/*
+ * Determine ktype->sysfs_ops for the given sysfs_dirent. This function
+ * must be called while holding an active reference.
+ */
+static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
+{
+ struct kobject *kobj = sd->s_parent->s_dir.kobj;
+
+ lockdep_assert_held(sd);
+ return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
+}
+
/**
* fill_read_buffer - allocate and fill buffer from object.
* @dentry: dentry pointer.
/**
* fill_read_buffer - allocate and fill buffer from object.
* @dentry: dentry pointer.
{
struct sysfs_dirent *attr_sd = dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
{
struct sysfs_dirent *attr_sd = dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
- const struct sysfs_ops *ops = buffer->ops;
+ const struct sysfs_ops *ops;
int ret = 0;
ssize_t count;
int ret = 0;
ssize_t count;
return -ENODEV;
buffer->event = atomic_read(&attr_sd->s_attr.open->event);
return -ENODEV;
buffer->event = atomic_read(&attr_sd->s_attr.open->event);
+
+ ops = sysfs_file_ops(attr_sd);
count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
sysfs_put_active(attr_sd);
count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
sysfs_put_active(attr_sd);
{
struct sysfs_dirent *attr_sd = dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
{
struct sysfs_dirent *attr_sd = dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
- const struct sysfs_ops *ops = buffer->ops;
+ const struct sysfs_ops *ops;
int rc;
/* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active(attr_sd))
return -ENODEV;
int rc;
/* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active(attr_sd))
return -ENODEV;
+ ops = sysfs_file_ops(attr_sd);
rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
sysfs_put_active(attr_sd);
rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
sysfs_put_active(attr_sd);
/**
* sysfs_write_file - write an attribute.
* @file: file pointer
/**
* sysfs_write_file - write an attribute.
* @file: file pointer
return -ENODEV;
/* every kobject with an attribute needs a ktype assigned */
return -ENODEV;
/* every kobject with an attribute needs a ktype assigned */
- if (kobj->ktype && kobj->ktype->sysfs_ops)
- ops = kobj->ktype->sysfs_ops;
- else {
- WARN(1, KERN_ERR
- "missing sysfs attribute operations for kobject: %s\n",
- kobject_name(kobj));
+ ops = sysfs_file_ops(attr_sd);
+ if (WARN(!ops, KERN_ERR
+ "missing sysfs attribute operations for kobject: %s\n",
+ kobject_name(kobj)))
/* File needs write support.
* The inode's perms must say it's ok,
/* File needs write support.
* The inode's perms must say it's ok,
goto err_out;
mutex_init(&buffer->mutex);
goto err_out;
mutex_init(&buffer->mutex);
file->private_data = buffer;
/* make sure we have open dirent struct */
file->private_data = buffer;
/* make sure we have open dirent struct */