添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
逃跑的松鼠  ·  Linux 中运行 C ...·  16 小时前    · 
体贴的路灯  ·  World Hello - ...·  16 小时前    · 
千年单身的咖啡  ·  All builds now ...·  昨天    · 
谈吐大方的猕猴桃  ·  Visual Studio ...·  3 月前    · 
无聊的金针菇  ·  Search·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

While following, among others, this tutorial ( 1 ) and reading certain chapters in the Linux Device Drivers book, I cannot get the pr_debug() statements in the probe function to show any output in dmesg.

Here's my code:

#include <linux/module.h>    /*included for all kernel modules*/
#include <linux/kernel.h>    /*included for KERN_DEBUG*/
#include <linux/init.h>      /*included for __init and __exit macros*/
#include <linux/usb.h>
#include <linux/usb/input.h>
#include <linux/hid.h>
#define VENDOR_ID 0x0930
#define DEVICE_ID 0x6545
MODULE_LICENSE("GPL");
MODULE_AUTHOR("dev");
MODULE_DESCRIPTION("eusb driver");
static struct usb_device_id eusb_table[] = {
        { USB_DEVICE(VENDOR_ID, DEVICE_ID) },
        { } /* Terminating entry */
MODULE_DEVICE_TABLE (usb, eusb_table);
static int eusb_probe(struct usb_interface *interface, const struct usb_device_id *id)
        pr_debug("USB probe function called\n");
        return 0;
static void eusb_disconnect(struct usb_interface *interface)
        pr_debug("USB disconnect function called\n");
static struct usb_driver eusb_driver = {
    //.owner =  THIS_MODULE,
    .name =     "eusb",
    .probe =    eusb_probe,
    .disconnect =   eusb_disconnect,
    .id_table =     eusb_table
static int __init eusb_init(void)
    int result = 0;
    pr_debug("Hello world!\n");
    result = usb_register(&eusb_driver);
    if(result){
        pr_debug("error %d while registering usb\n", result);}
    else{pr_debug("no error while registering usb\n");}
    return 0;
static void __exit eusb_exit(void)
    usb_deregister(&eusb_driver);
    pr_debug("Exiting module\n");
module_init(eusb_init);
module_exit(eusb_exit);

and Makefile:

obj-m := eusb.o
CFLAGS_eusb.o := -DDEBUG
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

Make finishes without errors, after insmod I can see the module listed in lsmod and the pr_debug() in the init and exit functions show output in dmesg.

When inserting the device however the probe function seems to not get called (or the pr_debug() statements do not show any output in dmesg).

Dmesg output:

[ 7777.521236] Hello world!
[ 7777.521264] usbcore: registered new interface driver eusb
[ 7777.521266] no error while registering usb
[ 7780.597087] usb 1-6: USB disconnect, device number 9
[ 7797.686970] usb 1-6: new high-speed USB device number 10 using xhci_hcd
[ 7797.857324] usb 1-6: New USB device found, idVendor=0930, idProduct=6545
[ 7797.857328] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 7797.857330] usb 1-6: Product: DataTraveler 2.0
[ 7797.857331] usb 1-6: Manufacturer: Kingston
[ 7797.857333] usb 1-6: SerialNumber: 08606E6D407FED10571E5067
[ 7797.858787] usb-storage 1-6:1.0: USB Mass Storage device detected
[ 7797.858902] scsi host11: usb-storage 1-6:1.0
[ 7798.931417] scsi 11:0:0:0: Direct-Access     Kingston DataTraveler 2.0 PMAP PQ: 0 ANSI: 4
[ 7798.931824] sd 11:0:0:0: Attached scsi generic sg3 type 0
[ 7800.184749] sd 11:0:0:0: [sdc] 60964864 512-byte logical blocks: (31.2 GB/29.0 GiB)
[ 7800.186338] sd 11:0:0:0: [sdc] Write Protect is off
[ 7800.186343] sd 11:0:0:0: [sdc] Mode Sense: 23 00 00 00
[ 7800.187948] sd 11:0:0:0: [sdc] No Caching mode page found
[ 7800.187952] sd 11:0:0:0: [sdc] Assuming drive cache: write through
[ 7800.220477]  sdc: sdc1 sdc2 sdc3
[ 7800.225068] sd 11:0:0:0: [sdc] Attached SCSI removable disk
[ 7802.798403] ISO 9660 Extensions: Microsoft Joliet Level 3
[ 7802.799507] ISO 9660 Extensions: RRIP_1991A

I have tried with another device, tried with printk() instead of pr_debug(). I found several questions on SO with the same problem, but my code is as far as I can tell almost/completely the same as the code in the answers.

I have also tried with:

USB_INTERFACE_INFO(
        USB_INTERFACE_CLASS_HID,
        USB_INTERFACE_SUBCLASS_BOOT,
    USB_INTERFACE_PROTOCOL_KEYBOARD) 

instead of USB_DEVICE() (the other device was a keyboard).

I noticed that some answers talk about platform_driver instead of usb_driver, but I think this is not relevant for me, as it is never mentioned in the tutorials.

Where am I going wrong?

Is your purpose just educational? Otherwise the driver is already there and it's called usb-storage. Seems even that driver enumerates your device first. Try to disable usb-storage and load your driver again. Or better use the virtual machine (KVM / Qemu) to try your drivers. – 0andriy Jun 25, 2015 at 16:55 Thanks for your response. Yes, just educational. I couldn't find the usb-storage module listed in lsmod, however it did get loaded on insertion of the usb device apparently and prevented my module from being used, like you said. I used usb-storage.blacklist=yes and uas.blacklist=yes (not sure this 2nd one was necessary, but it got loaded together with usb-storage) at grub command line before boot to temporarily disable them and now it used my module before loading those. How do I mark your response as answer? Thanks! – jasu Jun 26, 2015 at 11:00 @shashankarora It depends on the driver/hardware. Virtualization environments, such as QEMU, may or may not have the necessary hardware emulation, so for some cases it might be needed to develop that first. – 0andriy Jan 5 at 8:28

As you can see your Hello world! was printed which implies the module was loaded successfully. Often all the modules claiming to handle the device via usb_device_id* table are loaded. See 9.3.2.3. Module Loading.

Now, the probe function is called only for the driver the device was bound to. In the case where there is no priority set and two drivers are capable of binding, any of them might get the first opportunity.

I have written a blog post which might clear things further (if not, do comment here).

Further, you might want to go through these two relevant mailing list threads

  • https://lists.kernelnewbies.org/pipermail/kernelnewbies/2011-October/003639.html
  • https://marc.info/?l=linux-usb&m=162123892329464&w=2
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.