summaryrefslogtreecommitdiff
path: root/fs/sysfs
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2024-11-03 17:03:38 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-11-05 14:00:28 +0100
commiteb2e6c3a8d66ff37b2ee26cd32334ae0e05fd596 (patch)
tree72b99b7824ff5928bb6ea7bc29f7139c4736a1fd /fs/sysfs
parentae587a509903cca138e910445d8c21fe73b45c80 (diff)
sysfs: bin_attribute: add const read/write callback variants
To make it possible to put struct bin_attribute into read-only memory, the sysfs core has to stop passing mutable pointers to the read() and write() callbacks. As there are numerous implementors of these callbacks throughout the tree it's not possible to change all of them at once. To enable a step-by-step transition, add new variants of the read() and write() callbacks which differ only in the constness of the struct bin_attribute argument. As most binary attributes are defined through macros, extend these macros to transparently handle both variants of callbacks to minimize the churn during the transition. As soon as all handlers are switch to the const variant, the non-const one can be removed together with the transition machinery. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Krzysztof Wilczyński <kw@linux.com> Link: https://lore.kernel.org/r/20241103-sysfs-const-bin_attr-v2-9-71110628844c@weissschuh.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/file.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 6d39696b4306..785408861c01 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -91,9 +91,12 @@ static ssize_t sysfs_kf_bin_read(struct kernfs_open_file *of, char *buf,
count = size - pos;
}
- if (!battr->read)
+ if (!battr->read && !battr->read_new)
return -EIO;
+ if (battr->read_new)
+ return battr->read_new(of->file, kobj, battr, buf, pos, count);
+
return battr->read(of->file, kobj, battr, buf, pos, count);
}
@@ -152,9 +155,12 @@ static ssize_t sysfs_kf_bin_write(struct kernfs_open_file *of, char *buf,
if (!count)
return 0;
- if (!battr->write)
+ if (!battr->write && !battr->write_new)
return -EIO;
+ if (battr->write_new)
+ return battr->write_new(of->file, kobj, battr, buf, pos, count);
+
return battr->write(of->file, kobj, battr, buf, pos, count);
}
@@ -323,13 +329,19 @@ int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent,
const struct kernfs_ops *ops;
struct kernfs_node *kn;
+ if (battr->read && battr->read_new)
+ return -EINVAL;
+
+ if (battr->write && battr->write_new)
+ return -EINVAL;
+
if (battr->mmap)
ops = &sysfs_bin_kfops_mmap;
- else if (battr->read && battr->write)
+ else if ((battr->read || battr->read_new) && (battr->write || battr->write_new))
ops = &sysfs_bin_kfops_rw;
- else if (battr->read)
+ else if (battr->read || battr->read_new)
ops = &sysfs_bin_kfops_ro;
- else if (battr->write)
+ else if (battr->write || battr->write_new)
ops = &sysfs_bin_kfops_wo;
else
ops = &sysfs_file_kfops_empty;