public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
* Confused about usercopy_64.c
@ 2008-03-10 16:38 Timur Tabi
  2008-03-10 16:50 ` Olof Johansson
  2008-03-10 16:53 ` Andreas Schwab
  0 siblings, 2 replies; 3+ messages in thread
From: Timur Tabi @ 2008-03-10 16:38 UTC (permalink / raw)
  To: linuxppc-dev

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?

-- 
Timur Tabi
Linux kernel developer at Freescale

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Confused about usercopy_64.c
  2008-03-10 16:38 Confused about usercopy_64.c Timur Tabi
@ 2008-03-10 16:50 ` Olof Johansson
  2008-03-10 16:53 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Olof Johansson @ 2008-03-10 16:50 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Confused about usercopy_64.c
  2008-03-10 16:38 Confused about usercopy_64.c Timur Tabi
  2008-03-10 16:50 ` Olof Johansson
@ 2008-03-10 16:53 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2008-03-10 16:53 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev

Timur Tabi <timur@freescale•com> writes:

> 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'?

To tell the caller that the function failed.  The result is the number
of bytes _left_ to be copying, ie. zero means success.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse•de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-10 16:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-10 16:38 Confused about usercopy_64.c Timur Tabi
2008-03-10 16:50 ` Olof Johansson
2008-03-10 16:53 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox