kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: thomas.petazzoni@free-electrons.com (Thomas Petazzoni)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Why __force sparse annotation needed in copy_from_user() to vmalloc'ed area
Date: Wed, 5 Sep 2012 12:24:37 +0200	[thread overview]
Message-ID: <20120905122437.7565dc7f@skate> (raw)

Hello,

In the course of reviewing a new framebuffer driver [1], I discovered
the following bit of code:

+	dst = (void __force *) (info->screen_base + p);
+
+	if (copy_from_user(dst, buf, count))
+		err = -EFAULT;

Where info->screen_base is a vmalloc'ed memory area. Many other
framebuffer drivers have used this __force sparse annotation: see [2]
or [3] for example.

I am confused as to why sparse requires the __force annotation for what
seems to be a regular user to kernel copy. The __force annotation is
typically not needed for user to kernel copy when the destination
kernel buffer has been kmalloc'ed.

Why does sparse handles vmalloc'ed buffer differently, and gives a
warning in this case?

Thanks,

Thomas

[1] http://marc.info/?l=linux-fbdev&m=134683775709128&w=2
[2] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=28cdf76bf0bce757428f84161e3aa510028d47b4
[3] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=d2e8d369cd92a8bb856ff530fa1e4c03b0e0ff55
-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

                 reply	other threads:[~2012-09-05 10:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20120905122437.7565dc7f@skate \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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;
as well as URLs for NNTP newsgroup(s).