New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 868424 link

Starred by 1 user

Issue metadata

Status: Available
Owner:
Last visit > 30 days ago
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 3
Type: Feature



Sign in to add a comment

power: usb: expose over-current events on USB

Project Member Reported by tbroch@chromium.org, Jul 27

Issue description

Dtor pointed out this patch,

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/diff/?h=v4.17.10&id=1cbd53c8cd85a63383a075347abee8f6e3f14fbe

which can expose over-current counter via sysfs.

Lets land it and look into how we could use this info to enlighten users & developers alike about these undesirable events on USB devices.
 
Cc: jflat@chromium.org bleung@chromium.org
This could be a good starter bug for jflat@.
Labels: -Type-Bug Type-Feature
Cc: dtor@chromium.org
Here's the commit description from upstream btw:

commit 1cbd53c8cd85a63383a075347abee8f6e3f14fbe
Author: Richard Leitner <richard.leitner@skidata.com>
Date:   Tue Mar 20 11:17:13 2018 +0100

    usb: core: introduce per-port over-current counters
    
    For some userspace applications information on the number of
    over-current conditions at specific USB hub ports is relevant.
    
    In our case we have a series of USB hardware (using the cp210x driver)
    which communicates using a proprietary protocol. These devices sometimes
    trigger an over-current situation on some hubs. In case of such an
    over-current situation the USB devices offer an interface for reducing
    the max used power. As these conditions are quite rare and imply
    performance reductions of the device we don't want to reduce the max
    power always.
    
    Therefore give user-space applications the possibility to react
    adequately by introducing an over_current_counter in the usb port struct
    which is exported via sysfs.
    
    Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Status: Available (was: Assigned)
Here's backport for review: crrev.com/c/1153479

Haven't had time to dig how we'd expose beyond this so marking available if there's interest from others in pursuing 
Cc: tbroch@chromium.org
Owner: jflat@chromium.org
A few more patches landed upstream that expose this as a udev event and add poll() support for this sysfs attribute.

Here are the backports:
crrev.com/c/1308686
crrev.com/c/1308687

Project Member

Comment 8 by bugdroid1@chromium.org, Nov 1

Labels: merge-merged-chromeos-4.4
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/9d33ca9a9bc91197820b88f35c8ecf6d857a09da

commit 9d33ca9a9bc91197820b88f35c8ecf6d857a09da
Author: Richard Leitner <richard.leitner@skidata.com>
Date: Thu Nov 01 23:24:43 2018

BACKPORT: usb: core: introduce per-port over-current counters

For some userspace applications information on the number of
over-current conditions at specific USB hub ports is relevant.

In our case we have a series of USB hardware (using the cp210x driver)
which communicates using a proprietary protocol. These devices sometimes
trigger an over-current situation on some hubs. In case of such an
over-current situation the USB devices offer an interface for reducing
the max used power. As these conditions are quite rare and imply
performance reductions of the device we don't want to reduce the max
power always.

Therefore give user-space applications the possibility to react
adequately by introducing an over_current_counter in the usb port struct
which is exported via sysfs.

Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 1cbd53c8cd85a63383a075347abee8f6e3f14fbe)
Signed-off-by: Todd Broch <tbroch@chromium.org>

Conflicts (trivial w/ 0a3a4c2):
	Documentation/ABI/testing/sysfs-bus-usb
	drivers/usb/core/port.c

BUG=chromium:868424
TEST=manual,
  for f in `find /sys/devices -name "over_current_count"`; do
    ls -altr $f
    cat $f
  done

Change-Id: Icada1bcdfd4578f7ad69c72e2b81b4902f28994e
Reviewed-on: https://chromium-review.googlesource.com/1153479
Commit-Ready: Jon Flatley <jflat@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>

[modify] https://crrev.com/9d33ca9a9bc91197820b88f35c8ecf6d857a09da/drivers/usb/core/port.c
[modify] https://crrev.com/9d33ca9a9bc91197820b88f35c8ecf6d857a09da/drivers/usb/core/hub.h
[modify] https://crrev.com/9d33ca9a9bc91197820b88f35c8ecf6d857a09da/Documentation/ABI/testing/sysfs-bus-usb
[modify] https://crrev.com/9d33ca9a9bc91197820b88f35c8ecf6d857a09da/drivers/usb/core/hub.c

Project Member

Comment 9 by bugdroid1@chromium.org, Nov 1

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/c6ce198627fc08e0a5afe67ada9d67e294d1816a

commit c6ce198627fc08e0a5afe67ada9d67e294d1816a
Author: Jon Flatley <jflat@chromium.org>
Date: Thu Nov 01 23:24:45 2018

BACKPORT: usb: core: added uevent for over-current

After commit 1cbd53c8cd85 ("usb: core: introduce per-port over-current
counters") usb ports expose a sysfs value 'over_current_count'
to user space. This value on its own is not very useful as it requires
manual polling.

As a solution, fire a udev event from the usb hub device that specifies
the values 'OVER_CURRENT_PORT' and 'OVER_CURRENT_COUNT' that indicate
the path of the usb port where the over-current event occurred and the
value of 'over_current_count' in sysfs. Additionally, call
sysfs_notify() so the sysfs value supports poll().

Signed-off-by: Jon Flatley <jflat@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 201af55da8a3986297d7c3493f839dfc96ffd7db)

BUG=chromium:868424
TEST=None

Change-Id: Ia81c6955817f6c10903a5ffe55842093e582b8a6
Reviewed-on: https://chromium-review.googlesource.com/1308686
Commit-Ready: Jon Flatley <jflat@chromium.org>
Tested-by: Jon Flatley <jflat@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>

[modify] https://crrev.com/c6ce198627fc08e0a5afe67ada9d67e294d1816a/Documentation/ABI/testing/sysfs-bus-usb
[modify] https://crrev.com/c6ce198627fc08e0a5afe67ada9d67e294d1816a/drivers/usb/core/hub.c

Project Member

Comment 10 by bugdroid1@chromium.org, Nov 1

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/9be248d8f9906e6edd979582868272aa3d1b647c

commit 9be248d8f9906e6edd979582868272aa3d1b647c
Author: Colin Ian King <colin.king@canonical.com>
Date: Thu Nov 01 23:24:46 2018

UPSTREAM: usb: core: fix memory leak on port_dev_path allocation

Currently the allocation of port_dev_path from the call to
kobject_get_path is not being kfree'd, causing a memory leak. Fix
this by kfree'ing this at the end of the function. Add an extra
error exit path to fix one of the early leaks when envp[0] fails
to be allocated.

Detected by CoverityScan, CID#1473771 ("Resource Leak")

Fixes: 201af55da8a3 ("usb: core: added uevent for over-current")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit bf7f547ecdd707e7b4fcbc467b4f9ddb29915391)
Signed-off-by: Jon Flatley <jflat@chromium.org>

BUG=chromium:868424
TEST=None

Change-Id: I93f6cb32c43cd553f0a6f664675d4694375822ed
Reviewed-on: https://chromium-review.googlesource.com/1308687
Commit-Ready: Jon Flatley <jflat@chromium.org>
Tested-by: Jon Flatley <jflat@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>

[modify] https://crrev.com/9be248d8f9906e6edd979582868272aa3d1b647c/drivers/usb/core/hub.c

Sign in to add a comment