copy_from_user() and block_write question
Stephane Eranian
eranian en cello.hpl.hp.com
Jue Ene 27 04:13:27 CST 2000
Hi,
Could someone explain to me what was the intent of the following
piece of code (extracted from linux-2.3.35 in fs/buffer.c) ?
int block_write_zero_range(struct inode *inode, struct page *page,
unsigned zerofrom, unsigned from, unsigned to,
const char * buf)
{
....
/*
* Now we can copy the data.
*/
if (zerofrom < from)
memset(kaddr+zerofrom, 0, from-zerofrom);
if (from < to)
>>>> err = copy_from_user(kaddr+from, buf, to-from);
if (to < zeroto)
memset(kaddr+to, 0, zeroto-to);
else
zeroto = to;
>>>>> if (err < 0)
goto out;
copy_from_user() always returns something that is >= 0 so the test
err < 0 is never taken. In this case, isn't the use of err for
copy_from_user() kind of confusing ?
I understand that POSIX does not define the behavior of write when
you have a wild pointer. That's the behavior that you get here:
write never fails because buf is invalid. I have seen systems where
the behavior is to return EFAULT though.
Any comments ?
+--------------------------------------------------------------------+
| Ste'phane ERANIAN | Email eranian en hpl.hp.com |
| Hewlett-Packard Laboratories | |
| 1501, Page Mill Road MS 1U-15 | |
| Palo Alto, CA 94303-096 | |
| USA | |
| Tel : (650) 857-7174 | |
| Fax : (650) 857-5548 | |
+--------------------------------------------------------------------+
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo en vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
Más información sobre la lista de distribución Ayuda