Skip to content

Commit e2c9e61

Browse files
t-8chakpm00
authored andcommitted
mm/page_idle: 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. Link: https://lkml.kernel.org/r/20241216-sysfs-const-bin_attr-page_idle-v1-1-cc01ecc55196@weissschuh.net Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1fc1065 commit e2c9e61

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mm/page_idle.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void page_idle_clear_pte_refs(struct folio *folio)
112112
}
113113

114114
static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj,
115-
struct bin_attribute *attr, char *buf,
115+
const struct bin_attribute *attr, char *buf,
116116
loff_t pos, size_t count)
117117
{
118118
u64 *out = (u64 *)buf;
@@ -157,7 +157,7 @@ static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj,
157157
}
158158

159159
static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj,
160-
struct bin_attribute *attr, char *buf,
160+
const struct bin_attribute *attr, char *buf,
161161
loff_t pos, size_t count)
162162
{
163163
const u64 *in = (u64 *)buf;
@@ -193,17 +193,17 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj,
193193
return (char *)in - buf;
194194
}
195195

196-
static struct bin_attribute page_idle_bitmap_attr =
196+
static const struct bin_attribute page_idle_bitmap_attr =
197197
__BIN_ATTR(bitmap, 0600,
198198
page_idle_bitmap_read, page_idle_bitmap_write, 0);
199199

200-
static struct bin_attribute *page_idle_bin_attrs[] = {
200+
static const struct bin_attribute *const page_idle_bin_attrs[] = {
201201
&page_idle_bitmap_attr,
202202
NULL,
203203
};
204204

205205
static const struct attribute_group page_idle_attr_group = {
206-
.bin_attrs = page_idle_bin_attrs,
206+
.bin_attrs_new = page_idle_bin_attrs,
207207
.name = "page_idle",
208208
};
209209

0 commit comments

Comments
 (0)