Why is the probe function in my kernel module not being called?

会有一股神秘感。 提交于 2019-12-13 02:35:21

问题


While following, among others, this tutorial ([http://tali.admingilde.org/linux-docbook/writing_usb_driver.pdf][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?


回答1:


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.



来源:https://stackoverflow.com/questions/31052993/why-is-the-probe-function-in-my-kernel-module-not-being-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!