Re: copy_from_user returns a positive value?

From: Eli Carter (eli.carter@inet.com)
Date: Fri Feb 15 2002 - 10:01:54 EST


Ben Greear wrote:
>
> I have an IOCTL defined something like this:
>
> _IOWR (0xfe, (30<<3 + 0), __u8 [696])
>
> I'm really passing in a structure of size 696 (does that matter)?
>
> When I make the copy from user call:
>
> if ((ret = copy_from_user(&reqconf, arg, sizeof(reqconf)))) {
> printk("ERROR: copy_from_user returned: %i, sizeof(reqconf): %i\n",
> ret, sizeof(reqconf));
> return ret;
> }
>
> I see this printed out:
>
> ERROR: copy_from_user returned: 696, sizeof(reqconf): 696
>
> According to some docs I saw on the web, it should return 0, or the
> number it has left to copy. So, why does it have 696 bytes left
> to copy??

Because it couldn't copy any of the data? The code I have seen
generally returns -EFAULT in that case.
Could you be trying to copy data from somewhere that the user does not
have permission to read? Can you verify that both pointers are valid?
&reqconf should be in the kernel's memory space and arg should be a
pointer provided by the user-space app pointing to memory in userland.

You might want to get the Linux Device Drivers book... the 2nd ed. is
out.

HTH,

Eli
--------------------. "If it ain't broke now,
Eli Carter \ it will be soon." -- crypto-gram
eli.carter(a)inet.com `-------------------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Feb 15 2002 - 21:01:07 EST