Bug 231264 - libusb DPRINTF(ctx, LIBUSB_DEBUG_TRANSFER, "sync I/O done"); does not work in libusb10_do_transfer_cb()
Summary: libusb DPRINTF(ctx, LIBUSB_DEBUG_TRANSFER, "sync I/O done"); does not work in...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-usb (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-09 12:06 UTC by Ludovic Rousseau
Modified: 2018-09-19 08:14 UTC (History)
1 user (show)

See Also:


Attachments
Correctly et the context (674 bytes, patch)
2018-09-12 08:46 UTC, Ludovic Rousseau
no flags Details | Diff
LibUSB patch (1.27 KB, patch)
2018-09-12 15:26 UTC, Hans Petter Selasky
no flags Details | Diff
allows LIBUSB_DEBUG_FUNCTION and LIBUSB_DEBUG_TRANSFER (784 bytes, patch)
2018-09-14 12:20 UTC, Ludovic Rousseau
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Rousseau 2018-09-09 12:06:10 UTC
The _only_ use of DPRINTF(..., LIBUSB_DEBUG_TRANSFER, ...) is in the function libusb10_do_transfer_cb of libusb10_io.c
https://github.com/freebsd/freebsd/blob/master/lib/libusb/libusb10_io.c#L500

The function uses it as:
ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_TRANSFER, "sync I/O done");

Since the ctx context is fetched from NULL it has default values and ctx->debug is 0.

DPRINTF() definition uses ctx->debug to know the debug level.
https://github.com/freebsd/freebsd/blob/master/lib/libusb/libusb10.h#L44

In the present case the debug level will be 0 so nothing is logged.

I don't know how to get the libusb context from a libusb_transfer, the only parameter passed to libusb10_do_transfer_cb().

Another idea for improvement would be to use a bitmap for ctx->debug so it would be possible to enable both LIBUSB_DEBUG_TRANSFER and LIBUSB_DEBUG_FUNCTION at the same time.
Comment 1 Ludovic Rousseau 2018-09-12 08:46:17 UTC
Created attachment 197047 [details]
Correctly et the context
Comment 2 Ludovic Rousseau 2018-09-12 08:47:35 UTC
The code ctx = GET_CONTEXT(NULL); is also used in

libusb_bulk_transfer() at https://github.com/freebsd/freebsd/blob/master/lib/libusb/libusb10_io.c#L588

and

libusb_interrupt_transfer() at https://github.com/freebsd/freebsd/blob/master/lib/libusb/libusb10_io.c#L606

Patch attached. It works for me.
Comment 3 Hans Petter Selasky freebsd_committer freebsd_triage 2018-09-12 09:09:37 UTC
Patch looks good.
Comment 4 Ludovic Rousseau 2018-09-12 09:55:27 UTC
The patch does not fix the problem for libusb10_do_transfer_cb().

Only for the 2 other uses of GET_CONTEXT(NULL).
Comment 5 Hans Petter Selasky freebsd_committer freebsd_triage 2018-09-12 15:26:10 UTC
Created attachment 197056 [details]
LibUSB patch

Can you try this updated patch instead? Does it work for you?
Comment 6 Ludovic Rousseau 2018-09-14 12:20:18 UTC
This new patch works for me.

I would like to be able to have LIBUSB_DEBUG_FUNCTION *and* LIBUSB_DEBUG_TRANSFER logs.

This is easy to do using:
  libusb_set_debug(ctx, LIBUSB_DEBUG_FUNCTION | LIBUSB_DEBUG_TRANSFER);
and the attached patch.
Comment 7 Ludovic Rousseau 2018-09-14 12:20:57 UTC
Created attachment 197089 [details]
allows LIBUSB_DEBUG_FUNCTION and LIBUSB_DEBUG_TRANSFER
Comment 8 commit-hook freebsd_committer freebsd_triage 2018-09-14 13:42:18 UTC
A commit references this bug:

Author: hselasky
Date: Fri Sep 14 13:41:37 UTC 2018
New revision: 338679
URL: https://svnweb.freebsd.org/changeset/base/338679

Log:
  Improve LibUSB debugging by simultaneously allowing both function
  and transfer prints. Make sure the debug level comes from the
  correct USB context.

  Found by:		Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com>
  PR:			231264
  MFC after:		1 week
  Approved by:		re (kib)
  Sponsored by:		Mellanox Technologies

Changes:
  head/lib/libusb/libusb10.h
  head/lib/libusb/libusb10_io.c
Comment 9 commit-hook freebsd_committer freebsd_triage 2018-09-19 08:12:38 UTC
A commit references this bug:

Author: hselasky
Date: Wed Sep 19 08:11:44 UTC 2018
New revision: 338791
URL: https://svnweb.freebsd.org/changeset/base/338791

Log:
  MFC r338679:
  Improve LibUSB debugging by simultaneously allowing both function
  and transfer prints. Make sure the debug level comes from the
  correct USB context.

  Found by:		Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com>
  PR:			231264
  Sponsored by:		Mellanox Technologies

Changes:
_U  stable/11/
  stable/11/lib/libusb/libusb10.h
  stable/11/lib/libusb/libusb10_io.c
Comment 10 commit-hook freebsd_committer freebsd_triage 2018-09-19 08:13:42 UTC
A commit references this bug:

Author: hselasky
Date: Wed Sep 19 08:12:41 UTC 2018
New revision: 338792
URL: https://svnweb.freebsd.org/changeset/base/338792

Log:
  MFC r338679:
  Improve LibUSB debugging by simultaneously allowing both function
  and transfer prints. Make sure the debug level comes from the
  correct USB context.

  Found by:		Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com>
  PR:			231264
  Sponsored by:		Mellanox Technologies

Changes:
_U  stable/10/
  stable/10/lib/libusb/libusb10.h
  stable/10/lib/libusb/libusb10_io.c
Comment 11 commit-hook freebsd_committer freebsd_triage 2018-09-19 08:14:45 UTC
A commit references this bug:

Author: hselasky
Date: Wed Sep 19 08:13:58 UTC 2018
New revision: 338793
URL: https://svnweb.freebsd.org/changeset/base/338793

Log:
  MFC r338679:
  Improve LibUSB debugging by simultaneously allowing both function
  and transfer prints. Make sure the debug level comes from the
  correct USB context.

  Found by:		Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com>
  PR:			231264
  Sponsored by:		Mellanox Technologies

Changes:
_U  stable/9/lib/
_U  stable/9/lib/libusb/
  stable/9/lib/libusb/libusb10.h
  stable/9/lib/libusb/libusb10_io.c