I am a newbie learning how to write Linux device drivers for USB devices. I am getting an error while compiling my code. There is a problem in the commented line. I am making a module for a USB drive as follows:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>
static int pen_probe(struct usb_interface *intf,const struct usb_device_id *id)
{
printk(KERN_ALERT"\nthe probe is successful");
return 0;
}
static void pen_disconnect(struct usb_interface *intf)
{
printk(KERN_ALERT"pen drive removed");
}
const struct usb_device_id pen_table = {
USB_DEVICE(0x058f,0x6387),
};
MODULE_DEVICE_TABLE(usb,pen_table);
static struct usb_driver pen_driver = {
.name = "pen_driver",
.id_table = pen_table, // error coming at this line
.probe = pen_probe,
.disconnect = pen_disconnect,
};
static int __init pen_init(void)
{
int ret;
ret = usb_register(&pen_driver);
printk(KERN_ALERT"THE RET::%d\n",ret);
return 0;
}
static void __exit pen_exit(void)
{
usb_deregister(&pen_driver);
}
module_init(pen_init);
module_exit(pen_exit);
MODULE_LICENSE("GPL");
It's giving me an error as follows:
:26:5: error: initializer element is not constant
/home/karan/practice/usb/usb1.c:26:5: error: (near initialization for ‘pen_driver.id_table’)
Microsoft provides drivers for several USB device classes approved by USB-IF. These drivers and their installation files are included in Windows. They are available in the \Windows\System32\DriverStore\FileRepository folder. See, USB device class drivers included in Windows.
The Linux kernel supports two main types of USB drivers: drivers on a host system and drivers on a device. The USB drivers for a host system control the USB devices that are plugged into it, from the host's point of view (a common USB host is a desktop computer.)
id_table
member of the structure is of the type const struct usb_device_id *
but you are assigning const struct usb_device_id
. Try changing pen_table
to &pen_table
in structure initialization.
Hope this helps!
Edit: It actually look like you have the declaration of pen_table
incorrect. It should probably be :
const struct usb_device_id pen_table[] = {
{USB_DEVICE(0x058f,0x6387)},
{}
};
and the initialization should be pen_table
(and not &pen_table
as suggested previously) as you have done in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With