diff options
author | Rafał Miłecki <zajec5@gmail.com> | 2016-07-18 17:59:27 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2016-07-20 10:13:50 +0200 |
commit | 5ea8756766a5ba148e47075265743f727ef1d6dc (patch) | |
tree | b67042f2fdccc82b059551433a154d1356e6154a /target/linux/generic/files/drivers/leds | |
parent | e633a1b48f8504a17ea1d2d89ed760da03e41380 (diff) | |
download | mtk-20170518-5ea8756766a5ba148e47075265743f727ef1d6dc.zip mtk-20170518-5ea8756766a5ba148e47075265743f727ef1d6dc.tar.gz mtk-20170518-5ea8756766a5ba148e47075265743f727ef1d6dc.tar.bz2 |
ledtrig-usbdev: use upstream function for iterating USB devices
This will allow us to drop LEDE patch adding usb_find_device_by_name.
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Diffstat (limited to 'target/linux/generic/files/drivers/leds')
-rw-r--r-- | target/linux/generic/files/drivers/leds/ledtrig-usbdev.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/target/linux/generic/files/drivers/leds/ledtrig-usbdev.c b/target/linux/generic/files/drivers/leds/ledtrig-usbdev.c index 70b0e39..effcae6 100644 --- a/target/linux/generic/files/drivers/leds/ledtrig-usbdev.c +++ b/target/linux/generic/files/drivers/leds/ledtrig-usbdev.c @@ -83,6 +83,26 @@ static ssize_t usbdev_trig_name_show(struct device *dev, return strlen(buf) + 1; } +struct usbdev_trig_match { + char *device_name; + struct usb_device *usb_dev; +}; + +static int usbdev_trig_find_usb_dev(struct usb_device *usb_dev, void *data) +{ + struct usbdev_trig_match *match = data; + + if (WARN_ON(match->usb_dev)) + return 0; + + if (!strcmp(dev_name(&usb_dev->dev), match->device_name)) { + dev_dbg(&usb_dev->dev, "matched this device!\n"); + match->usb_dev = usb_get_dev(usb_dev); + } + + return 0; +} + static ssize_t usbdev_trig_name_store(struct device *dev, struct device_attribute *attr, const char *buf, @@ -101,16 +121,18 @@ static ssize_t usbdev_trig_name_store(struct device *dev, td->device_name[size - 1] = 0; if (td->device_name[0] != 0) { - struct usb_device *usb_dev; + struct usbdev_trig_match match = { + .device_name = td->device_name, + }; /* check for existing device to update from */ - usb_dev = usb_find_device_by_name(td->device_name); - if (usb_dev) { + usb_for_each_dev(&match, usbdev_trig_find_usb_dev); + if (match.usb_dev) { if (td->usb_dev) usb_put_dev(td->usb_dev); - td->usb_dev = usb_dev; - td->last_urbnum = atomic_read(&usb_dev->urbnum); + td->usb_dev = match.usb_dev; + td->last_urbnum = atomic_read(&match.usb_dev->urbnum); } /* updates LEDs, may start timers */ |