Commit a1ab720e authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Greg Kroah-Hartman
Browse files

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: default avatarThomas Weißschuh <linux@weissschuh.net>
Acked-by: default avatarKrzysztof Wilczyński <kw@linux.com>
Link: https://lore.kernel.org/r/20241103-sysfs-const-bin_attr-v2-3-71110628844c@weissschuh.net


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bebf29b1
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -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,