Skip to content

Commit daefd7f

Browse files
t-8chlag-linaro
authored andcommitted
leds: triggers: 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]> Link: https://lore.kernel.org/r/20241222-sysfs-const-bin_attr-led-v1-1-ecc5212a31fa@weissschuh.net Signed-off-by: Lee Jones <[email protected]>
1 parent 417cad5 commit daefd7f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

drivers/leds/led-class.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ static ssize_t max_brightness_show(struct device *dev,
8585
static DEVICE_ATTR_RO(max_brightness);
8686

8787
#ifdef CONFIG_LEDS_TRIGGERS
88-
static BIN_ATTR(trigger, 0644, led_trigger_read, led_trigger_write, 0);
89-
static struct bin_attribute *led_trigger_bin_attrs[] = {
88+
static const BIN_ATTR(trigger, 0644, led_trigger_read, led_trigger_write, 0);
89+
static const struct bin_attribute *const led_trigger_bin_attrs[] = {
9090
&bin_attr_trigger,
9191
NULL,
9292
};
9393
static const struct attribute_group led_trigger_group = {
94-
.bin_attrs = led_trigger_bin_attrs,
94+
.bin_attrs_new = led_trigger_bin_attrs,
9595
};
9696
#endif
9797

drivers/leds/led-triggers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig)
3434
}
3535

3636
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
37-
struct bin_attribute *bin_attr, char *buf,
37+
const struct bin_attribute *bin_attr, char *buf,
3838
loff_t pos, size_t count)
3939
{
4040
struct device *dev = kobj_to_dev(kobj);
@@ -123,7 +123,7 @@ static int led_trigger_format(char *buf, size_t size,
123123
* copy it.
124124
*/
125125
ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
126-
struct bin_attribute *attr, char *buf,
126+
const struct bin_attribute *attr, char *buf,
127127
loff_t pos, size_t count)
128128
{
129129
struct device *dev = kobj_to_dev(kobj);

drivers/leds/leds.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ void led_stop_software_blink(struct led_classdev *led_cdev);
2222
void led_set_brightness_nopm(struct led_classdev *led_cdev, unsigned int value);
2323
void led_set_brightness_nosleep(struct led_classdev *led_cdev, unsigned int value);
2424
ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
25-
struct bin_attribute *attr, char *buf,
25+
const struct bin_attribute *attr, char *buf,
2626
loff_t pos, size_t count);
2727
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
28-
struct bin_attribute *bin_attr, char *buf,
28+
const struct bin_attribute *bin_attr, char *buf,
2929
loff_t pos, size_t count);
3030

3131
extern struct rw_semaphore leds_list_lock;

0 commit comments

Comments
 (0)