Skip to content

Commit 23d99ba

Browse files
krzkgregkh
authored andcommitted
PCI: Use driver_set_override() instead of open-coding
Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20220419113435.246203-6-krzysztof.kozlowski@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 01ed100 commit 23d99ba

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -567,31 +567,11 @@ static ssize_t driver_override_store(struct device *dev,
567567
const char *buf, size_t count)
568568
{
569569
struct pci_dev *pdev = to_pci_dev(dev);
570-
char *driver_override, *old, *cp;
571-
572-
/* We need to keep extra room for a newline */
573-
if (count >= (PAGE_SIZE - 1))
574-
return -EINVAL;
575-
576-
driver_override = kstrndup(buf, count, GFP_KERNEL);
577-
if (!driver_override)
578-
return -ENOMEM;
579-
580-
cp = strchr(driver_override, '\n');
581-
if (cp)
582-
*cp = '\0';
583-
584-
device_lock(dev);
585-
old = pdev->driver_override;
586-
if (strlen(driver_override)) {
587-
pdev->driver_override = driver_override;
588-
} else {
589-
kfree(driver_override);
590-
pdev->driver_override = NULL;
591-
}
592-
device_unlock(dev);
570+
int ret;
593571

594-
kfree(old);
572+
ret = driver_set_override(dev, &pdev->driver_override, buf, count);
573+
if (ret)
574+
return ret;
595575

596576
return count;
597577
}

include/linux/pci.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,11 @@ struct pci_dev {
516516
u16 acs_cap; /* ACS Capability offset */
517517
phys_addr_t rom; /* Physical address if not from BAR */
518518
size_t romlen; /* Length if not from BAR */
519-
char *driver_override; /* Driver name to force a match */
519+
/*
520+
* Driver name to force a match. Do not set directly, because core
521+
* frees it. Use driver_set_override() to set or clear it.
522+
*/
523+
const char *driver_override;
520524

521525
unsigned long priv_flags; /* Private flags for the PCI driver */
522526

0 commit comments

Comments
 (0)