Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bcafe4ee authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman
Browse files

sysfs: add sysfs_open_file->sd and ->file



sysfs will be converted to use seq_file for read path, which will make
it difficult to pass around multiple pointers directly.  This patch
adds sysfs_open_file->sd and ->file so that we can reach all the
necessary data structures from sysfs_open_file.

flush_write_buffer() is updated to drop @dentry which was used to
discover the sysfs_dirent as it's now available through
sysfs_open_file->sd.

This patch doesn't cause any behavior difference.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 58282d8d
Loading
Loading
Loading
Loading
+12 −11
Original line number Original line Diff line number Diff line
@@ -45,6 +45,8 @@ struct sysfs_open_dirent {
};
};


struct sysfs_open_file {
struct sysfs_open_file {
	struct sysfs_dirent	*sd;
	struct file		*file;
	size_t			count;
	size_t			count;
	char			*page;
	char			*page;
	struct mutex		mutex;
	struct mutex		mutex;
@@ -192,7 +194,6 @@ static int fill_write_buffer(struct sysfs_open_file *of,


/**
/**
 *	flush_write_buffer - push buffer to kobject.
 *	flush_write_buffer - push buffer to kobject.
 *	@dentry:	dentry to the attribute
 *	@of:		open file
 *	@of:		open file
 *	@count:		number of bytes
 *	@count:		number of bytes
 *
 *
@@ -200,22 +201,20 @@ static int fill_write_buffer(struct sysfs_open_file *of,
 *	dealing with, then call the store() method for the attribute,
 *	dealing with, then call the store() method for the attribute,
 *	passing the buffer that we acquired in fill_write_buffer().
 *	passing the buffer that we acquired in fill_write_buffer().
 */
 */
static int flush_write_buffer(struct dentry *dentry,
static int flush_write_buffer(struct sysfs_open_file *of, size_t count)
			      struct sysfs_open_file *of, size_t count)
{
{
	struct sysfs_dirent *attr_sd = dentry->d_fsdata;
	struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
	struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
	const struct sysfs_ops *ops;
	const struct sysfs_ops *ops;
	int rc;
	int rc;


	/* need attr_sd for attr and ops, its parent for kobj */
	/* need @of->sd for attr and ops, its parent for kobj */
	if (!sysfs_get_active(attr_sd))
	if (!sysfs_get_active(of->sd))
		return -ENODEV;
		return -ENODEV;


	ops = sysfs_file_ops(attr_sd);
	ops = sysfs_file_ops(of->sd);
	rc = ops->store(kobj, attr_sd->s_attr.attr, of->page, count);
	rc = ops->store(kobj, of->sd->s_attr.attr, of->page, count);


	sysfs_put_active(attr_sd);
	sysfs_put_active(of->sd);


	return rc;
	return rc;
}
}
@@ -245,7 +244,7 @@ static ssize_t sysfs_write_file(struct file *file, const char __user *buf,
	mutex_lock(&of->mutex);
	mutex_lock(&of->mutex);
	len = fill_write_buffer(of, buf, count);
	len = fill_write_buffer(of, buf, count);
	if (len > 0)
	if (len > 0)
		len = flush_write_buffer(file->f_path.dentry, of, len);
		len = flush_write_buffer(of, len);
	if (len > 0)
	if (len > 0)
		*ppos += len;
		*ppos += len;
	mutex_unlock(&of->mutex);
	mutex_unlock(&of->mutex);
@@ -385,6 +384,8 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
		goto err_out;
		goto err_out;


	mutex_init(&of->mutex);
	mutex_init(&of->mutex);
	of->sd = attr_sd;
	of->file = file;
	file->private_data = of;
	file->private_data = of;


	/* make sure we have open dirent struct */
	/* make sure we have open dirent struct */