Skip to contentSkip to conversation

PCI: cpqphp: Fix error handling in cpqhpc_init()

PATCH Superseded Yuan Can 2 participants 3 messages Nov 22, 2022 – Nov 23, 2022 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 PCI: cpqphp: Fix error handling in cpqhpc_init()

The cpqhpc_init() returns the result of pci_register_driver() without checking it, if pci_register_driver() failed, the debugfs created in cpqhp_initialize_debugfs() is not removed, resulting the debugfs of cpqhp can never be created later.
Fix by calling cpqhp_shutdown_debugfs() when pci_register_driver() failed.

Fixes 9f3f4681291f ("[PATCH] PCI Hotplug: fix up the sysfs file in the compaq pci hotplug driver")
---
 drivers/pci/hotplug/cpqphp_core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/hotplug/cpqphp_core.c +2 -0
index c94b40e64baf..c47981ef92ea 100644
@@ -1389,6 +1389,8 @@ static int __init cpqhpc_init(void)
 	info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
 	cpqhp_initialize_debugfs();
 	result = pci_register_driver(&cpqhpc_driver);
+	if (result)
+		cpqhp_shutdown_debugfs();
 	dbg("pci_register_driver = %d\n", result);
 	return result;
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · Yuan Can

The cpqhpc_init() returns the result of pci_register_driver() without checking it, if pci_register_driver() failed, the debugfs created in cpqhp_initialize_debugfs() is not removed, resulting the debugfs of cpqhp can never be created later.
Fix by calling cpqhp_shutdown_debugfs() when pci_register_driver() failed.

Add a blank line between paragraphs.

Quoted 11 lines
Fixes 9f3f4681291f ("[PATCH] PCI Hotplug: fix up the sysfs file in the compaq pci hotplug driver")
---
 drivers/pci/hotplug/cpqphp_core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/hotplug/cpqphp_core.c +0 -0
index c94b40e64baf..c47981ef92ea 100644

drivers/pci/hotplug/cpqphp_core.c static int __init cpqhpc_init(void) · line 1393

Quoted 5 lines
drivers/pci/hotplug/cpqphp_core.c +2 -0
@@ -1389,6 +1389,8 @@ static int __init cpqhpc_init(void)
 	info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
 	cpqhp_initialize_debugfs();
 	result = pci_register_driver(&cpqhpc_driver);
+	if (result)
+		cpqhp_shutdown_debugfs();

Is there some reason cpqhp_initialize_debugfs() needs to be called before pci_register_driver()?

In other words, could we do this instead?

  result = pci_register_driver(&cpqhpc_driver);
  if (result)
    return result;

  cpqhp_initialize_debugfs();
  return 0;

I assume this was found by code inspection? I've never heard of anybody actually using this driver :)

Quoted 6 lines
drivers/pci/hotplug/cpqphp_core.c +0 -0
 	dbg("pci_register_driver = %d\n", result);
 	return result;
 }
Signature · 1 line
2.17.1
author
#2 lore raw
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Yuan Can

The cpqhpc_init() returns the result of pci_register_driver() without checking it, if pci_register_driver() failed, the debugfs created in cpqhp_initialize_debugfs() is not removed, resulting the debugfs of cpqhp can never be created later.
Fix by calling cpqhp_shutdown_debugfs() when pci_register_driver() failed.

Add a blank line between paragraphs.

Ok.

Quoted 19 lines
Quoted 11 lines
Fixes 9f3f4681291f ("[PATCH] PCI Hotplug: fix up the sysfs file in the compaq pci hotplug driver")
---
  drivers/pci/hotplug/cpqphp_core.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/pci/hotplug/cpqphp_core.c +0 -0
index c94b40e64baf..c47981ef92ea 100644

drivers/pci/hotplug/cpqphp_core.c static int __init cpqhpc_init(void) · line 1393

Quoted 5 lines
drivers/pci/hotplug/cpqphp_core.c +2 -0
@@ -1389,6 +1389,8 @@ static int __init cpqhpc_init(void)
  	info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
  	cpqhp_initialize_debugfs();
  	result = pci_register_driver(&cpqhpc_driver);
+	if (result)
+		cpqhp_shutdown_debugfs();

Is there some reason cpqhp_initialize_debugfs() needs to be called before pci_register_driver()?

Quoted 8 lines

In other words, could we do this instead?

   result = pci_register_driver(&cpqhpc_driver);
   if (result)
     return result;

   cpqhp_initialize_debugfs();
   return 0;

Thanks for the suggestion! I do not see any reason that the order must be kept, will change to this style in the next version.

Quoted 2 lines

I assume this was found by code inspection? I've never heard of anybody actually using this driver :)

Yes, you are right :)

Quoted 6 lines
Quoted 6 lines
drivers/pci/hotplug/cpqphp_core.c +0 -0
  	dbg("pci_register_driver = %d\n", result);
  	return result;
  }
Signature · 1 line
2.17.1
Signature · 2 lines
Best regards,
Yuan Can