Skip to contentSkip to conversation

ns558 bug

PATCH In review matthieu castet 4 participants 9 messages Feb 4, 2005 – Feb 7, 2005 Input drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ns558 bug

Hi,

this patch is based on http://bugzilla.kernel.org/show_bug.cgi?id=2962 patch from adam belay.

It solve a oops when pnp_register_driver(&ns558_pnp_driver) failed.

Please apply this patch.

Matthieu

Index: drivers/input/gameport/ns558.c
===================================================================
RCS file: /home/mat/dev/linux-cvs-rep/linux-cvs/drivers/input/gameport/ns558.c,v retrieving revision 1.15

input/gameport/ns558.c +8 -3
diff -u -u -r1.15 ns558.c
@@ -261,6 +261,8 @@
 
 #endif
 
+static int registered = 0;
+
 int __init ns558_init(void)
 {
 	int i = 0;
@@ -272,8 +274,10 @@
 	while (ns558_isa_portlist[i])
 		ns558_isa_probe(ns558_isa_portlist[i++]);
 
-	pnp_register_driver(&ns558_pnp_driver);
-	return list_empty(&ns558_list) ? -ENODEV : 0;
+	if (pnp_register_driver(&ns558_pnp_driver) >= 0) 
+		registered = 1;
+
+	return (list_empty(&ns558_list) && !registered) ? -ENODEV : 0;
 }
 
 void __exit ns558_exit(void)
@@ -297,7 +301,8 @@
 				break;
 		}
 	}
-	pnp_unregister_driver(&ns558_pnp_driver);
+	if (registered)
+		pnp_unregister_driver(&ns558_pnp_driver);
 }
 
 module_init(ns558_init);
#1 lore raw
Quoted 10 lines · matthieu castet

Hi,

this patch is based on http://bugzilla.kernel.org/show_bug.cgi?id=2962
patch from adam belay.

It solve a oops when pnp_register_driver(&ns558_pnp_driver) failed.

Please apply this patch.

Matthieu

I remember writing a version of this patch a while ago. The current behavior is broken because it shouldn't be considered a failure if the driver doesn't find any devices.

Thanks,
Adam

Quoted 39 lines

Index: drivers/input/gameport/ns558.c
===================================================================
RCS file: /home/mat/dev/linux-cvs-rep/linux-cvs/drivers/input/gameport/ns558.c,v retrieving revision 1.15
diff -u -u -r1.15 ns558.c

input/gameport/ns558.c +8 -3
@@ -261,6 +261,8 @@
 
 #endif
 
+static int registered = 0;
+
 int __init ns558_init(void)
 {
 	int i = 0;
@@ -272,8 +274,10 @@
 	while (ns558_isa_portlist[i])
 		ns558_isa_probe(ns558_isa_portlist[i++]);
 
-	pnp_register_driver(&ns558_pnp_driver);
-	return list_empty(&ns558_list) ? -ENODEV : 0;
+	if (pnp_register_driver(&ns558_pnp_driver) >= 0) 
+		registered = 1;
+
+	return (list_empty(&ns558_list) && !registered) ? -ENODEV : 0;
 }
 
 void __exit ns558_exit(void)
@@ -297,7 +301,8 @@
 				break;
 		}
 	}
-	pnp_unregister_driver(&ns558_pnp_driver);
+	if (registered)
+		pnp_unregister_driver(&ns558_pnp_driver);
 }
 
 module_init(ns558_init);
#2 lore raw
Quoted 9 lines · [email protected] (Adam Belay) wrote:
Quoted 7 lines · matthieu castet

Hi,

this patch is based on http://bugzilla.kernel.org/show_bug.cgi?id=2962
patch from adam belay.

It solve a oops when pnp_register_driver(&ns558_pnp_driver) failed.

Quoted 7 lines
Quoted 3 lines

Please apply this patch.

Matthieu

I remember writing a version of this patch a while ago. The current behavior is broken because it shouldn't be considered a failure if the driver doesn't find any devices.

So would this be the appropriate fix?

drivers/input/gameport/ns558.c renamed from drivers/input/gameport/ns558.c~ns558-oops-fix +3 -2
@@ -264,6 +264,7 @@ static struct pnp_driver ns558_pnp_drive
 static int __init ns558_init(void)
 {
 	int i = 0;
+	int ret;
 
 /*
  * Probe for ISA ports.
@@ -272,8 +273,8 @@ static int __init ns558_init(void)
 	while (ns558_isa_portlist[i])
 		ns558_isa_probe(ns558_isa_portlist[i++]);
 
-	pnp_register_driver(&ns558_pnp_driver);
-	return list_empty(&ns558_list) ? -ENODEV : 0;
+	ret = pnp_register_driver(&ns558_pnp_driver);
+	return (ret < 0) ? ret : 0;
 }
 
 static void __exit ns558_exit(void)

_

#3 lore raw

On Fri, Feb 04, 2005 at 07:06:14PM -0800, Andrew Morton wrote:

It looks ok. My only concern is what would happen if the isa probe succeded but the pnp_register_driver failed? "pnp_register_driver" return -ENODEV if "CONFIG_PNP" isn't enabled. Do you think this would conflict with legacy probing?

Thanks,
Adam

Quoted 24 lines

So would this be the appropriate fix?

drivers/input/gameport/ns558.c renamed from drivers/input/gameport/ns558.c~ns558-oops-fix +3 -2
@@ -264,6 +264,7 @@ static struct pnp_driver ns558_pnp_drive
 static int __init ns558_init(void)
 {
 	int i = 0;
+	int ret;
 
 /*
  * Probe for ISA ports.
@@ -272,8 +273,8 @@ static int __init ns558_init(void)
 	while (ns558_isa_portlist[i])
 		ns558_isa_probe(ns558_isa_portlist[i++]);
 
-	pnp_register_driver(&ns558_pnp_driver);
-	return list_empty(&ns558_list) ? -ENODEV : 0;
+	ret = pnp_register_driver(&ns558_pnp_driver);
+	return (ret < 0) ? ret : 0;
 }
 
 static void __exit ns558_exit(void)

_

#4 lore raw
Quoted 5 lines · [email protected] (Adam Belay) wrote:

It looks ok. My only concern is what would happen if the isa probe succeded but the pnp_register_driver failed? "pnp_register_driver" return -ENODEV if "CONFIG_PNP" isn't enabled. Do you think this would conflict with legacy probing?

Fair enough. How about this?

static void ns588_unregister_ports(void)

{
	struct ns558 *port;

	list_for_each_entry(port, &ns558_list, node) {
		gameport_unregister_port(&port->gameport);
		switch (port->type) {
#ifdef CONFIG_PNP
			case NS558_PNP:
				/* fall through */
#endif
			case NS558_ISA:
				release_region(port->gameport.io &
					~(port->size - 1), port->size);
				kfree(port);
				break;

			default:
				break;
		}
	}
}

static int __init ns558_init(void)

{
	int i = 0;
	int ret;

/*
* Probe for ISA ports.
*/

	while (ns558_isa_portlist[i])
		ns558_isa_probe(ns558_isa_portlist[i++]);

	ret = pnp_register_driver(&ns558_pnp_driver);
	if (ret < 0) {
		ns588_unregister_ports();
		return ret;
	}
	return 0;
}

static void __exit ns558_exit(void)

{
	ns588_unregister_ports();
	pnp_unregister_driver(&ns558_pnp_driver);
}
#5 lore raw
Quoted 8 lines · Andrew Morton
Quoted 5 lines · [email protected] (Adam Belay) wrote:

It looks ok. My only concern is what would happen if the isa probe succeded but the pnp_register_driver failed? "pnp_register_driver" return -ENODEV if "CONFIG_PNP" isn't enabled. Do you think this would conflict with legacy probing?

Fair enough. How about this?

The code no longer is leaking devices. I may be overlooking something, but I think it still doesn't retain legacy probed devices when PnP isn't available.

If "pnp_register_driver" fails then "ns588_unregister_ports" will unregister the correctly detected ISA ports. "pnp_register_driver" will always fail if pnp support isn't compiled into the kernel. We need a way of not unregistering "ns558_pnp_driver" in "ns558_exit" but retaining the ports detected by the legacy probe. In a way, this is sort of a driver model problem.

As a more general solution for all drivers, I've been thinking about doing something like this in the long term.

int ret;
if (!(ret = register_driver(&ns558_driver)))

	return ret;

add_driver_protocol(&ns558_driver, &ns558_pnp);
add_driver_protocol(&ns558_driver, &ns558_isa);

and then on exit:

unregister_driver(&ns558_driver); /* this tears down any successfully
registered bus protocol automatically */

For now a less invasive solution might be better.

Comments?

Thanks,
Adam

Quoted 50 lines

static void ns588_unregister_ports(void)

{
	struct ns558 *port;

	list_for_each_entry(port, &ns558_list, node) {
		gameport_unregister_port(&port->gameport);
		switch (port->type) {
#ifdef CONFIG_PNP
			case NS558_PNP:
				/* fall through */
#endif
			case NS558_ISA:
				release_region(port->gameport.io &
					~(port->size - 1), port->size);
				kfree(port);
				break;

			default:
				break;
		}
	}
}

static int __init ns558_init(void)

{
	int i = 0;
	int ret;

/*
* Probe for ISA ports.
*/

	while (ns558_isa_portlist[i])
		ns558_isa_probe(ns558_isa_portlist[i++]);

	ret = pnp_register_driver(&ns558_pnp_driver);
	if (ret < 0) {
		ns588_unregister_ports();
		return ret;
	}
	return 0;
}

static void __exit ns558_exit(void)

{
	ns588_unregister_ports();
	pnp_unregister_driver(&ns558_pnp_driver);
}
#6 lore raw
Quoted 7 lines · [email protected] (Adam Belay) wrote:

As a more general solution for all drivers, I've been thinking about doing something like this in the long term.

int ret;
if (!(ret = register_driver(&ns558_driver)))

(quoted diff) +0 -0
 	return ret;

Review

Quoted 10 lines
(quoted diff) +0 -0
 add_driver_protocol(&ns558_driver, &ns558_pnp);
 add_driver_protocol(&ns558_driver, &ns558_isa);
 
 and then on exit:
 
 unregister_driver(&ns558_driver); /* this tears down any successfully
 				     registered bus protocol automatically */
 
 
 For now a less invasive solution might be better.

Well the thing oopses the kernel at present. Your call, Adam. Something to make it work acceptably for now would suit.

#7 lore raw
In reply to Andrew Morton

Hi,

Quoted 9 lines · Andrew Morton
Quoted 7 lines · [email protected] (Adam Belay) wrote:
Quoted 6 lines · matthieu castet

Hi,

this patch is based on http://bugzilla.kernel.org/show_bug.cgi?id=2962 patch from adam belay.

It solve a oops when pnp_register_driver(&ns558_pnp_driver) failed.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Please apply this patch.

Matthieu

I remember writing a version of this patch a while ago. The current behavior is broken because it shouldn't be considered a failure if the driver doesn't find any devices.

Why ?
If isa detection failed, the modules could not find any new isa devices. If the pnp detection find no device, the module is load.
If it is the kernel modules behaviour, lot's of modules are broken...

If you want that, why not simply alway "return 0" in the __init like it is done in the bugzilla patch ?

Matthieu