--- zzzz-none-000/linux-4.4.60/drivers/pci/pci-sysfs.c 2017-04-08 07:53:53.000000000 +0000 +++ scorpion-7490-727/linux-4.4.60/drivers/pci/pci-sysfs.c 2021-02-04 17:41:59.000000000 +0000 @@ -321,8 +321,32 @@ } static BUS_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store); +#ifdef CONFIG_AVM_PCI_RECOVERY +static ssize_t bus_down_store(struct bus_type *bus, const char *buf, + size_t count) +{ + ath_pci_down(); + + return count; +} +static BUS_ATTR(down, (S_IWUSR|S_IWGRP), NULL, bus_down_store); + +static ssize_t bus_up_store(struct bus_type *bus, const char *buf, + size_t count) +{ + ath_pci_up(); + + return count; +} +static BUS_ATTR(up, (S_IWUSR|S_IWGRP), NULL, bus_up_store); +#endif + static struct attribute *pci_bus_attrs[] = { &bus_attr_rescan.attr, +#ifdef CONFIG_AVM_PCI_RECOVERY + &bus_attr_down.attr, + &bus_attr_up.attr, +#endif NULL, }; @@ -522,7 +546,7 @@ const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - char *driver_override, *old = pdev->driver_override, *cp; + char *driver_override, *old, *cp; /* We need to keep extra room for a newline */ if (count >= (PAGE_SIZE - 1)) @@ -536,12 +560,15 @@ if (cp) *cp = '\0'; + device_lock(dev); + old = pdev->driver_override; if (strlen(driver_override)) { pdev->driver_override = driver_override; } else { kfree(driver_override); pdev->driver_override = NULL; } + device_unlock(dev); kfree(old); @@ -552,8 +579,12 @@ struct device_attribute *attr, char *buf) { struct pci_dev *pdev = to_pci_dev(dev); + ssize_t len; - return snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override); + device_lock(dev); + len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override); + device_unlock(dev); + return len; } static DEVICE_ATTR_RW(driver_override);