Skip to content

Commit 943e5f8

Browse files
t-8chPratyush Yadav
authored andcommitted
mtd: spi-nor: sysfs: constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh <[email protected]> Acked-by: Pratyush Yadav <[email protected]> Signed-off-by: Pratyush Yadav <[email protected]> Link: https://lore.kernel.org/r/20241222-sysfs-const-bin_attr-mtd-v1-1-ee13140a4e9b@weissschuh.net
1 parent b239cbc commit 943e5f8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/mtd/spi-nor/sysfs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static struct attribute *spi_nor_sysfs_entries[] = {
5050
};
5151

5252
static ssize_t sfdp_read(struct file *filp, struct kobject *kobj,
53-
struct bin_attribute *bin_attr, char *buf,
53+
const struct bin_attribute *bin_attr, char *buf,
5454
loff_t off, size_t count)
5555
{
5656
struct spi_device *spi = to_spi_device(kobj_to_dev(kobj));
@@ -62,9 +62,9 @@ static ssize_t sfdp_read(struct file *filp, struct kobject *kobj,
6262
return memory_read_from_buffer(buf, count, &off, nor->sfdp->dwords,
6363
sfdp_size);
6464
}
65-
static BIN_ATTR_RO(sfdp, 0);
65+
static const BIN_ATTR_RO(sfdp, 0);
6666

67-
static struct bin_attribute *spi_nor_sysfs_bin_entries[] = {
67+
static const struct bin_attribute *const spi_nor_sysfs_bin_entries[] = {
6868
&bin_attr_sfdp,
6969
NULL
7070
};
@@ -104,7 +104,7 @@ static const struct attribute_group spi_nor_sysfs_group = {
104104
.is_visible = spi_nor_sysfs_is_visible,
105105
.is_bin_visible = spi_nor_sysfs_is_bin_visible,
106106
.attrs = spi_nor_sysfs_entries,
107-
.bin_attrs = spi_nor_sysfs_bin_entries,
107+
.bin_attrs_new = spi_nor_sysfs_bin_entries,
108108
};
109109

110110
const struct attribute_group *spi_nor_sysfs_groups[] = {

0 commit comments

Comments
 (0)