From: Andi Kleen <ak@suse.de>
To: Asang K Dani <asang@yahoo.com>
Cc: linux-kernel@vger.kernel.org, sct@redhat.com,
Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: Re: generic_file_write code segment in 2.2.18
Date: Thu, 4 Jan 2001 08:51:37 +0100 [thread overview]
Message-ID: <20010104085137.A18532@gruyere.muc.suse.de> (raw)
In-Reply-To: <20010104052948.12042.qmail@web2303.mail.yahoo.com>
In-Reply-To: <20010104052948.12042.qmail@web2303.mail.yahoo.com>; from asang@yahoo.com on Wed, Jan 03, 2001 at 09:29:48PM -0800
On Wed, Jan 03, 2001 at 09:29:48PM -0800, Asang K Dani wrote:
> hi everyone,
> I was trying to understand following piece of code in
> 'generic_file_read' (mm/filemap.c) for 2.2.18 kernel. The code
> segment
> is as follows:
>
> ----------------------------------------------------------------
> dest = (char *) page_address(page) + offset;
> if (dest != buf) { /* See comment in
> update_vm_cache_cond. */
> bytes -= copy_from_user(dest, buf, bytes);
> flush_dcache_page(page_address(page));
> }
> status = -EFAULT;
> if (bytes)
> status = inode->i_op->updatepage(file, page,
> offset, bytes, sync);
>
> unlock:
> /* Mark it unlocked again and drop the page.. */
> clear_bit(PG_locked, &page->flags);
> wake_up(&page->wait);
> page_cache_release(page);
>
> if (status < 0)
> break;
>
> written += status;
> count -= status;
> pos += status;
> buf += status;
> ----------------------------------------------------------------
> copy_from_user returns the number of bytes copied from userspace
> to 'dest'. In case it succeeds, 'bytes' will be set to 0 after the
> call. However, 'status' is set to -EFAULT. So wouldn't it break
> out of the while loop (prematurely)?
The code is buggy as far as I can see. copy_from_user doesn't return the
number of bytes copied, but the number of bytes not copied when an error
occurs (or 0 on success).
Correct would be:
--- linux-work/mm/filemap.c-o Wed Jan 3 17:37:27 2001
+++ linux-work/mm/filemap.c Thu Jan 4 08:48:42 2001
@@ -1685,11 +1685,11 @@
*/
dest = (char *) page_address(page) + offset;
if (dest != buf) { /* See comment in update_vm_cache_cond. */
- bytes -= copy_from_user(dest, buf, bytes);
+ if (copy_from_user(dest, buf, bytes))
+ status = -EFAULT;
flush_dcache_page(page_address(page));
}
- status = -EFAULT;
- if (bytes)
+ if (!status)
status = inode->i_op->updatepage(file, page, offset, bytes, sync);
unlock:
-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2001-01-04 7:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-04 5:29 Asang K Dani
2001-01-04 7:51 ` Andi Kleen [this message]
2001-01-04 22:42 ` Stephen C. Tweedie
2001-01-04 22:49 ` Andi Kleen
2001-01-04 22:58 Asang K Dani
2001-01-04 23:02 ` Andi Kleen
2001-01-04 23:09 Asang K Dani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010104085137.A18532@gruyere.muc.suse.de \
--to=ak@suse.de \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=asang@yahoo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sct@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®