linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Question] How to check whether or not a device is an USB device?
@ 2022-11-24 15:40 Vincent Mailhol
  2022-11-24 16:02 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Vincent Mailhol @ 2022-11-24 15:40 UTC (permalink / raw)
  To: linux-usb; +Cc: Greg Kroah-Hartman, Alan Stern

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@wanadoo.fr/

Thank you for your help,


Yours sincerely,
Vincent Mailhol

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-24 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-24 15:40 [Question] How to check whether or not a device is an USB device? Vincent Mailhol
2022-11-24 16:02 ` Greg Kroah-Hartman
2022-11-24 16:08   ` Vincent Mailhol
2022-11-24 16:15     ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).