Skip to content

Commit bf2066c

Browse files
t-8chTzung-Bi Shih
authored andcommitted
firmware: google: cbmem: 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: Brian Norris <[email protected]> Link: https://lore.kernel.org/r/20241215-sysfs-const-bin_attr-google-v1-1-e5c2808f5833@weissschuh.net Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent 40384c8 commit bf2066c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/firmware/google/cbmem.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static struct cbmem_entry *to_cbmem_entry(struct kobject *kobj)
3030
}
3131

3232
static ssize_t mem_read(struct file *filp, struct kobject *kobj,
33-
struct bin_attribute *bin_attr, char *buf, loff_t pos,
33+
const struct bin_attribute *bin_attr, char *buf, loff_t pos,
3434
size_t count)
3535
{
3636
struct cbmem_entry *entry = to_cbmem_entry(kobj);
@@ -40,7 +40,7 @@ static ssize_t mem_read(struct file *filp, struct kobject *kobj,
4040
}
4141

4242
static ssize_t mem_write(struct file *filp, struct kobject *kobj,
43-
struct bin_attribute *bin_attr, char *buf, loff_t pos,
43+
const struct bin_attribute *bin_attr, char *buf, loff_t pos,
4444
size_t count)
4545
{
4646
struct cbmem_entry *entry = to_cbmem_entry(kobj);
@@ -53,7 +53,7 @@ static ssize_t mem_write(struct file *filp, struct kobject *kobj,
5353
memcpy(entry->mem_file_buf + pos, buf, count);
5454
return count;
5555
}
56-
static BIN_ATTR_ADMIN_RW(mem, 0);
56+
static const BIN_ATTR_ADMIN_RW(mem, 0);
5757

5858
static ssize_t address_show(struct device *dev, struct device_attribute *attr,
5959
char *buf)
@@ -79,14 +79,14 @@ static struct attribute *attrs[] = {
7979
NULL,
8080
};
8181

82-
static struct bin_attribute *bin_attrs[] = {
82+
static const struct bin_attribute *const bin_attrs[] = {
8383
&bin_attr_mem,
8484
NULL,
8585
};
8686

8787
static const struct attribute_group cbmem_entry_group = {
8888
.attrs = attrs,
89-
.bin_attrs = bin_attrs,
89+
.bin_attrs_new = bin_attrs,
9090
};
9191

9292
static const struct attribute_group *dev_groups[] = {

0 commit comments

Comments
 (0)