Re: EFAULT in an ioctl (in a kernel module) when calling copy_to_user() - why ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
1)I don't have a clue from where this 4 is returned.
2)The udage is ususally thus is the kernel:
if the return value of copy_to_user() is not zero, than
the method who calls it returns  -EFAULT.

Any ideas how to solve this problem?
John

On 12/20/05, Bernd Petrovitsch <bernd@xxxxxxxxx> wrote:
> On Tue, 2005-12-20 at 14:32 +0200, John Que wrote:
> [....]
> > res of copy_to_user = 4
> > Any idea?
>
> Yes.
> Where might the 4 come from?
> And how do others use the return value?
>
> [...]
> > On 12/20/05, Bernd Petrovitsch <bernd@xxxxxxxxx> wrote:
> > > On Tue, 2005-12-20 at 14:02 +0200, John Que wrote:
> > > [...]
> > > > I had written a very simple ioctl() method in a module;
> > > > this ioctl calls copy_to_user();
> > > >
> > > > I am getting EFAULT when trying to call this ioctl from
> > > > use space.
> > > >
> > > > Any idea what can be the reason ?
> > >
> > > Yes.
> > >
> > > > Here is the code:
> > > >
> > > > static unsigned long my_ioctl(struct inode* inode,
> > > >                                                     struct file* file,
> > > >                                                     unsigned int cmd,
> > > >                                                     unsigned long data)
> > > >
> > > >   {
> > > >       ...
> > > >       ...
> > > > case MY_IOCTL:
> > > >   {
> > > >   unsigned int result = 99;
> > > >
> > > >   if (copy_to_user((unsigned int *)data,
> > > >                               &result,
> > > >                               sizeof(unsigned int)))
> > > >     {
> > > >    printk("copy_to_user failed\n");
> > > >    return -EFAULT;
> > > >    }
> > > >
> > > > }
> > >
> > > What value is returned by copy_to_user()?
>
>         Bernd
> --
> Firmix Software GmbH                   http://www.firmix.at/
> mobil: +43 664 4416156                 fax: +43 1 7890849-55
>           Embedded Linux Development and Services
>
>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux