Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1250919 > unrolled thread
| Started by | "Nelson, Shannon" <shannon.nelson@intel.com> |
|---|---|
| First post | 2015-10-19 19:00 +0200 |
| Last post | 2015-10-20 17:30 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: [PATCH] intel: i40e: fix confused code "Nelson, Shannon" <shannon.nelson@intel.com> - 2015-10-19 19:00 +0200
Re: [PATCH] intel: i40e: fix confused code Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-10-20 09:30 +0200
RE: [PATCH] intel: i40e: fix confused code "Nelson, Shannon" <shannon.nelson@intel.com> - 2015-10-20 17:30 +0200
| From | "Nelson, Shannon" <shannon.nelson@intel.com> |
|---|---|
| Date | 2015-10-19 19:00 +0200 |
| Subject | RE: [PATCH] intel: i40e: fix confused code |
| Message-ID | <qllWV-1T1-7@gated-at.bofh.it> |
> 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. Also, if somewhere else along the line there is some other error, I'd prefer to return that value rather than stomp on it with my own error code.
sln
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Rasmus Villemoes <linux@rasmusvillemoes.dk> |
|---|---|
| Date | 2015-10-20 09:30 +0200 |
| Message-ID | <qlzwT-5dK-53@gated-at.bofh.it> |
| In reply to | #1250919 |
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Nelson, Shannon" <shannon.nelson@intel.com> |
|---|---|
| Date | 2015-10-20 17:30 +0200 |
| Message-ID | <qlH1o-7IO-19@gated-at.bofh.it> |
| In reply to | #1251338 |
> From: Rasmus Villemoes [mailto:linux@rasmusvillemoes.dk]
> Sent: Tuesday, October 20, 2015 12:22 AM
>
> 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).
I like the comment about the moronic interface for copy_to/from_user...
Yes, I see where I turned left instead of right. This would be good to fix up.
sln
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web