Skip to contentSkip to conversation

leds-ss4200: Check pci_enable_device return

PATCH In review Javier Martinez Canillas 2 participants 3 messages Oct 14, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds-ss4200: Check pci_enable_device return

pci_enable_result is defined using the __must_check macro but leds-ss4200 is not checking the return value.

This patch solves the issue

---
 drivers/leds/leds-ss4200.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/leds/leds-ss4200.c +4 -1
index 0ec4ec3..1e72383 100644
@@ -347,7 +347,10 @@ static int __devinit ich7_lpc_probe(struct pci_dev *dev,
 	int status = 0;
 	u32 gc = 0;
 
-	pci_enable_device(dev);
+	if ((status = pci_enable_device(dev))) {
+		dev_err(&dev->dev, "pci_enable_device failed\n");
+		goto out;
+	}
 
 	nas_gpio_pci_dev = dev;
 	status = pci_read_config_dword(dev, PMBASE, &g_pm_io_base);
Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 3 lines · Javier Martinez Canillas

pci_enable_result is defined using the __must_check macro but leds-ss4200 is not checking the return value.

This patch solves the issue

Thanks for the patch. By the way, what tree is this against, or did you just see my patch on a mailing list?

drivers/leds/leds-ss4200.c static int __devinit ich7_lpc_probe(struct pci_dev *dev, · line 353

Quoted 13 lines
drivers/leds/leds-ss4200.c +4 -1
index 0ec4ec3..1e72383 100644
@@ -347,7 +347,10 @@ static int __devinit ich7_lpc_probe(struct pci_dev *dev,
 	int status = 0;
 	u32 gc = 0;
 
-	pci_enable_device(dev);
+	if ((status = pci_enable_device(dev))) {
+		dev_err(&dev->dev, "pci_enable_device failed\n");
+		goto out;
+	}

Unfortunately, this patch has some issues. It's a bit nasty to do real work inside of if() conditions, especially when you already have a nice, local variable to store the condition for you.

Your patch is also buggy because the out: label tries to disable the device and clean up the 'struct device'. Neither of those things has been done if the pci_enable_device() fails in the first place. It will probably oops.

I'll cc you on what I think is the correct patch.

-- Dave

#2 lore raw
In reply to Javier Martinez Canillas
Quoted 4 lines

Thanks for the patch.  By the way, what tree is this against, or did you just see my patch on a mailing list?

It is against yesterday linux-next tree.

Quoted 10 lines

Unfortunately, this patch has some issues.  It's a bit nasty to do real work inside of if() conditions, especially when you already have a nice, local variable to store the condition for you.

Your patch is also buggy because the out: label tries to disable the device and clean up the 'struct device'.  Neither of those things has been done if the pci_enable_device() fails in the first place.  It will probably oops.

I see.

Quoted 5 lines

I'll cc you on what I think is the correct patch.

-- Dave

Thank you very much and sorry for the noise