[Question] How to check whether or not a device is an USB device?

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

 



Hello,

I am trying to have devlink report default information at the core
level. One of the attributes reported by devlink is the serial number
which is available in usb_device::serial (details: [1]).

This code would work:

        if (!strcmp(dev->parent->type->name, "usb_device")) {
                /* is indeed an USB device */

but the string comparison looks odd.

There is a is_usb_device() which does the check:

  https://elixir.bootlin.com/linux/v6.1-rc1/source/drivers/usb/core/usb.h#L152

but this function is only visible at the USB core level.

Thus my questions:

  * what is the correct way (outside of USB core) to check if a device
is an USB device? Is the string comparaison OK or is there a smarter
way?

  * would it make sense to export the is_usb_device() function?


[1] https://lore.kernel.org/netdev/20221122154934.13937-1-mailhol.vincent@xxxxxxxxxx/

Thank you for your help,


Yours sincerely,
Vincent Mailhol



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

  Powered by Linux