Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7819773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:04:19+00:00 2026-06-02T07:04:19+00:00

I am a newbie learning how to write Linux device drivers for USB devices.

  • 0

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’)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:04:20+00:00Added an answer on June 2, 2026 at 7:04 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie learning how to write WDM device drivers for USB devices
Please bear with me, newbie just learning the ropes. I am getting the below
I am a newbie learning C# after C++. VS2010. Trying to debug my code,
Newbie to C++ learning by converting a java program to c++. The following code
Newbie still learning, been trying to search and hack code together for hours now,
I'm a newbie to Asp.net,learning from the Apress's Begining Asp.net...book.While very curious to see
Is is that I'm a newbie learning Ruby, or does it really have more
I'm a machine learning newbie trying to understand how Adaboost works. I've read many
I am a newbie to Android and currently learning the Android SDK. I am
I am quite a newbie in OOP using java and I'm learning as I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.