Skip to content

Commit a1ab720

Browse files
t-8chgregkh
authored andcommitted
PCI/sysfs: Calculate bin_attribute size through bin_size()
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 <[email protected]> Acked-by: Krzysztof Wilczyński <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bebf29b commit a1ab720

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -818,21 +818,20 @@ static struct bin_attribute *pci_dev_config_attrs[] = {
818818
NULL,
819819
};
820820

821-
static umode_t pci_dev_config_attr_is_visible(struct kobject *kobj,
822-
struct bin_attribute *a, int n)
821+
static size_t pci_dev_config_attr_bin_size(struct kobject *kobj,
822+
const struct bin_attribute *a,
823+
int n)
823824
{
824825
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
825826

826-
a->size = PCI_CFG_SPACE_SIZE;
827827
if (pdev->cfg_size > PCI_CFG_SPACE_SIZE)
828-
a->size = PCI_CFG_SPACE_EXP_SIZE;
829-
830-
return a->attr.mode;
828+
return PCI_CFG_SPACE_EXP_SIZE;
829+
return PCI_CFG_SPACE_SIZE;
831830
}
832831

833832
static const struct attribute_group pci_dev_config_attr_group = {
834833
.bin_attrs = pci_dev_config_attrs,
835-
.is_bin_visible = pci_dev_config_attr_is_visible,
834+
.bin_size = pci_dev_config_attr_bin_size,
836835
};
837836

838837
/*
@@ -1330,21 +1329,26 @@ static umode_t pci_dev_rom_attr_is_visible(struct kobject *kobj,
13301329
struct bin_attribute *a, int n)
13311330
{
13321331
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1333-
size_t rom_size;
13341332

13351333
/* If the device has a ROM, try to expose it in sysfs. */
1336-
rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
1337-
if (!rom_size)
1334+
if (!pci_resource_end(pdev, PCI_ROM_RESOURCE))
13381335
return 0;
13391336

1340-
a->size = rom_size;
1341-
13421337
return a->attr.mode;
13431338
}
13441339

1340+
static size_t pci_dev_rom_attr_bin_size(struct kobject *kobj,
1341+
const struct bin_attribute *a, int n)
1342+
{
1343+
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1344+
1345+
return pci_resource_len(pdev, PCI_ROM_RESOURCE);
1346+
}
1347+
13451348
static const struct attribute_group pci_dev_rom_attr_group = {
13461349
.bin_attrs = pci_dev_rom_attrs,
13471350
.is_bin_visible = pci_dev_rom_attr_is_visible,
1351+
.bin_size = pci_dev_rom_attr_bin_size,
13481352
};
13491353

13501354
static ssize_t reset_store(struct device *dev, struct device_attribute *attr,

0 commit comments

Comments
 (0)