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

  • SEARCH
  • Home
  • 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 8430349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:45+00:00 2026-06-10T05:34:45+00:00

I have written a device driver and need to pass an int value to

  • 0

I have written a device driver and need to pass an int value to it. Am using copy_from_user() for this. Here is what I have done so far,

#define MY_MAGIC 'G'
#define TEST_IOCTL _IO(MY_MAGIC, 0)
#define PASS_STRUCT_ARRAY_SIZE _IOW(MY_MAGIC, 1, int )
#define TEST_IOCTL_ONE _IO(MY_MAGIC, 2)


int major;

int device_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg){

int ret, SIZE;

switch(cmd){

    case TEST_IOCTL:
        printk("NO argument IOCTL called\n");
        break;

    case PASS_STRUCT_ARRAY_SIZE:
            printk("Inside PASS_STRUCT_ARRAY_SIZE\n");
        ret = copy_from_user(SIZE, arg, sizeof(int));
        if(ret < 0){
            printk("Error in PASS_STRUCT_ARRAY_SIZE\n");
            return -1;  
        }
        printk("Struct Array Size : %d\n",SIZE);
        break;

    case TEST_IOCTL_ONE:
        printk("NO argument IOCTL_ONE called\n");
        break;

    default :
        return -ENOTTY;
}

return 0;

}

When I call the TEST_IOCTL & TEST_IOCTL_ONE the module works properly. However when I call PASS_STRUCT_ARRAY_SIZE the system freezes.

Userspace code is this,

if(ioctl(fd, PASS_STRUCT_ARRAY_SIZE, 10) < 0){
    perror("PASS_STRUCT_ARRAY_SIZE : ");
        return -1;
}

What can I be doing wrong?

  • 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-10T05:34:45+00:00Added an answer on June 10, 2026 at 5:34 am

    Sorry, my previous answer was wrong. Since the argument is an integer you should just use it without copy_from_user:

    SIZE = arg;
    

    You only need copy_from_user when the argument is a pointer.

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

Sidebar

Related Questions

I have written a device driver for a device but each time I connect
I find the type of device using WURFL.Also i have written plugin to set
I have written a kernel driver hello_kernel which registers as a character device on
have written this little class, which generates a UUID every time an object of
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I have written a Linux kernel-module to act as an FPGA driver for a
I have a class called Device that accepts two policies as far as I
I have a device and the drivers for this device. What I would like
I have written a server/client application using sockets in C# for .NET 3.5. I'm

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.