Confused about usercopy_64.c

Olof Johansson olof at lixom.net
Tue Mar 11 03:50:17 EST 2008


On Mon, Mar 10, 2008 at 11:38:49AM -0500, Timur Tabi wrote:
> I'm confused about something in usercopy_64.c:
> 
> unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
> {
> 	if (likely(access_ok(VERIFY_READ, from, n)))
> 		n = __copy_from_user(to, from, n);
> 	else
> 		memset(to, 0, n);
> 	return n;
> }
> 
> If access_ok() returns false, then that means that we cannot copy the data from
> user-space.  So why are we returning 'n'?  Shouldn't we return zero, to let the
> caller know that the function failed?

copy_from_user() returns number of bytes _not_ copied.


-Olof



More information about the Linuxppc-dev mailing list