Arvid Brodin wrote: > What's the best way to get a notification in user space when an overcurrent > event occurs on a usb port? The idea is to let a user application notify > the user that something is wrong. Long time ago (linux-2.6.36) we did this in one of our projects, to forward this event to userland. From: Juergen Beisert <jbe@xxxxxxxxxxxxxx> Date: Wed, 11 Aug 2010 14:18:04 +0200 Subject: [PATCH] Generate a uevent when an overcurrent event happens This quick hack generates a 'uevent' to userland and adds the 'POWERFAIL=1' environment variable for this report. Any userland program listening to the 'uevent' interface can filter for the presence of this environment variable to distinguish this special 'uevent' from other 'add' or 'remove' events. Current disadvantage: Due to the fact, the hub driver tries to enable the port again immediately (it does not wait for user interaction) this powerfail event gets reported twice: First time when it really happens and second time when the external overcurrent detection device will be reset. The second false positive report must be sorted out by the userland application. Signed-off-by: Juergen Beisert <jbe@xxxxxxxxxxxxxx> Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx> --- drivers/usb/core/hub.c | 4 ++++ 1 file changed, 4 insertions(+), 0 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 84c18971..c615292 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3372,9 +3372,13 @@ static void hub_events(void) } if (portchange & USB_PORT_STAT_C_OVERCURRENT) { + char event[] = "POWERFAIL=1"; + char *envp[] = { event, NULL }; + dev_err (hub_dev, "over-current change on port %d\n", i); + kobject_uevent_env(&hub->intfdev->kobj, KOBJ_CHANGE, envp); clear_port_feature(hdev, i, USB_PORT_FEAT_C_OVER_CURRENT); hub_power_on(hub, true); It seems the overcurrent case is an important event. So we really should think about how to report it to userland in useful manner. Alan Stern wrote: > There are plenty of error conditions that the kernel does not export to > userspace. Sure. But IMHO sometimes it would be really nice, to have a reliable API to filter for some error conditions, than some ugly regular expressions for kernel messages. Regards, Juergen -- Pengutronix e.K. | Juergen Beisert | Linux Solutions for Science and Industry | Phone: +49-5121-206917-5128 | Vertretung Sued/Muenchen, Germany | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html