mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: "Nelson\, Shannon" <shannon.nelson@intel.com>
Cc: "Kirsher\, Jeffrey T" <jeffrey.t.kirsher@intel.com>, "Brandeburg\,
	Jesse" <jesse.brandeburg@intel.com>, "Wyborny\,
	Carolyn" <carolyn.wyborny@intel.com>, "Skidmore\,
	Donald C" <donald.c.skidmore@intel.com>, "Vick\,
	Matthew" <matthew.vick@intel.com>, "Ronciak\,
	John" <john.ronciak@intel.com>, "Williams\,
	Mitch A" <mitch.a.williams@intel.com>,
	"intel-wired-lan\@lists.osuosl.org" 
	<intel-wired-lan@lists.osuosl.org>,
	"netdev\@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] intel: i40e: fix confused code
Date: Tue, 20 Oct 2015 09:22:14 +0200	[thread overview]
Message-ID: <87wpuim2c9.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <FC41C24E35F18A40888AACA1A36F3E418AFA4A68@fmsmsx115.amr.corp.intel.com> (Shannon Nelson's message of "Mon, 19 Oct 2015 16:56:15 +0000")

On Mon, Oct 19 2015, "Nelson, Shannon" <shannon.nelson@intel.com> wrote:

>> From: Rasmus Villemoes [mailto:linux@rasmusvillemoes.dk]
>> Sent: Saturday, October 17, 2015 1:58 PM
>> Subject: [PATCH] intel: i40e: fix confused code
>> 
>> This code is pretty confused. The variable name 'bytes_not_copied'
>> clearly indicates that the programmer knew the semantics of
>> copy_{to,from}_user, but then the return value is checked for being
>> negative and used as a -Exxx return value.
>> 
>> I'm not sure this is the proper fix, but at least we get rid of the
>> dead code which pretended to check for access faults.
>> 
>> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
>
> I believe this patch is unnecessary: if the value is negative, then it
> already is an error code giving some potentially useful information.
> When I dig into the copy_to_user() code, I see in the comments for
> put_user() that -EFAULT is the error being returned.

Thanks, this was precisely the kind of confusion I'm talking about:
copy_{from,to}_user _never_ returns a negative value. It returns
precisely what the very explicit variable name hints.

This is in contrast to the single-scalar functions get_user/put_user,
which do return -EFAULT for error and 0 for success.

(See also lines 479-519 of Documentation/DocBook/kernel-hacking.tmpl).

In the entire kernel source tree, two files contain a check for the
return value from copy_{from,to}_user being negative. It will never
trigger, so might as well be removed - except if it was _supposed_ to be
checking for access violations, in which case one should probably
replace it with actually handling it. Try

  git grep -C2 -E 'copy_(from|to)_user' drivers/net/ethernet/

Rasmus

  reply	other threads:[~2015-10-20  7:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-17 20:58 Rasmus Villemoes
2015-10-19 16:56 ` Nelson, Shannon
2015-10-20  7:22   ` Rasmus Villemoes [this message]
2015-10-20 15:27     ` Nelson, Shannon
2015-10-20 15:39 ` Nelson, Shannon

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=87wpuim2c9.fsf@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=carolyn.wyborny@intel.com \
    --cc=donald.c.skidmore@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=john.ronciak@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.vick@intel.com \
    --cc=mitch.a.williams@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=shannon.nelson@intel.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®