[PATCH v3 0/2] 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).

Johan


Changes in v3
 - drop patches already applied, and resend the two patces which had
   dependencies on usb-linus which have now been merged to usb-next

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 (2):
  USB: lvstest: tighten endpoint sanity check
  USB: usbtmc: refactor endpoint retrieval

 drivers/usb/class/usbtmc.c | 56 +++++++++++++++-------------------------------
 drivers/usb/misc/lvstest.c |  7 +++---
 2 files changed, 21 insertions(+), 42 deletions(-)

-- 
2.12.2

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