Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --sysdev/-y option for direct device node access #600

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tormodvolden
Copy link

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 <[email protected]>
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 Show resolved Hide resolved
uhubctl.c Outdated Show resolved Hide resolved
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
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
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
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.

uhubctl.c Outdated Show resolved Hide resolved
@tormodvolden
Copy link
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants