Skip to content

Conversation

@tormodvolden
Copy link
Contributor

Only the device specified by the given device path will be accessed, instead of scanning the USB bus.

Most useful if you use udev rules to create stable device node aliases for hubs, independent of bus topology.

For instance, if your matching udev rules include SYMLINK+="MYSMARTHUB1" you can call uhubctl with --sysdev /dev/MYSMARTHUB1 instead of using -l and a non-stable bus location to specify it.

Only the device specified by the given device path will be accessed, instead of scanning the USB bus. Most useful if you use udev rules to create stable device node aliases for hubs, independent of bus topology. For instance, if your matching udev rules include SYMLINK+="MYSMARTHUB1" you can call uhubctl with --sysdev /dev/MYSMARTHUB1 instead of using -l and a non-stable bus location to specify it. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Copy link
Owner

@mvp mvp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this work! It looks good, but there are few things to be fixed before merging:

  • libusb_wrap_sys_device is not Linux only. We should be able to support any OS that libusb suppors, e.g. FreeBSD, Darwin, Solaris. It means applicable code should not be under Linux ifdef.
  • I would like to reserve -u/--usb for future functionality. Can you use -y or -Y instead?
uhubctl.c Outdated
(defined(__gnu_linux__) || defined(__linux__))
int sys_fd;
libusb_device_handle *sys_devh = NULL;
libusb_device *dev_list[2];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this variable definition into if (opt_sysdev) block - the only place it is used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allocated memory is pointed to by the usb_dev pointer later, so it cannot be free'd before libusb_free_device_list(usb_devs, 1) at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it cannot be allocated on the stack inside the if (opt_sysdev) block. I agree this isn't pretty. The alternative is malloc'ing it inside that block instead, but I found it a lot of overhead for 2 measly pointers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know what you think about the calloc variant I pushed now.

@tormodvolden
Copy link
Contributor Author

Thank you for this work! It looks good, but there are few things to be fixed before merging:

* libusb_wrap_sys_device is not Linux only. We should be able to support any OS that libusb suppors, e.g. FreeBSD, Darwin, Solaris. It means applicable code should not be under Linux ifdef. 

Thanks for the review! The libusb_wrap_sys_device() is (unfortunately) Linux-only and I don't foresee that changing any time soon.

* I would like to reserve -u/--usb for future functionality. Can you use -y or -Y instead? 

Sure! I have no preference on -y vs -Y, is there a system to it, or any preference from your side?

@tormodvolden
Copy link
Contributor Author

I pushed a fixup commit (of -y option renaming for now) for review, but I will of course squash it once ready.

@tormodvolden tormodvolden changed the title Add --sysdev/-u option for direct device node access Add --sysdev/-y option for direct device node access Nov 24, 2024
@mvp mvp merged commit a957b21 into mvp:master Jan 18, 2025
@mvp
Copy link
Owner

mvp commented Jan 18, 2025

Thanks for your work @tormodvolden! Sorry it took so long to merge it.
I plan to release new version soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants