From fb26228bfc4ce3951544848555c0278e2832e618 Mon Sep 17 00:00:00 2001 From: Tyrel Datwyler Date: Fri, 22 Mar 2019 13:27:21 -0500 Subject: PCI: rpadlpar: Fix leaked device_node references in add/remove paths The find_dlpar_node() helper returns a device node with its reference incremented. Both the add and remove paths use this helper for find the appropriate node, but fail to release the reference when done. Annotate the find_dlpar_node() helper with a comment about the incremented reference count and call of_node_put() on the obtained device_node in the add and remove paths. Also, fixup a reference leak in the find_vio_slot() helper where we fail to call of_node_put() on the vdevice node after we iterate over its children. Signed-off-by: Tyrel Datwyler Signed-off-by: Bjorn Helgaas --- drivers/pci/hotplug/rpadlpar_core.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c index e2356a9c7088..182f9e3443ee 100644 --- a/drivers/pci/hotplug/rpadlpar_core.c +++ b/drivers/pci/hotplug/rpadlpar_core.c @@ -51,6 +51,7 @@ static struct device_node *find_vio_slot_node(char *drc_name) if (rc == 0) break; } + of_node_put(parent); return dn; } @@ -71,6 +72,7 @@ static struct device_node *find_php_slot_pci_node(char *drc_name, return np; } +/* Returns a device_node with its reference count incremented */ static struct device_node *find_dlpar_node(char *drc_name, int *node_type) { struct device_node *dn; @@ -306,6 +308,7 @@ int dlpar_add_slot(char *drc_name) rc = dlpar_add_phb(drc_name, dn); break; } + of_node_put(dn); printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name); exit: @@ -439,6 +442,7 @@ int dlpar_remove_slot(char *drc_name) rc = dlpar_remove_pci_slot(drc_name, dn); break; } + of_node_put(dn); vm_unmap_aliases(); printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name); -- cgit v1.2.3 From 91800660bbe9d4ae7791f0e646e5736180f01fc0 Mon Sep 17 00:00:00 2001 From: Tyrel Datwyler Date: Fri, 22 Mar 2019 13:27:22 -0500 Subject: PCI: rpaphp: Get/put device node reference during slot alloc/dealloc When allocating the slot structure we store a pointer to the associated device_node. We really should be incrementing the reference count, so add an of_node_get() during slot alloc and an of_node_put() during slot dealloc. Signed-off-by: Tyrel Datwyler Signed-off-by: Bjorn Helgaas --- drivers/pci/hotplug/rpaphp_slot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c index 5282aa3e33c5..93b4a945c55d 100644 --- a/drivers/pci/hotplug/rpaphp_slot.c +++ b/drivers/pci/hotplug/rpaphp_slot.c @@ -21,6 +21,7 @@ /* free up the memory used by a slot */ void dealloc_slot_struct(struct slot *slot) { + of_node_put(slot->dn); kfree(slot->name); kfree(slot); } @@ -36,7 +37,7 @@ struct slot *alloc_slot_struct(struct device_node *dn, slot->name = kstrdup(drc_name, GFP_KERNEL); if (!slot->name) goto error_slot; - slot->dn = dn; + slot->dn = of_node_get(dn); slot->index = drc_index; slot->power_domain = power_domain; slot->hotplug_slot.ops = &rpaphp_hotplug_slot_ops; -- cgit v1.2.3 From 7e696b8ae9a7f939584284a12eec3b7c62123836 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Wed, 8 May 2019 14:59:00 -0500 Subject: PCI: pciehp: Remove pciehp_debug uses We're about to convert pciehp to the dyndbg mechanism, which means we can eventually remove pciehp_debug. Replace uses of pciehp_debug with dbg() and ctrl_dbg(), which check pciehp_debug internally. Link: https://lore.kernel.org/lkml/20190509141456.223614-6-helgaas@kernel.org Signed-off-by: Bjorn Helgaas Reviewed-by: Keith Busch Reviewed-by: Andy Shevchenko --- drivers/pci/hotplug/pciehp_hpc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 6a2365cd794e..e121f1c06c21 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -232,8 +232,8 @@ static bool pci_bus_check_dev(struct pci_bus *bus, int devfn) delay -= step; } while (delay > 0); - if (count > 1 && pciehp_debug) - printk(KERN_DEBUG "pci %04x:%02x:%02x.%d id reading try %d times with interval %d ms to get %08x\n", + if (count > 1) + dbg("pci %04x:%02x:%02x.%d id reading try %d times with interval %d ms to get %08x\n", pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), count, step, l); @@ -822,14 +822,11 @@ static inline void dbg_ctrl(struct controller *ctrl) struct pci_dev *pdev = ctrl->pcie->port; u16 reg16; - if (!pciehp_debug) - return; - - ctrl_info(ctrl, "Slot Capabilities : 0x%08x\n", ctrl->slot_cap); + ctrl_dbg(ctrl, "Slot Capabilities : 0x%08x\n", ctrl->slot_cap); pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, ®16); - ctrl_info(ctrl, "Slot Status : 0x%04x\n", reg16); + ctrl_dbg(ctrl, "Slot Status : 0x%04x\n", reg16); pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, ®16); - ctrl_info(ctrl, "Slot Control : 0x%04x\n", reg16); + ctrl_dbg(ctrl, "Slot Control : 0x%04x\n", reg16); } #define FLAG(x, y) (((x) & (y)) ? '+' : '-') -- cgit v1.2.3 From 017124725c155a3e1b09429d27c5846b0efafa89 Mon Sep 17 00:00:00 2001 From: Frederick Lawler Date: Tue, 7 May 2019 18:24:52 -0500 Subject: PCI: pciehp: Replace pciehp_debug module param with dyndbg Previously pciehp debug messages were enabled by the pciehp_debug module parameter, e.g., by booting with this kernel command line option: pciehp.pciehp_debug=1 Convert this mechanism to use the generic dynamic debug (dyndbg) feature. After this commit, pciehp debug messages are enabled by building the kernel with CONFIG_DYNAMIC_DEBUG=y and booting with this command line option: dyndbg="file pciehp* +p" The dyndbg facility is much more flexible: messages can be enabled at boot- or run-time based on the file name, function name, line number, message test, etc. See Documentation/admin-guide/dynamic-debug-howto.rst for more details. Link: https://lore.kernel.org/lkml/20190509141456.223614-7-helgaas@kernel.org Signed-off-by: Frederick Lawler [bhelgaas: commit log, comment, remove pciehp_debug parameter] Signed-off-by: Bjorn Helgaas Reviewed-by: Keith Busch Reviewed-by: Andy Shevchenko --- drivers/pci/hotplug/pciehp.h | 16 ++++++---------- drivers/pci/hotplug/pciehp_core.c | 3 --- 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index 506e1d923a1f..af5d9f92e6d5 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -29,13 +29,13 @@ extern bool pciehp_poll_mode; extern int pciehp_poll_time; -extern bool pciehp_debug; +/* + * Set CONFIG_DYNAMIC_DEBUG=y and boot with 'dyndbg="file pciehp* +p"' to + * enable debug messages. + */ #define dbg(format, arg...) \ -do { \ - if (pciehp_debug) \ - printk(KERN_DEBUG "%s: " format, MY_NAME, ## arg); \ -} while (0) + pr_debug("%s: " format, MY_NAME, ## arg); #define err(format, arg...) \ printk(KERN_ERR "%s: " format, MY_NAME, ## arg) #define info(format, arg...) \ @@ -44,11 +44,7 @@ do { \ printk(KERN_WARNING "%s: " format, MY_NAME, ## arg) #define ctrl_dbg(ctrl, format, arg...) \ - do { \ - if (pciehp_debug) \ - dev_printk(KERN_DEBUG, &ctrl->pcie->device, \ - format, ## arg); \ - } while (0) + dev_dbg(&ctrl->pcie->device, format, ## arg) #define ctrl_err(ctrl, format, arg...) \ dev_err(&ctrl->pcie->device, format, ## arg) #define ctrl_info(ctrl, format, arg...) \ diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index fc5366b50e95..6ff204c435bf 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c @@ -27,7 +27,6 @@ #include "../pci.h" /* Global variables */ -bool pciehp_debug; bool pciehp_poll_mode; int pciehp_poll_time; @@ -35,10 +34,8 @@ int pciehp_poll_time; * not really modular, but the easiest way to keep compat with existing * bootargs behaviour is to continue using module_param here. */ -module_param(pciehp_debug, bool, 0644); module_param(pciehp_poll_mode, bool, 0644); module_param(pciehp_poll_time, int, 0644); -MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not"); MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not"); MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds"); -- cgit v1.2.3 From 94dbc9562edc745d0549f1744ca1bd75e644473e Mon Sep 17 00:00:00 2001 From: Frederick Lawler Date: Tue, 7 May 2019 18:24:51 -0500 Subject: PCI: pciehp: Log messages with pci_dev, not pcie_device Log messages with pci_dev, not pcie_device. Factor out common message prefixes with dev_fmt(). Example output change: - pciehp 0000:00:06.0:pcie004: Slot(0) Powering on due to button press + pcieport 0000:00:06.0: pciehp: Slot(0) Powering on due to button press Link: https://lore.kernel.org/lkml/20190509141456.223614-8-helgaas@kernel.org Signed-off-by: Frederick Lawler Signed-off-by: Bjorn Helgaas Reviewed-by: Keith Busch Reviewed-by: Andy Shevchenko --- drivers/pci/hotplug/pciehp.h | 16 ++++++++-------- drivers/pci/hotplug/pciehp_core.c | 7 +++++-- drivers/pci/hotplug/pciehp_ctrl.c | 2 ++ drivers/pci/hotplug/pciehp_hpc.c | 2 ++ drivers/pci/hotplug/pciehp_pci.c | 2 ++ 5 files changed, 19 insertions(+), 10 deletions(-) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index af5d9f92e6d5..2f0295b48d5d 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -35,22 +35,22 @@ extern int pciehp_poll_time; * enable debug messages. */ #define dbg(format, arg...) \ - pr_debug("%s: " format, MY_NAME, ## arg); + pr_debug(format, ## arg); #define err(format, arg...) \ - printk(KERN_ERR "%s: " format, MY_NAME, ## arg) + pr_err(format, ## arg) #define info(format, arg...) \ - printk(KERN_INFO "%s: " format, MY_NAME, ## arg) + pr_info(format, ## arg) #define warn(format, arg...) \ - printk(KERN_WARNING "%s: " format, MY_NAME, ## arg) + pr_warn(format, ## arg) #define ctrl_dbg(ctrl, format, arg...) \ - dev_dbg(&ctrl->pcie->device, format, ## arg) + pci_dbg(ctrl->pcie->port, format, ## arg) #define ctrl_err(ctrl, format, arg...) \ - dev_err(&ctrl->pcie->device, format, ## arg) + pci_err(ctrl->pcie->port, format, ## arg) #define ctrl_info(ctrl, format, arg...) \ - dev_info(&ctrl->pcie->device, format, ## arg) + pci_info(ctrl->pcie->port, format, ## arg) #define ctrl_warn(ctrl, format, arg...) \ - dev_warn(&ctrl->pcie->device, format, ## arg) + pci_warn(ctrl->pcie->port, format, ## arg) #define SLOT_NAME_SIZE 10 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index 6ff204c435bf..b85b22880c50 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c @@ -17,6 +17,9 @@ * Dely Sy " */ +#define pr_fmt(fmt) "pciehp: " fmt +#define dev_fmt pr_fmt + #include #include #include @@ -179,14 +182,14 @@ static int pciehp_probe(struct pcie_device *dev) if (!dev->port->subordinate) { /* Can happen if we run out of bus numbers during probe */ - dev_err(&dev->device, + pci_err(dev->port, "Hotplug bridge without secondary bus, ignoring\n"); return -ENODEV; } ctrl = pcie_init(dev); if (!ctrl) { - dev_err(&dev->device, "Controller initialization failed\n"); + pci_err(dev->port, "Controller initialization failed\n"); return -ENODEV; } set_service_data(dev, ctrl); diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c index 3f3df4c29f6e..bf81f977a751 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c @@ -13,6 +13,8 @@ * */ +#define dev_fmt(fmt) "pciehp: " fmt + #include #include #include diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index e121f1c06c21..913c7e66504f 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -12,6 +12,8 @@ * Send feedback to , */ +#define dev_fmt(fmt) "pciehp: " fmt + #include #include #include diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index b9c1396db6fe..d17f3bf36f70 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c @@ -13,6 +13,8 @@ * */ +#define dev_fmt(fmt) "pciehp: " fmt + #include #include #include -- cgit v1.2.3 From 742ee16bc31f42b034a9b3b01731fd6dc20d0b19 Mon Sep 17 00:00:00 2001 From: Frederick Lawler Date: Tue, 7 May 2019 18:24:53 -0500 Subject: PCI: pciehp: Remove unused dbg/err/info/warn() wrappers Replace the last uses of dbg() with the equivalent pr_debug(), then remove unused dbg(), err(), info(), and warn() wrappers. Link: https://lore.kernel.org/lkml/20190509141456.223614-9-helgaas@kernel.org Signed-off-by: Frederick Lawler Signed-off-by: Bjorn Helgaas Reviewed-by: Keith Busch Reviewed-by: Andy Shevchenko --- drivers/pci/hotplug/pciehp.h | 9 --------- drivers/pci/hotplug/pciehp_core.c | 4 ++-- drivers/pci/hotplug/pciehp_hpc.c | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index 2f0295b48d5d..c206fd9cd3d7 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -34,15 +34,6 @@ extern int pciehp_poll_time; * Set CONFIG_DYNAMIC_DEBUG=y and boot with 'dyndbg="file pciehp* +p"' to * enable debug messages. */ -#define dbg(format, arg...) \ - pr_debug(format, ## arg); -#define err(format, arg...) \ - pr_err(format, ## arg) -#define info(format, arg...) \ - pr_info(format, ## arg) -#define warn(format, arg...) \ - pr_warn(format, ## arg) - #define ctrl_dbg(ctrl, format, arg...) \ pci_dbg(ctrl->pcie->port, format, ## arg) #define ctrl_err(ctrl, format, arg...) \ diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index b85b22880c50..1643e9aa261c 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c @@ -328,9 +328,9 @@ int __init pcie_hp_init(void) int retval = 0; retval = pcie_port_service_register(&hpdriver_portdrv); - dbg("pcie_port_service_register = %d\n", retval); + pr_debug("pcie_port_service_register = %d\n", retval); if (retval) - dbg("Failure to register service\n"); + pr_debug("Failure to register service\n"); return retval; } diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 913c7e66504f..9ce93b1034bd 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -235,7 +235,7 @@ static bool pci_bus_check_dev(struct pci_bus *bus, int devfn) } while (delay > 0); if (count > 1) - dbg("pci %04x:%02x:%02x.%d id reading try %d times with interval %d ms to get %08x\n", + pr_debug("pci %04x:%02x:%02x.%d id reading try %d times with interval %d ms to get %08x\n", pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), count, step, l); -- cgit v1.2.3 From b498b6872da1143d67ed588d21d3c3c496a987ee Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Wed, 8 May 2019 15:23:39 -0500 Subject: PCI: pciehp: Remove pointless PCIE_MODULE_NAME definition PCIE_MODULE_NAME is only used once and offers no benefit, so remove it. Link: https://lore.kernel.org/lkml/20190509141456.223614-10-helgaas@kernel.org Signed-off-by: Bjorn Helgaas Reviewed-by: Keith Busch Reviewed-by: Andy Shevchenko --- drivers/pci/hotplug/pciehp_core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index 1643e9aa261c..6ad0d86762cb 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c @@ -42,8 +42,6 @@ module_param(pciehp_poll_time, int, 0644); MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not"); MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds"); -#define PCIE_MODULE_NAME "pciehp" - static int set_attention_status(struct hotplug_slot *slot, u8 value); static int get_power_status(struct hotplug_slot *slot, u8 *value); static int get_latch_status(struct hotplug_slot *slot, u8 *value); @@ -307,7 +305,7 @@ static int pciehp_runtime_resume(struct pcie_device *dev) #endif /* PM */ static struct pcie_port_service_driver hpdriver_portdrv = { - .name = PCIE_MODULE_NAME, + .name = "pciehp", .port_type = PCIE_ANY_PORT, .service = PCIE_PORT_SERVICE_HP, -- cgit v1.2.3 From e07ca82a5fde88b5caf2b7025e97c7980c60abe1 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Wed, 8 May 2019 16:34:01 -0500 Subject: PCI: pciehp: Remove pointless MY_NAME definition MY_NAME is only used once and offers no benefit, so remove it. Link: https://lore.kernel.org/lkml/20190509141456.223614-11-helgaas@kernel.org Signed-off-by: Bjorn Helgaas Reviewed-by: Keith Busch Reviewed-by: Andy Shevchenko --- drivers/pci/hotplug/pciehp.h | 2 -- drivers/pci/hotplug/pciehp_hpc.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/pci/hotplug') diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index c206fd9cd3d7..8c51a04b8083 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -25,8 +25,6 @@ #include "../pcie/portdrv.h" -#define MY_NAME "pciehp" - extern bool pciehp_poll_mode; extern int pciehp_poll_time; diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 9ce93b1034bd..bd990e3371e3 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -48,7 +48,7 @@ static inline int pciehp_request_irq(struct controller *ctrl) /* Installs the interrupt handler */ retval = request_threaded_irq(irq, pciehp_isr, pciehp_ist, - IRQF_SHARED, MY_NAME, ctrl); + IRQF_SHARED, "pciehp", ctrl); if (retval) ctrl_err(ctrl, "Cannot get irq %d for the hotplug controller\n", irq); -- cgit v1.2.3