From: Adam Lee <adam.lee@canonical.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: linux-bluetooth@vger.kernel.org,
Wen-chien Jesse Sung <jesse.sung@canonical.com>,
AceLan Kao <acelan.kao@canonical.com>,
Tedd Ho-Jeong An <tedd.an@intel.com>,
Anthony Wong <anthony.wong@canonical.com>,
Gustavo Padovan <gustavo@padovan.org>,
Johan Hedberg <johan.hedberg@gmail.com>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] btusb: fix overflow return values
Date: Tue, 9 Jul 2013 10:55:01 +0800 [thread overview]
Message-ID: <20130709025501.GA6369@adam-laptop> (raw)
In-Reply-To: <25CD2206-7B7B-4DAD-A714-A79976C9DB13@holtmann.org>
[-- Attachment #1: Type: text/plain, Size: 1605 bytes --]
On Mon, Jul 08, 2013 at 11:50:54AM -0700, Marcel Holtmann wrote:
> Hi Adam,
>
> > PTR_ERR() returns a long type value, but btusb_setup_intel() and
> > btusb_setup_intel_patching() should return an int type value.
> >
> > This bug makes the judgement "if (ret < 0)" not working on x86_64
> > architecture systems, leading to failure as below, even panic.
> > ...
> > For not affecting other modules, I choose to modify the return values
> > but not extend btusb_setup_intel() and btusb_setup_intel_patching()'s
> > return types. This is harmless, because the return values were only
> > used to comparing number 0.
>
> there are tons of examples in various subsystems and drivers where we
> return PTR_ERR from a function calls returning int.
>
> So I wonder what is actually going wrong here. If this is x86_64
> specific problem with PTR_ERR vs int, then we should have this problem
> everywhere in the kernel.
Hi, Marcel
I see you point, the difference between here and other subsystems are:
1, it returns -PTR_ERR() here but all other places return PTR_ERR(), I
checked.
2, the judgement is "if (ret < 0)" here but other places are "if (ret)".
I'm not saying other subsystems are 100% right, but here, returning
-PTR_ERR() and checking "if (ret < 0)" make the judgement broken much
much more easily.
I attached a testing C file, run it on x86_64, you will see the bug.
PS, about other subsystems, I also think returning PTR_ERR() from a
function calls returning int considered harmful sometimes, will talk
about that in other thread.
Great thanks.
--
Regards,
Adam Lee
Hardware Enablement
[-- Attachment #2: ptr_err.c --]
[-- Type: text/x-csrc, Size: 606 bytes --]
#include <stdio.h>
static inline long PTR_ERR(const void *ptr)
{
return (long) ptr;
}
int main(int argc, const char *argv[])
{
printf("sizeof(char) = %lu, sizeof(int) = %lu, sizeof(long) = %lu\n\n",
sizeof(char), sizeof(int), sizeof(long));
/*This address is in kernel space, check Documentation/x86/x86_64/mm.txt*/
void *ptr = (void *)0Xffff8900f0000000;
printf("ptr = %p, PTR_ERR(ptr) = %lx, (int)(-PTR_ERR(ptr)) = %d\n\n",
ptr, PTR_ERR(ptr), (int)(-PTR_ERR(ptr)));
if ((int)(-PTR_ERR(ptr)) < 0)
printf("That's what the codes want.\n");
else
printf("Bug happens!\n");
return 0;
}
next prev parent reply other threads:[~2013-07-09 2:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-04 12:43 [PATCH] btusb: fix overflow return values Adam Lee
2013-07-05 2:37 ` Yang Bai
2013-07-05 2:53 ` Yang Bai
2013-07-05 2:59 ` Adam Lee
2013-07-05 4:41 ` Adam Lee
2013-07-08 18:50 ` Marcel Holtmann
2013-07-09 2:55 ` Adam Lee [this message]
2013-07-09 7:40 ` Adam Lee
2013-07-09 8:48 ` [PATCH v2] btusb: fix wrong use of PTR_ERR() Adam Lee
2013-07-09 15:32 ` [PATCH] btusb: fix overflow return values Gustavo Padovan
2013-07-10 2:02 ` [PATCH v3] btusb: fix wrong use of PTR_ERR() Adam Lee
2013-07-10 10:28 ` Gustavo Padovan
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=20130709025501.GA6369@adam-laptop \
--to=adam.lee@canonical.com \
--cc=acelan.kao@canonical.com \
--cc=anthony.wong@canonical.com \
--cc=gustavo@padovan.org \
--cc=jesse.sung@canonical.com \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=tedd.an@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;
as well as URLs for NNTP newsgroup(s).