Skip to contentSkip to conversation

ibmasm: add missing pci_enable_device()

PATCH In review Bjorn Helgaas 3 participants 4 messages Aug 4, 2004 – Aug 9, 2004 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ibmasm: add missing pci_enable_device()

I don't have this hardware, so this has not been tested.

Add pci_enable_device()/pci_disable_device(). In the past, drivers often worked without this, but it is now required in order to route PCI interrupts correctly.

===== drivers/misc/ibmasm/module.c 1.2 vs edited =====

drivers/misc/ibmasm/module.c +11 -1
@@ -62,10 +62,17 @@
 	int result = -ENOMEM;
 	struct service_processor *sp;
 
+	if (pci_enable_device(pdev)) {
+		printk(KERN_ERR "%s: can't enable PCI device at %s\n",
+			DRIVER_NAME, pci_name(pdev));
+		return -ENODEV;
+	}
+
 	sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
 	if (sp == NULL) {
 		dev_err(&pdev->dev, "Failed to allocate memory\n");
-		return result;
+		result = -ENOMEM;
+		goto error_kmalloc;
 	}
 	memset(sp, 0, sizeof(struct service_processor));
 
@@ -148,6 +155,8 @@
 	ibmasm_event_buffer_exit(sp);
 error_eventbuffer:
 	kfree(sp);
+error_kmalloc:
+	pci_disable_device(pdev);
 
 	return result;
 }
@@ -166,6 +175,7 @@
 	iounmap(sp->base_address);
 	ibmasm_event_buffer_exit(sp);
 	kfree(sp);
+	pci_disable_device(pdev);
 }
 
 static struct pci_device_id ibmasm_pci_table[] =
#1 lore raw

I tested this on the hardware. It works fine.
Is there any reason we shouldn't use dev_err() for the pci_enable error message like in the other messages?

regards,
max

Quoted 55 lines · Bjorn Helgaas

I don't have this hardware, so this has not been tested.

Add pci_enable_device()/pci_disable_device(). In the past, drivers often worked without this, but it is now required in order to route PCI interrupts correctly.

===== drivers/misc/ibmasm/module.c 1.2 vs edited =====

drivers/misc/ibmasm/module.c +11 -2
@@ -62,10 +62,17 @@
 	int result = -ENOMEM;
 	struct service_processor *sp;
 
+	if (pci_enable_device(pdev)) {
+		printk(KERN_ERR "%s: can't enable PCI device at %s\n",
+			DRIVER_NAME, pci_name(pdev));
+		return -ENODEV;
+	}
+
 	sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
 	if (sp == NULL) {
 		dev_err(&pdev->dev, "Failed to allocate memory\n");
-		return result;
+		result = -ENOMEM;
+		goto error_kmalloc;
 	}
 	memset(sp, 0, sizeof(struct service_processor));
 
@@ -148,6 +155,8 @@
 	ibmasm_event_buffer_exit(sp);
 error_eventbuffer:
 	kfree(sp);
+error_kmalloc:
+	pci_disable_device(pdev);
 
 	return result;
 }
@@ -166,6 +175,7 @@
 	iounmap(sp->base_address);
 	ibmasm_event_buffer_exit(sp);
 	kfree(sp);
+	pci_disable_device(pdev);
 }
 
 static struct pci_device_id ibmasm_pci_table[] =
-

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
Quoted 3 lines · Max Asbock

I tested this on the hardware. It works fine.
Is there any reason we shouldn't use dev_err() for the pci_enable error message like in the other messages?

That would probably be fine, too. ISTR looking at one case where the printk wrapper wouldn't work quite right if pci_enable_device() failed. But dev_err() looks like it should work fine.

Quoted 61 lines

regards,
max

Quoted 55 lines · Bjorn Helgaas

I don't have this hardware, so this has not been tested.

Add pci_enable_device()/pci_disable_device(). In the past, drivers often worked without this, but it is now required in order to route PCI interrupts correctly.

===== drivers/misc/ibmasm/module.c 1.2 vs edited =====

drivers/misc/ibmasm/module.c +11 -2
@@ -62,10 +62,17 @@
 	int result = -ENOMEM;
 	struct service_processor *sp;
 
+	if (pci_enable_device(pdev)) {
+		printk(KERN_ERR "%s: can't enable PCI device at %s\n",
+			DRIVER_NAME, pci_name(pdev));
+		return -ENODEV;
+	}
+
 	sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
 	if (sp == NULL) {
 		dev_err(&pdev->dev, "Failed to allocate memory\n");
-		return result;
+		result = -ENOMEM;
+		goto error_kmalloc;
 	}
 	memset(sp, 0, sizeof(struct service_processor));
 
@@ -148,6 +155,8 @@
 	ibmasm_event_buffer_exit(sp);
 error_eventbuffer:
 	kfree(sp);
+error_kmalloc:
+	pci_disable_device(pdev);
 
 	return result;
 }
@@ -166,6 +175,7 @@
 	iounmap(sp->base_address);
 	ibmasm_event_buffer_exit(sp);
 	kfree(sp);
+	pci_disable_device(pdev);
 }
 
 static struct pci_device_id ibmasm_pci_table[] =
-

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#3 lore raw

Bjorn Helgaas <[email protected]> :
[...]

Quoted 11 lines
Quoted 11 lines

drivers/misc/ibmasm/module.c line 68

Quoted 11 lines

===== drivers/misc/ibmasm/module.c 1.2 vs edited =====

drivers/misc/ibmasm/module.c +4 -0
@@ -62,10 +62,17 @@
 	int result = -ENOMEM;
 	struct service_processor *sp;
 
+	if (pci_enable_device(pdev)) {
+		printk(KERN_ERR "%s: can't enable PCI device at %s\n",
+			DRIVER_NAME, pci_name(pdev));
+		return -ENODEV;

Btw, pci_enable_device returns a perfectly fine status code. There is no reason to override it ('result = pci_enable_device(...' and you can even remove the previous ENOMEM initialization).

[...]

Quoted 6 lines
Quoted 6 lines

drivers/misc/ibmasm/module.c line 75

Quoted 6 lines
drivers/misc/ibmasm/module.c +2 -1
 	sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
 	if (sp == NULL) {
 		dev_err(&pdev->dev, "Failed to allocate memory\n");
-		return result;
+		result = -ENOMEM;
+		goto error_kmalloc;

You may consider calling it err_pci_disable (or such). This way:
- one can check that the kmalloc is preceeded by a pci_enable;
- one can locally check that the unroll path does its job (error_pci_disable is followed by a pci_disable_xxx -> makes sense).

--
Ueimor