Hello, I'm not sure why you're seeing the errors but my question is did
you tag your module_init() with "__init" ??? ...because this will
destroy that function after it's called during insmod and I think it
takes all it's variables with it to the grave.
----- Original Message ----
From: John Que <qwejohn@xxxxxxxxx>
To: kernelnewbies@xxxxxxxxxxxx
Sent: Sunday, August 20, 2006 7:44:55 PM
Subject: copy_to_user() returns an error
From: John Que <qwejohn@xxxxxxxxx>
To: kernelnewbies@xxxxxxxxxxxx
Sent: Sunday, August 20, 2006 7:44:55 PM
Subject: copy_to_user() returns an error
Hello,
I am trying to copy a table (an array of structs) from
kernel to user space in a kernel module ioctl method.
I do it thus;
...
...
struct myStruct
{
char* name;
int value1;
int value2;
struct myStruct *next;
};
static struct myStruct* myTable = NULL;
there is allocation of memOry for myTable in the module init() thus:
myTable = kmalloc( MAXELEM* sizeof(struct MYStruct), GFP_KERNEL);
and it is filled with values.
(MAXENTIRES is 1000 - maybe it is too big ??)
...
...
...
static int my_ioctl(struct inode* inode,
struct file* file,
unsigned int cmd,
unsigned long data)
{
switch (cmd)
{
case MYIOCTL:
{
int res;
res = copy_to_user((void __user*)data,
relayTable,
numberOfPorts* sizeof(struct relayStruct));
printk("res is %d\n",res);
}
...
...
}
copy_to_user() should return 0 in case of success;
I keep getting positive number after calling copy_to_user();
(it is 240 or 160 or 80, depends on which trial I made)
I also tried to copy only one element (numberOfPorts=1) , and
I had also tried : copy_to_user((struct relayStruct*)data,
and also copy_to_user() returned error.
When I try to use this IOCTL from user space I get garbage
for the table entries.
Any ideas what is wrong here?
Regards,
John
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
I am trying to copy a table (an array of structs) from
kernel to user space in a kernel module ioctl method.
I do it thus;
...
...
struct myStruct
{
char* name;
int value1;
int value2;
struct myStruct *next;
};
static struct myStruct* myTable = NULL;
there is allocation of memOry for myTable in the module init() thus:
myTable = kmalloc( MAXELEM* sizeof(struct MYStruct), GFP_KERNEL);
and it is filled with values.
(MAXENTIRES is 1000 - maybe it is too big ??)
...
...
...
static int my_ioctl(struct inode* inode,
struct file* file,
unsigned int cmd,
unsigned long data)
{
switch (cmd)
{
case MYIOCTL:
{
int res;
res = copy_to_user((void __user*)data,
relayTable,
numberOfPorts* sizeof(struct relayStruct));
printk("res is %d\n",res);
}
...
...
}
copy_to_user() should return 0 in case of success;
I keep getting positive number after calling copy_to_user();
(it is 240 or 160 or 80, depends on which trial I made)
I also tried to copy only one element (numberOfPorts=1) , and
I had also tried : copy_to_user((struct relayStruct*)data,
and also copy_to_user() returned error.
When I try to use this IOCTL from user space I get garbage
for the table entries.
Any ideas what is wrong here?
Regards,
John
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/