[PATCH v2 00/21] USB: refactor endpoint retrieval

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Many USB drivers iterate over the available endpoints to find required
endpoints of a specific type and direction. Typically the endpoints are
required for proper function and a missing endpoint should abort probe.

To facilitate code reuse, this series adds a helper to retrieve common
endpoints (bulk or interrupt, in or out) and four wrappers to find a
single endpoint (which should cover the vast majority of drivers).

This typically saves about 10-15 lines of code per driver, so even if
this series result in a net gain in terms of lines due to the helpers
being added to core, there will be further reductions when applied to
other subsystems.

Note that the helpers are marked as __must_check to serve as a reminder
to always verify that all expected endpoints are indeed present.

Also note that some drivers have implemented their endpoint look-up
loops in such a way that they have picked the last endpoint descriptor
of the specified type should more than one such descriptor exist. To
avoid any regressions, the second patch therefore adds corresponding
helpers to lookup endpoints by searching the endpoint descriptors in
reverse order. In almost all cases, I expect it would be safe to simply
pick the first matching descriptor instead (i.e. there is only one
endpoint descriptor per type).

Note that this series applies on top of Greg's usb-linus branch which
has a few fixes for the iowarrior and USBTMC drivers.

Johan


Changes in v2
 - use the new helpers also in cdc-acm, usb-storage and usblp (last
   three patches)
 - s/lookup/look up/ in kerneldoc comments
 - simplify match_endpoint helper (Bjørn Mork)
 - add the chaoskey and legousbtower maintainers on CC
 - add temporary variables to avoid reinitialising return-value
   variables where approporiate


Johan Hovold (21):
  USB: core: add helpers to retrieve endpoints
  USB: core: add helpers to retrieve endpoints in reverse order
  USB: adutux: drop redundant sanity check
  USB: adutux: fix up error paths
  USB: adutux: refactor endpoint retrieval
  USB: appledisplay: refactor endpoint retrieval
  USB: chaoskey: refactor endpoint retrieval
  USB: ftdi-elan: refactor endpoint retrieval
  USB: idmouse: refactor endpoint retrieval
  USB: iowarrior: refactor endpoint retrieval
  USB: ldusb: refactor endpoint retrieval
  USB: legousbtower: refactor endpoint retrieval
  USB: lvstest: tighten endpoint sanity check
  USB: usblcd: refactor endpoint retrieval
  USB: uss720: add debug endpoint-type check
  USB: yurex: refactor endpoint retrieval
  USB: usbtmc: refactor endpoint retrieval
  USB: usb-skeleton: refactor endpoint retrieval
  USB: cdc-acm: refactor endpoint retrieval
  USB: storage: refactor endpoint retrieval
  USB: usblp: refactor endpoint retrieval

 drivers/usb/class/cdc-acm.c     |  24 +++-----
 drivers/usb/class/usblp.c       |  35 +++++-------
 drivers/usb/class/usbtmc.c      |  56 ++++++------------
 drivers/usb/core/usb.c          | 123 ++++++++++++++++++++++++++++++++++++++++
 drivers/usb/misc/adutux.c       |  55 ++++++------------
 drivers/usb/misc/appledisplay.c |  19 ++-----
 drivers/usb/misc/chaoskey.c     |  22 ++++---
 drivers/usb/misc/ftdi-elan.c    |  42 ++++++--------
 drivers/usb/misc/idmouse.c      |  31 ++++------
 drivers/usb/misc/iowarrior.c    |  25 +++-----
 drivers/usb/misc/ldusb.c        |  23 +++-----
 drivers/usb/misc/legousbtower.c |  29 +++-------
 drivers/usb/misc/lvstest.c      |   7 +--
 drivers/usb/misc/usblcd.c       |  47 ++++++---------
 drivers/usb/misc/uss720.c       |  10 ++--
 drivers/usb/misc/yurex.c        |  16 ++----
 drivers/usb/storage/usb.c       |  40 +++++--------
 drivers/usb/usb-skeleton.c      |  59 ++++++++-----------
 include/linux/usb.h             |  70 +++++++++++++++++++++++
 19 files changed, 386 insertions(+), 347 deletions(-)

-- 
2.12.0

--
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



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux