Skip to content

Commit 3c39919

Browse files
t-8chbjorn-helgaas
authored andcommitted
PCI/VPD: 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://lore.kernel.org/r/20241202-sysfs-const-bin_attr-pci-v1-2-c32360f495a7@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 0530ad4 commit 3c39919

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/pci/vpd.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ void pci_vpd_init(struct pci_dev *dev)
271271
}
272272

273273
static ssize_t vpd_read(struct file *filp, struct kobject *kobj,
274-
struct bin_attribute *bin_attr, char *buf, loff_t off,
275-
size_t count)
274+
const struct bin_attribute *bin_attr, char *buf,
275+
loff_t off, size_t count)
276276
{
277277
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
278278
struct pci_dev *vpd_dev = dev;
@@ -295,8 +295,8 @@ static ssize_t vpd_read(struct file *filp, struct kobject *kobj,
295295
}
296296

297297
static ssize_t vpd_write(struct file *filp, struct kobject *kobj,
298-
struct bin_attribute *bin_attr, char *buf, loff_t off,
299-
size_t count)
298+
const struct bin_attribute *bin_attr, char *buf,
299+
loff_t off, size_t count)
300300
{
301301
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
302302
struct pci_dev *vpd_dev = dev;
@@ -317,9 +317,9 @@ static ssize_t vpd_write(struct file *filp, struct kobject *kobj,
317317

318318
return ret;
319319
}
320-
static BIN_ATTR(vpd, 0600, vpd_read, vpd_write, 0);
320+
static const BIN_ATTR(vpd, 0600, vpd_read, vpd_write, 0);
321321

322-
static struct bin_attribute *vpd_attrs[] = {
322+
static const struct bin_attribute *const vpd_attrs[] = {
323323
&bin_attr_vpd,
324324
NULL,
325325
};
@@ -336,7 +336,7 @@ static umode_t vpd_attr_is_visible(struct kobject *kobj,
336336
}
337337

338338
const struct attribute_group pci_dev_vpd_attr_group = {
339-
.bin_attrs = vpd_attrs,
339+
.bin_attrs_new = vpd_attrs,
340340
.is_bin_visible = vpd_attr_is_visible,
341341
};
342342

0 commit comments

Comments
 (0)