Message ID | 20241103-sysfs-const-bin_attr-v2-3-71110628844c@weissschuh.net (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | sysfs: constify struct bin_attribute (Part 1) | expand |
On Sun, Nov 03, 2024 at 05:03:32PM +0000, Thomas Weißschuh wrote: > Stop abusing the is_bin_visible() callback to calculate the attribute > size. Instead use the new, dedicated bin_size() one. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Thanks for doing this! > --- > drivers/pci/pci-sysfs.c | 28 ++++++++++++++++------------ > 1 file changed, 16 insertions(+), 12 deletions(-) > > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c > index 5d0f4db1cab78674c5e5906f321bf7a57b742983..040f01b2b999175e8d98b05851edc078bbabbe0d 100644 > --- a/drivers/pci/pci-sysfs.c > +++ b/drivers/pci/pci-sysfs.c > @@ -818,21 +818,20 @@ static struct bin_attribute *pci_dev_config_attrs[] = { > NULL, > }; > > -static umode_t pci_dev_config_attr_is_visible(struct kobject *kobj, > - struct bin_attribute *a, int n) > +static size_t pci_dev_config_attr_bin_size(struct kobject *kobj, > + const struct bin_attribute *a, > + int n) > { > struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); > > - a->size = PCI_CFG_SPACE_SIZE; > if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) > - a->size = PCI_CFG_SPACE_EXP_SIZE; > - > - return a->attr.mode; > + return PCI_CFG_SPACE_EXP_SIZE; > + return PCI_CFG_SPACE_SIZE; > } > > static const struct attribute_group pci_dev_config_attr_group = { > .bin_attrs = pci_dev_config_attrs, > - .is_bin_visible = pci_dev_config_attr_is_visible, > + .bin_size = pci_dev_config_attr_bin_size, > }; > > /* > @@ -1330,21 +1329,26 @@ static umode_t pci_dev_rom_attr_is_visible(struct kobject *kobj, > struct bin_attribute *a, int n) > { > struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); > - size_t rom_size; > > /* If the device has a ROM, try to expose it in sysfs. */ > - rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE); > - if (!rom_size) > + if (!pci_resource_end(pdev, PCI_ROM_RESOURCE)) > return 0; > > - a->size = rom_size; > - > return a->attr.mode; > } > > +static size_t pci_dev_rom_attr_bin_size(struct kobject *kobj, > + const struct bin_attribute *a, int n) > +{ > + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); > + > + return pci_resource_len(pdev, PCI_ROM_RESOURCE); > +} > + > static const struct attribute_group pci_dev_rom_attr_group = { > .bin_attrs = pci_dev_rom_attrs, > .is_bin_visible = pci_dev_rom_attr_is_visible, > + .bin_size = pci_dev_rom_attr_bin_size, > }; > > static ssize_t reset_store(struct device *dev, struct device_attribute *attr, > > -- > 2.47.0 >
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 5d0f4db1cab78674c5e5906f321bf7a57b742983..040f01b2b999175e8d98b05851edc078bbabbe0d 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -818,21 +818,20 @@ static struct bin_attribute *pci_dev_config_attrs[] = { NULL, }; -static umode_t pci_dev_config_attr_is_visible(struct kobject *kobj, - struct bin_attribute *a, int n) +static size_t pci_dev_config_attr_bin_size(struct kobject *kobj, + const struct bin_attribute *a, + int n) { struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); - a->size = PCI_CFG_SPACE_SIZE; if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) - a->size = PCI_CFG_SPACE_EXP_SIZE; - - return a->attr.mode; + return PCI_CFG_SPACE_EXP_SIZE; + return PCI_CFG_SPACE_SIZE; } static const struct attribute_group pci_dev_config_attr_group = { .bin_attrs = pci_dev_config_attrs, - .is_bin_visible = pci_dev_config_attr_is_visible, + .bin_size = pci_dev_config_attr_bin_size, }; /* @@ -1330,21 +1329,26 @@ static umode_t pci_dev_rom_attr_is_visible(struct kobject *kobj, struct bin_attribute *a, int n) { struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); - size_t rom_size; /* If the device has a ROM, try to expose it in sysfs. */ - rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE); - if (!rom_size) + if (!pci_resource_end(pdev, PCI_ROM_RESOURCE)) return 0; - a->size = rom_size; - return a->attr.mode; } +static size_t pci_dev_rom_attr_bin_size(struct kobject *kobj, + const struct bin_attribute *a, int n) +{ + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); + + return pci_resource_len(pdev, PCI_ROM_RESOURCE); +} + static const struct attribute_group pci_dev_rom_attr_group = { .bin_attrs = pci_dev_rom_attrs, .is_bin_visible = pci_dev_rom_attr_is_visible, + .bin_size = pci_dev_rom_attr_bin_size, }; static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
Stop abusing the is_bin_visible() callback to calculate the attribute size. Instead use the new, dedicated bin_size() one. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- drivers/pci/pci-sysfs.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)