Skip to contentSkip to conversation

PNP: adjust pnp_register_driver signature

PATCH Applied Bjorn Helgaas 4 participants 14 messages Mar 2, 2006 – Mar 14, 2006

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

cover PNP: adjust pnp_register_driver signature

This series of patches removes the assumption that pnp_register_driver() returns the number of devices claimed. Returning the count is unreliable because devices may be hot-plugged in the future. (Many devices don't support hot-plug, of course, but PNP in general does.)

This changes the convention to "zero for success, or a negative error value," which matches pci_register_driver(), acpi_bus_register_driver(), and platform_driver_register().

If drivers need to know the number of devices, they can count calls to their .probe() methods.

#1 lore raw

PATCH 1/9 parport: adjust pnp_register_driver signature

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

parport_pc_init() does nothing with "count", so remove it. Then nobody uses the return value of parport_pc_find_ports(), so make it void. Finally, update pnp_register_driver() usage.

drivers/parport/parport_pc.c +11 -20
Index: work-mm4/drivers/parport/parport_pc.c
===================================================================
@@ -3126,9 +3126,9 @@
  * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
  * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
  */
-static int __init parport_pc_find_ports (int autoirq, int autodma)
+static void __init parport_pc_find_ports (int autoirq, int autodma)
 {
-	int count = 0, r;
+	int count = 0, err;
 
 #ifdef CONFIG_PARPORT_PC_SUPERIO
 	detect_and_report_winbond ();
@@ -3140,23 +3140,17 @@
 
 	/* PnP ports, skip detection if SuperIO already found them */
 	if (!count) {
-		r = pnp_register_driver (&parport_pc_pnp_driver);
-		if (r >= 0) {
+		err = pnp_register_driver (&parport_pc_pnp_driver);
+		if (!err)
 			pnp_registered_parport = 1;
-			count += r;
-		}
 	}
 
 	/* ISA ports and whatever (see asm/parport.h). */
-	count += parport_pc_find_nonpci_ports (autoirq, autodma);
-
-	r = pci_register_driver (&parport_pc_pci_driver);
-	if (r)
-		return r;
-	pci_registered_parport = 1;
-	count += 1;
+	parport_pc_find_nonpci_ports (autoirq, autodma);
 
-	return count;
+	err = pci_register_driver (&parport_pc_pci_driver);
+	if (!err)
+		pci_registered_parport = 1;
 }
 
 /*
@@ -3381,8 +3375,6 @@
 
 static int __init parport_pc_init(void)
 {
-	int count = 0;
-
 	if (parse_parport_params())
 		return -EINVAL;
 
@@ -3395,12 +3387,11 @@
 				break;
 			if ((io_hi[i]) == PARPORT_IOHI_AUTO)
 			       io_hi[i] = 0x400 + io[i];
-			if (parport_pc_probe_port(io[i], io_hi[i],
-						  irqval[i], dmaval[i], NULL))
-				count++;
+			parport_pc_probe_port(io[i], io_hi[i],
+						  irqval[i], dmaval[i], NULL);
 		}
 	} else
-		count += parport_pc_find_ports (irqval[0], dmaval[0]);
+		parport_pc_find_ports (irqval[0], dmaval[0]);
 
 	return 0;
 }
#2 lore raw

PATCH 2/9 mpu401: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

sound/drivers/mpu401/mpu401.c +8 -8
Index: work-mm4/sound/drivers/mpu401/mpu401.c
===================================================================
@@ -59,7 +59,8 @@
 MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device.");
 
 static struct platform_device *platform_devices[SNDRV_CARDS];
-static int pnp_registered = 0;
+static int pnp_registered;
+static unsigned int snd_mpu401_devices;
 
 static int snd_mpu401_create(int dev, struct snd_card **rcard)
 {
@@ -197,6 +198,7 @@
 		}
 		snd_card_set_dev(card, &pnp_dev->dev);
 		pnp_set_drvdata(pnp_dev, card);
+		snd_mpu401_devices++;
 		++dev;
 		return 0;
 	}
@@ -234,12 +236,11 @@
 
 static int __init alsa_card_mpu401_init(void)
 {
-	int i, err, devices;
+	int i, err;
 
 	if ((err = platform_driver_register(&snd_mpu401_driver)) < 0)
 		return err;
 
-	devices = 0;
 	for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
 		struct platform_device *device;
 #ifdef CONFIG_PNP
@@ -253,14 +254,13 @@
 			goto errout;
 		}
 		platform_devices[i] = device;
-		devices++;
+		snd_mpu401_devices++;
 	}
-	if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) {
+	err = pnp_register_driver(&snd_mpu401_pnp_driver);
+	if (!err)
 		pnp_registered = 1;
-		devices += err;
-	}
 
-	if (!devices) {
+	if (!snd_mpu401_devices) {
 #ifdef MODULE
 		printk(KERN_ERR "MPU-401 device not found or device busy\n");
 #endif
#3 lore raw

PATCH 3/9 cs4236: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

sound/isa/cs423x/cs4236.c +12 -13
Index: work-mm4/sound/isa/cs423x/cs4236.c
===================================================================
@@ -133,6 +133,7 @@
 static int pnp_registered;
 #endif
 #endif /* CONFIG_PNP */
+static unsigned int snd_cs423x_devices;
 
 struct snd_card_cs4236 {
 	struct snd_cs4231 *chip;
@@ -564,7 +565,7 @@
 		snd_card_free(card);
 		return err;
 	}
-	
+
 	platform_set_drvdata(pdev, card);
 	return 0;
 }
@@ -650,6 +651,7 @@
 	}
 	pnp_set_drvdata(pdev, card);
 	dev++;
+	snd_cs423x_devices++;
 	return 0;
 }
 
@@ -713,6 +715,7 @@
 	}
 	pnp_set_card_drvdata(pcard, card);
 	dev++;
+	snd_cs423x_devices++;
 	return 0;
 }
 
@@ -721,7 +724,7 @@
 	snd_card_free(pnp_get_card_drvdata(pcard));
 	pnp_set_card_drvdata(pcard, NULL);
 }
-                        
+
 #ifdef CONFIG_PM
 static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
 {
@@ -766,7 +769,7 @@
 
 static int __init alsa_card_cs423x_init(void)
 {
-	int i, err, cards = 0;
+	int i, err;
 
 	if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0)
 		return err;
@@ -782,24 +785,20 @@
 			goto errout;
 		}
 		platform_devices[i] = device;
-		cards++;
+		snd_cs423x_devices++;
 	}
 #ifdef CONFIG_PNP
 #ifdef CS4232
-	i = pnp_register_driver(&cs4232_pnp_driver);
-	if (i >= 0) {
+	err = pnp_register_driver(&cs4232_pnp_driver);
+	if (!err)
 		pnp_registered = 1;
-		cards += i;
-	}
 #endif
-	i = pnp_register_card_driver(&cs423x_pnpc_driver);
-	if (i >= 0) {
+	err = pnp_register_card_driver(&cs423x_pnpc_driver);
+	if (!err)
 		pnpc_registered = 1;
-		cards += i;
-	}
 #endif /* CONFIG_PNP */
 
-	if (!cards) {
+	if (!snd_cs423x_devices) {
 #ifdef MODULE
 		printk(KERN_ERR IDENT " soundcard not found or device busy\n");
 #endif
#4 lore raw

PATCH 4/9 opl3sa2: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

Index: work-mm4/sound/isa/opl3sa2.c
=================================--- work-mm4.orig/sound/isa/opl3sa2.c 2006-02-01 16:24:54.000000000 -0700
+++ work-mm4/sound/isa/opl3sa2.c 2006-02-15 10:11:17.000000000 -0700
@@ -95,6 +95,7 @@
static int pnp_registered;
static int pnpc_registered;
#endif
+static unsigned int snd_opl3sa2_devices;

/* control ports */
#define OPL3SA2_PM_CTRL 0x01
@@ -760,6 +761,7 @@
}
pnp_set_drvdata(pdev, card);
dev++;
+ snd_opl3sa2_devices++;
return 0;
}

@@ -826,6 +828,7 @@
}
pnp_set_card_drvdata(pcard, card);
dev++;
+ snd_opl3sa2_devices++;
return 0;
}

@@ -944,7 +947,7 @@

static int __init alsa_card_opl3sa2_init(void)
{
- int i, err, cards = 0;
+ int i, err;

if ((err = platform_driver_register(&snd_opl3sa2_nonpnp_driver)) < 0)
return err;
@@ -962,23 +965,19 @@
goto errout;
}
platform_devices[i] = device;
- cards++;
+ snd_opl3sa2_devices++;
}

#ifdef CONFIG_PNP
err = pnp_register_driver(&opl3sa2_pnp_driver);
- if (err >= 0) {
+ if (!err)
pnp_registered = 1;
- cards += err;
- }
err = pnp_register_card_driver(&opl3sa2_pnpc_driver);
- if (err >= 0) {
+ if (!err)
pnpc_registered = 1;
- cards += err;
- }
#endif

- if (!cards) {
+ if (!snd_opl3sa2_devices) {
#ifdef MODULE
snd_printk(KERN_ERR "Yamaha OPL3-SA soundcard not found or device busy\n");
#endif

#5 lore raw

PATCH 5/9 ns558: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

drivers/input/gameport/ns558.c +3 -2
Index: work-mm4/drivers/input/gameport/ns558.c
===================================================================
@@ -256,9 +256,10 @@
 
 static int __init ns558_init(void)
 {
-	int i = 0;
+	int i = 0, err;
 
-	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
+	err = pnp_register_driver(&ns558_pnp_driver);
+	if (!err)
 		pnp_registered = 1;
 
 /*
#6 lore raw

Re: [PATCH 5/9] ns558: adjust pnp_register_driver signature

Quoted 4 lines · Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

Wouldn't a diff like

drivers/input/gameport/ns558.c +1 -1
@@ -258,7 +256,7 @@
 {
 	int i = 0;
 
-	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
+	if (!pnp_register_driver(&ns558_pnp_driver))
 		pnp_registered = 1;
  
  /*

be enough? The err variable isn't used anywhere else.

Quoted 19 lines

Index: work-mm4/drivers/input/gameport/ns558.c
===================================================================

drivers/input/gameport/ns558.c +3 -2
@@ -256,9 +256,10 @@
 
 static int __init ns558_init(void)
 {
-	int i = 0;
+	int i = 0, err;
 
-	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
+	err = pnp_register_driver(&ns558_pnp_driver);
+	if (!err)
 		pnp_registered = 1;
 
 /*
Signature · 2 lines
Vojtech Pavlik
Director SuSE Labs
#7 lore raw

Re: [PATCH 5/9] ns558: adjust pnp_register_driver signature

Quoted 20 lines · Vojtech Pavlik
Quoted 4 lines · Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

Wouldn't a diff like

drivers/input/gameport/ns558.c +1 -1
@@ -258,7 +256,7 @@
 {
 	int i = 0;
 
-	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
+	if (!pnp_register_driver(&ns558_pnp_driver))
 		pnp_registered = 1;
 
  /*
Quoted 1 line

be enough? The err variable isn't used anywhere else.

Yup, that'd be fine, and in fact my first version of the patch did just that. I introduced "err" because most of the other drivers I had to touch used "err," and it seemed a bit clearer to me because it gives an extra hint that pnp_register_driver() returns only an error code.

But I don't care either way, so say the word, and I'll send Andrew your patch to replace mine.

Bjorn

Quoted 20 lines
Quoted 19 lines

Index: work-mm4/drivers/input/gameport/ns558.c
===================================================================

drivers/input/gameport/ns558.c +3 -2
@@ -256,9 +256,10 @@
 
 static int __init ns558_init(void)
 {
-	int i = 0;
+	int i = 0, err;
 
-	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
+	err = pnp_register_driver(&ns558_pnp_driver);
+	if (!err)
 		pnp_registered = 1;
 
 /*
#8 lore raw

PATCH 6/9 i8042: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

drivers/input/serio/i8042-x86ia64io.h +16 -10
Index: work-mm4/drivers/input/serio/i8042-x86ia64io.h
===================================================================
@@ -192,7 +192,9 @@
 #include <linux/pnp.h>
 
 static int i8042_pnp_kbd_registered;
+static unsigned int i8042_pnp_kbd_devices;
 static int i8042_pnp_aux_registered;
+static unsigned int i8042_pnp_aux_devices;
 
 static int i8042_pnp_command_reg;
 static int i8042_pnp_data_reg;
@@ -219,6 +221,7 @@
 		strncat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name));
 	}
 
+	i8042_pnp_kbd_devices++;
 	return 0;
 }
 
@@ -239,6 +242,7 @@
 		strncat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name));
 	}
 
+	i8042_pnp_aux_devices++;
 	return 0;
 }
 
@@ -287,21 +291,23 @@
 
 static int __init i8042_pnp_init(void)
 {
-	int result_kbd = 0, result_aux = 0;
 	char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 };
+	int err;
 
 	if (i8042_nopnp) {
 		printk(KERN_INFO "i8042: PNP detection disabled\n");
 		return 0;
 	}
 
-	if ((result_kbd = pnp_register_driver(&i8042_pnp_kbd_driver)) >= 0)
+	err = pnp_register_driver(&i8042_pnp_kbd_driver);
+	if (!err)
 		i8042_pnp_kbd_registered = 1;
 
-	if ((result_aux = pnp_register_driver(&i8042_pnp_aux_driver)) >= 0)
+	err = pnp_register_driver(&i8042_pnp_aux_driver);
+	if (!err)
 		i8042_pnp_aux_registered = 1;
 
-	if (result_kbd <= 0 && result_aux <= 0) {
+	if (!i8042_pnp_kbd_devices && !i8042_pnp_aux_devices) {
 		i8042_pnp_exit();
 #if defined(__ia64__)
 		return -ENODEV;
@@ -311,24 +317,24 @@
 #endif
 	}
 
-	if (result_kbd > 0)
+	if (i8042_pnp_kbd_devices)
 		snprintf(kbd_irq_str, sizeof(kbd_irq_str),
 			"%d", i8042_pnp_kbd_irq);
-	if (result_aux > 0)
+	if (i8042_pnp_aux_devices)
 		snprintf(aux_irq_str, sizeof(aux_irq_str),
 			"%d", i8042_pnp_aux_irq);
 
 	printk(KERN_INFO "PNP: PS/2 Controller [%s%s%s] at %#x,%#x irq %s%s%s\n",
-		i8042_pnp_kbd_name, (result_kbd > 0 && result_aux > 0) ? "," : "",
+		i8042_pnp_kbd_name, (i8042_pnp_kbd_devices && i8042_pnp_aux_devices) ? "," : "",
 		i8042_pnp_aux_name,
 		i8042_pnp_data_reg, i8042_pnp_command_reg,
-		kbd_irq_str, (result_kbd > 0 && result_aux > 0) ? "," : "",
+		kbd_irq_str, (i8042_pnp_kbd_devices && i8042_pnp_aux_devices) ? "," : "",
 		aux_irq_str);
 
 #if defined(__ia64__)
-	if (result_kbd <= 0)
+	if (!i8042_pnp_kbd_devices)
 		i8042_nokbd = 1;
-	if (result_aux <= 0)
+	if (!i8042_pnp_aux_devices)
 		i8042_noaux = 1;
 #endif
 
#9 lore raw

Re: [PATCH 6/9] i8042: adjust pnp_register_driver signature

Quoted 3 lines · Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

Applied, thank you Bjorn.

Signature · 1 line
Dmitry
#10 lore raw

PATCH 7/9 IRDA: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

drivers/net/irda/nsc-ircc.c +1 -1
Index: work-mm4/drivers/net/irda/nsc-ircc.c
===================================================================
@@ -207,7 +207,7 @@
  	/* Register with PnP subsystem to detect disable ports */
 	ret = pnp_register_driver(&nsc_ircc_pnp_driver);
 
- 	if (ret >= 0)
+ 	if (!ret)
  		pnp_registered = 1;
 
 	ret = -ENODEV;
#11 lore raw

PATCH 8/9 cs4232: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed.

sound/oss/cs4232.c +10 -5
Index: work-mm4/sound/oss/cs4232.c
===================================================================
@@ -360,6 +360,8 @@
 static int __initdata synthirq	= -1;
 static int __initdata isapnp	= 1;
 
+static unsigned int cs4232_devices;
+
 MODULE_DESCRIPTION("CS4232 based soundcard driver"); 
 MODULE_AUTHOR("Hannu Savolainen, Paul Barton-Davis"); 
 MODULE_LICENSE("GPL");
@@ -421,6 +423,7 @@
 		return -ENODEV;
 	}
 	pnp_set_drvdata(dev,isapnpcfg);
+	cs4232_devices++;
 	return 0;
 }
 
@@ -455,10 +458,11 @@
 #endif
 	cfg.irq = -1;
 
-	if (isapnp &&
-	    (pnp_register_driver(&cs4232_driver) > 0)
-	)
-		return 0;
+	if (isapnp) {
+		pnp_register_driver(&cs4232_driver);
+		if (cs4232_devices)
+			return 0;
+	}
 
 	if(io==-1||irq==-1||dma==-1)
 	{
@@ -503,7 +507,8 @@
 	int ints[7];
 
 	/* If we have isapnp cards, no need for options */
-	if (pnp_register_driver(&cs4232_driver) > 0)
+	pnp_register_driver(&cs4232_driver);
+	if (cs4232_devices)
 		return 1;
 	
 	str = get_options(str, ARRAY_SIZE(ints), ints);
#12 lore raw

PATCH 9/9 PNP: adjust pnp_register_driver signature

In reply to Bjorn Helgaas

Remove the assumption that pnp_register_driver() returns the number of devices claimed. Returning the count is unreliable because devices may be hot-plugged in the future.

This changes the convention to "zero for success, or a negative error value," which matches pci_register_driver(), acpi_bus_register_driver(), and platform_driver_register().

drivers/pnp/driver.c +1 -18
Index: work-mm4/drivers/pnp/driver.c
===================================================================
@@ -201,31 +201,14 @@
 	.resume = pnp_bus_resume,
 };
 
-
-static int count_devices(struct device * dev, void * c)
-{
-	int * count = c;
-	(*count)++;
-	return 0;
-}
-
 int pnp_register_driver(struct pnp_driver *drv)
 {
-	int count;
-
 	pnp_dbg("the driver '%s' has been registered", drv->name);
 
 	drv->driver.name = drv->name;
 	drv->driver.bus = &pnp_bus_type;
 
-	count = driver_register(&drv->driver);
-
-	/* get the number of initial matches */
-	if (count >= 0){
-		count = 0;
-		driver_for_each_device(&drv->driver, NULL, &count, count_devices);
-	}
-	return count;
+	return driver_register(&drv->driver);
 }
 
 void pnp_unregister_driver(struct pnp_driver *drv)
drivers/pnp/card.c +7 -9
Index: work-mm4/drivers/pnp/card.c
===================================================================
@@ -47,7 +47,7 @@
 {
 	dev->card_link = NULL;
 }
- 
+
 static void card_remove_first(struct pnp_dev * dev)
 {
 	struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver);
@@ -373,7 +373,7 @@
 
 int pnp_register_card_driver(struct pnp_card_driver * drv)
 {
-	int count;
+	int error;
 	struct list_head *pos, *temp;
 
 	drv->link.name = drv->name;
@@ -384,21 +384,19 @@
 	drv->link.suspend = drv->suspend ? card_suspend : NULL;
 	drv->link.resume = drv->resume ? card_resume : NULL;
 
-	count = pnp_register_driver(&drv->link);
-	if (count < 0)
-		return count;
+	error = pnp_register_driver(&drv->link);
+	if (error < 0)
+		return error;
 
 	spin_lock(&pnp_lock);
 	list_add_tail(&drv->global_list, &pnp_card_drivers);
 	spin_unlock(&pnp_lock);
 
-	count = 0;
-
 	list_for_each_safe(pos,temp,&pnp_cards){
 		struct pnp_card *card = list_entry(pos, struct pnp_card, global_list);
-		count += card_probe(card,drv);
+		card_probe(card,drv);
 	}
-	return count;
+	return 0;
 }
 
 /**
Documentation/pnp.txt +3 -0
Index: work-mm4/Documentation/pnp.txt
===================================================================
@@ -115,6 +115,9 @@
 pnp_register_driver
 - adds a PnP driver to the Plug and Play Layer
 - this includes driver model integration
+- returns zero for success or a negative error number for failure; count
+  calls to the .add() method if you need to know how many devices bind to
+  the driver
 
 pnp_unregister_driver
 - removes a PnP driver from the Plug and Play Layer
#13 lore raw
In reply to Bjorn Helgaas
Quoted 11 lines · Bjorn Helgaas

This series of patches removes the assumption that pnp_register_driver() returns the number of devices claimed. Returning the count is unreliable because devices may be hot-plugged in the future. (Many devices don't support hot-plug, of course, but PNP in general does.)

This changes the convention to "zero for success, or a negative error value," which matches pci_register_driver(), acpi_bus_register_driver(), and platform_driver_register().

If drivers need to know the number of devices, they can count calls to their .probe() methods.

Andrew, I'd appreciate if you add this to mainline when it's convenient to make non-critical changes.

Thanks,
Adam