* A simple question of sys_
@ 2010-09-17 6:58 Rofail Qu
2010-09-17 18:55 ` Randy Dunlap
2010-09-20 7:48 ` Américo Wang
0 siblings, 2 replies; 7+ messages in thread
From: Rofail Qu @ 2010-09-17 6:58 UTC (permalink / raw)
To: linux-kernel
How to use macro IS_ERR() ?
It defines as,
...
#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
static inline long __must_check IS_ERR(const void *ptr)
{
return IS_ERR_VALUE((unsigned long)ptr);
}
...
so when pass x as a pointer and x>=-MAX_ERRNO (including NULL or any
valid address),
IS_ERR() will return true!
IS_ERR(x) seems to use on judge if "x" is a valid error number, right?
So in sys_execve(),
...
long error;
char* filename;
filename = getname(name);
error = PTR_ERR(filename);
if (IS_ERR(filename)) // <== should be IS_ERR((void *)error) or other?
return error;
error = do_execve(filename, argv, envp, regs);
...
Where i am wrong?
Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A simple question of sys_
2010-09-17 6:58 A simple question of sys_ Rofail Qu
@ 2010-09-17 18:55 ` Randy Dunlap
2010-09-20 8:34 ` Rofail Qu
2010-09-20 7:48 ` Américo Wang
1 sibling, 1 reply; 7+ messages in thread
From: Randy Dunlap @ 2010-09-17 18:55 UTC (permalink / raw)
To: Rofail Qu; +Cc: linux-kernel
On Fri, 17 Sep 2010 14:58:30 +0800 Rofail Qu wrote:
> How to use macro IS_ERR() ?
>
> It defines as,
> ...
> #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
> static inline long __must_check IS_ERR(const void *ptr)
> {
> return IS_ERR_VALUE((unsigned long)ptr);
> }
> ...
> so when pass x as a pointer and x>=-MAX_ERRNO (including NULL or any
> valid address),
> IS_ERR() will return true!
Since your conclusion is false, some part of your premise must have a problem.
Can you find it?
> IS_ERR(x) seems to use on judge if "x" is a valid error number, right?
Yes, that's what it is for.
> So in sys_execve(),
> ...
> long error;
> char* filename;
>
> filename = getname(name);
> error = PTR_ERR(filename);
> if (IS_ERR(filename)) // <== should be IS_ERR((void *)error) or other?
> return error;
> error = do_execve(filename, argv, envp, regs);
> ...
>
> Where i am wrong?
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A simple question of sys_
2010-09-17 6:58 A simple question of sys_ Rofail Qu
2010-09-17 18:55 ` Randy Dunlap
@ 2010-09-20 7:48 ` Américo Wang
2010-09-20 8:28 ` Rofail Qu
1 sibling, 1 reply; 7+ messages in thread
From: Américo Wang @ 2010-09-20 7:48 UTC (permalink / raw)
To: Rofail Qu; +Cc: linux-kernel
On Fri, Sep 17, 2010 at 02:58:30PM +0800, Rofail Qu wrote:
>How to use macro IS_ERR() ?
>
>It defines as,
>...
>#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
>static inline long __must_check IS_ERR(const void *ptr)
>{
> return IS_ERR_VALUE((unsigned long)ptr);
>}
>...
>so when pass x as a pointer and x>=-MAX_ERRNO (including NULL or any
>valid address),
>IS_ERR() will return true!
NULL is not an error pointer, you missed the cast to unsigned long.
>IS_ERR(x) seems to use on judge if "x" is a valid error number, right?
>
Strictly speaking, it checks if 'x' is an error pointer.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A simple question of sys_
2010-09-20 7:48 ` Américo Wang
@ 2010-09-20 8:28 ` Rofail Qu
2010-09-21 7:53 ` Américo Wang
0 siblings, 1 reply; 7+ messages in thread
From: Rofail Qu @ 2010-09-20 8:28 UTC (permalink / raw)
To: Américo Wang, linux-kernel
2010/9/20 Américo Wang <xiyou.wangcong@gmail.com>:
> On Fri, Sep 17, 2010 at 02:58:30PM +0800, Rofail Qu wrote:
>>How to use macro IS_ERR() ?
>>
>>It defines as,
>>...
>>#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
>>static inline long __must_check IS_ERR(const void *ptr)
>>{
>> return IS_ERR_VALUE((unsigned long)ptr);
>>}
>>...
>>so when pass x as a pointer and x>=-MAX_ERRNO (including NULL or any
>>valid address),
>>IS_ERR() will return true!
>
> NULL is not an error pointer, you missed the cast to unsigned long.
Ahh, yeah. A stupid mistake i have.
Thanks.
>
>
>>IS_ERR(x) seems to use on judge if "x" is a valid error number, right?
>>
>
> Strictly speaking, it checks if 'x' is an error pointer.
Then what is the range of a valid pointer?
At least less than (unsigned long)-MAX_ERRNO from this case.
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A simple question of sys_
2010-09-17 18:55 ` Randy Dunlap
@ 2010-09-20 8:34 ` Rofail Qu
2010-09-20 15:28 ` Randy Dunlap
0 siblings, 1 reply; 7+ messages in thread
From: Rofail Qu @ 2010-09-20 8:34 UTC (permalink / raw)
To: Randy Dunlap, linux-kernel
2010/9/18 Randy Dunlap <rdunlap@xenotime.net>:
> On Fri, 17 Sep 2010 14:58:30 +0800 Rofail Qu wrote:
>
>> How to use macro IS_ERR() ?
>>
>> It defines as,
>> ...
>> #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
>> static inline long __must_check IS_ERR(const void *ptr)
>> {
>> return IS_ERR_VALUE((unsigned long)ptr);
>> }
>> ...
>> so when pass x as a pointer and x>=-MAX_ERRNO (including NULL or any
>> valid address),
>> IS_ERR() will return true!
>
> Since your conclusion is false, some part of your premise must have a problem.
> Can you find it?
Got it.
thanks any way.
>
>
>> IS_ERR(x) seems to use on judge if "x" is a valid error number, right?
>
> Yes, that's what it is for.
So in kernel, a bad pointer must have saved an valid error number, right?
>
>> So in sys_execve(),
>> ...
>> long error;
>> char* filename;
>>
>> filename = getname(name);
>> error = PTR_ERR(filename);
>> if (IS_ERR(filename)) // <== should be IS_ERR((void *)error) or other?
>> return error;
>> error = do_execve(filename, argv, envp, regs);
>> ...
>>
>> Where i am wrong?
>
>
> ---
> ~Randy
> *** Remember to use Documentation/SubmitChecklist when testing your code ***
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A simple question of sys_
2010-09-20 8:34 ` Rofail Qu
@ 2010-09-20 15:28 ` Randy Dunlap
0 siblings, 0 replies; 7+ messages in thread
From: Randy Dunlap @ 2010-09-20 15:28 UTC (permalink / raw)
To: Rofail Qu; +Cc: linux-kernel
On Mon, 20 Sep 2010 16:34:26 +0800 Rofail Qu wrote:
> 2010/9/18 Randy Dunlap <rdunlap@xenotime.net>:
> > On Fri, 17 Sep 2010 14:58:30 +0800 Rofail Qu wrote:
> >
> >> How to use macro IS_ERR() ?
> >>
> >> It defines as,
> >> ...
> >> #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
> >> static inline long __must_check IS_ERR(const void *ptr)
> >> {
> >> return IS_ERR_VALUE((unsigned long)ptr);
> >> }
> >> ...
> >> so when pass x as a pointer and x>=-MAX_ERRNO (including NULL or any
> >> valid address),
> >> IS_ERR() will return true!
> >
> > Since your conclusion is false, some part of your premise must have a problem.
> > Can you find it?
> Got it.
> thanks any way.
>
> >
> >
> >> IS_ERR(x) seems to use on judge if "x" is a valid error number, right?
> >
> > Yes, that's what it is for.
> So in kernel, a bad pointer must have saved an valid error number, right?
Sorry, I don't quite understand your question.
> >
> >> So in sys_execve(),
> >> ...
> >> long error;
> >> char* filename;
> >>
> >> filename = getname(name);
> >> error = PTR_ERR(filename);
> >> if (IS_ERR(filename)) // <== should be IS_ERR((void *)error) or other?
> >> return error;
> >> error = do_execve(filename, argv, envp, regs);
> >> ...
> >>
> >> Where i am wrong?
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A simple question of sys_
2010-09-20 8:28 ` Rofail Qu
@ 2010-09-21 7:53 ` Américo Wang
0 siblings, 0 replies; 7+ messages in thread
From: Américo Wang @ 2010-09-21 7:53 UTC (permalink / raw)
To: Rofail Qu; +Cc: Américo Wang, linux-kernel
On Mon, Sep 20, 2010 at 04:28:36PM +0800, Rofail Qu wrote:
>2010/9/20 Américo Wang <xiyou.wangcong@gmail.com>:
>> On Fri, Sep 17, 2010 at 02:58:30PM +0800, Rofail Qu wrote:
>>>How to use macro IS_ERR() ?
>>>
>>>It defines as,
>>>...
>>>#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
>>>static inline long __must_check IS_ERR(const void *ptr)
>>>{
>>> return IS_ERR_VALUE((unsigned long)ptr);
>>>}
>>>...
>>>so when pass x as a pointer and x>=-MAX_ERRNO (including NULL or any
>>>valid address),
>>>IS_ERR() will return true!
>>
>> NULL is not an error pointer, you missed the cast to unsigned long.
>Ahh, yeah. A stupid mistake i have.
>Thanks.
>>
>>
>>>IS_ERR(x) seems to use on judge if "x" is a valid error number, right?
>>>
>>
>> Strictly speaking, it checks if 'x' is an error pointer.
>Then what is the range of a valid pointer?
>At least less than (unsigned long)-MAX_ERRNO from this case.
Yeah, the last page in the virtual memory address is reserved,
so all but the last page are non-error addresses.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-09-21 7:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-17 6:58 A simple question of sys_ Rofail Qu
2010-09-17 18:55 ` Randy Dunlap
2010-09-20 8:34 ` Rofail Qu
2010-09-20 15:28 ` Randy Dunlap
2010-09-20 7:48 ` Américo Wang
2010-09-20 8:28 ` Rofail Qu
2010-09-21 7:53 ` Américo Wang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.