Skip to content

Commit

Permalink
PCI: Use kobj_to_dev() instead of open-coding it
Browse files Browse the repository at this point in the history
Use kobj_to_dev() instead of open-coding it.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  • Loading branch information
Geliang Tang authored and Bjorn Helgaas committed Jan 8, 2016
1 parent f3d2f16 commit 554a603
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
4 changes: 2 additions & 2 deletions drivers/pci/pci-label.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static umode_t smbios_instance_string_exist(struct kobject *kobj,
struct device *dev;
struct pci_dev *pdev;

dev = container_of(kobj, struct device, kobj);
dev = kobj_to_dev(kobj);
pdev = to_pci_dev(dev);

return find_smbios_instance_string(pdev, NULL, SMBIOS_ATTR_NONE) ?
Expand Down Expand Up @@ -221,7 +221,7 @@ static umode_t acpi_index_string_exist(struct kobject *kobj,
{
struct device *dev;

dev = container_of(kobj, struct device, kobj);
dev = kobj_to_dev(kobj);

if (device_has_dsm(dev))
return S_IRUGO;
Expand Down
40 changes: 15 additions & 25 deletions drivers/pci/pci-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,7 @@ static ssize_t pci_read_config(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_dev *dev = to_pci_dev(container_of(kobj, struct device,
kobj));
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
unsigned int size = 64;
loff_t init_off = off;
u8 *data = (u8 *) buf;
Expand Down Expand Up @@ -704,8 +703,7 @@ static ssize_t pci_write_config(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_dev *dev = to_pci_dev(container_of(kobj, struct device,
kobj));
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
unsigned int size = count;
loff_t init_off = off;
u8 *data = (u8 *) buf;
Expand Down Expand Up @@ -766,8 +764,7 @@ static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_dev *dev =
to_pci_dev(container_of(kobj, struct device, kobj));
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));

if (off > bin_attr->size)
count = 0;
Expand All @@ -781,8 +778,7 @@ static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_dev *dev =
to_pci_dev(container_of(kobj, struct device, kobj));
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));

if (off > bin_attr->size)
count = 0;
Expand All @@ -809,8 +805,7 @@ static ssize_t pci_read_legacy_io(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_bus *bus = to_pci_bus(container_of(kobj, struct device,
kobj));
struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));

/* Only support 1, 2 or 4 byte accesses */
if (count != 1 && count != 2 && count != 4)
Expand All @@ -835,8 +830,7 @@ static ssize_t pci_write_legacy_io(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_bus *bus = to_pci_bus(container_of(kobj, struct device,
kobj));
struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));

/* Only support 1, 2 or 4 byte accesses */
if (count != 1 && count != 2 && count != 4)
Expand All @@ -860,8 +854,7 @@ static int pci_mmap_legacy_mem(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
struct vm_area_struct *vma)
{
struct pci_bus *bus = to_pci_bus(container_of(kobj, struct device,
kobj));
struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));

return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem);
}
Expand All @@ -881,8 +874,7 @@ static int pci_mmap_legacy_io(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
struct vm_area_struct *vma)
{
struct pci_bus *bus = to_pci_bus(container_of(kobj, struct device,
kobj));
struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));

return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io);
}
Expand Down Expand Up @@ -997,8 +989,7 @@ int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
struct vm_area_struct *vma, int write_combine)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj,
struct device, kobj));
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
struct resource *res = attr->private;
enum pci_mmap_state mmap_type;
resource_size_t start, end;
Expand Down Expand Up @@ -1051,8 +1042,7 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t off, size_t count, bool write)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj,
struct device, kobj));
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
struct resource *res = attr->private;
unsigned long port = off;
int i;
Expand Down Expand Up @@ -1222,7 +1212,7 @@ static ssize_t pci_write_rom(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));

if ((off == 0) && (*buf == '0') && (count == 2))
pdev->rom_attr_enabled = 0;
Expand All @@ -1248,7 +1238,7 @@ static ssize_t pci_read_rom(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
void __iomem *rom;
size_t size;

Expand Down Expand Up @@ -1508,7 +1498,7 @@ static struct attribute *pci_dev_dev_attrs[] = {
static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct device *dev = kobj_to_dev(kobj);
struct pci_dev *pdev = to_pci_dev(dev);

if (a == &vga_attr.attr)
Expand All @@ -1527,7 +1517,7 @@ static struct attribute *pci_dev_hp_attrs[] = {
static umode_t pci_dev_hp_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct device *dev = kobj_to_dev(kobj);
struct pci_dev *pdev = to_pci_dev(dev);

if (pdev->is_virtfn)
Expand All @@ -1551,7 +1541,7 @@ static struct attribute *sriov_dev_attrs[] = {
static umode_t sriov_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct device *dev = kobj_to_dev(kobj);

if (!dev_is_pf(dev))
return 0;
Expand Down

0 comments on commit 554a603

Please sign in to comment.