* return negative number for unsigned long function in kernel
@ 2007-03-06 14:52 Chen, Dongliang
2007-03-06 19:05 ` Andreas Schwab
2007-03-07 0:39 ` H. Peter Anvin
0 siblings, 2 replies; 5+ messages in thread
From: Chen, Dongliang @ 2007-03-06 14:52 UTC (permalink / raw)
To: linux-kernel; +Cc: Chen, Dongliang
There are lots of functions in the Linux kernel that are declared as
unsigned long, but the return value is negative integer while error
occurred. An example of these functions is do_mmap_pgoff in mm/mmap.c,
which is defined as:
unsigned long do_mmap_pgoff(....)
In this function, it returns -ENODEV, -EPERM, -ENOMEM, -EINVAL, -EAGAIN,
-EACCESS depends on the error type. My question is how should the caller
perform error check based on the return value?
Please CC reply to me at chen.d@ems-t.com
Thanks,
Dongliang Chen
Staff Engineer
EMS Technologies, Inc - Defense and Space Systems
660 Engineering Dr
Norcross, GA 30092
Tel: 770-263-9200 x 4379
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: return negative number for unsigned long function in kernel
2007-03-06 14:52 return negative number for unsigned long function in kernel Chen, Dongliang
@ 2007-03-06 19:05 ` Andreas Schwab
2007-03-07 0:39 ` H. Peter Anvin
1 sibling, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2007-03-06 19:05 UTC (permalink / raw)
To: Chen, Dongliang; +Cc: linux-kernel
"Chen, Dongliang" <Chen.D@ems-t.com> writes:
> There are lots of functions in the Linux kernel that are declared as
> unsigned long, but the return value is negative integer while error
> occurred. An example of these functions is do_mmap_pgoff in mm/mmap.c,
> which is defined as:
>
> unsigned long do_mmap_pgoff(....)
>
> In this function, it returns -ENODEV, -EPERM, -ENOMEM, -EINVAL, -EAGAIN,
> -EACCESS depends on the error type. My question is how should the caller
> perform error check based on the return value?
The return value is directly passed to user space (it's the guts of the
mmap syscall). The glibc wrapper transforms it appropriately so that
errno is set and -1 is returned if there is an error.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: return negative number for unsigned long function in kernel
2007-03-06 14:52 return negative number for unsigned long function in kernel Chen, Dongliang
2007-03-06 19:05 ` Andreas Schwab
@ 2007-03-07 0:39 ` H. Peter Anvin
2007-03-07 13:31 ` Chen, Dongliang
1 sibling, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2007-03-07 0:39 UTC (permalink / raw)
To: Chen, Dongliang; +Cc: linux-kernel
Chen, Dongliang wrote:
> There are lots of functions in the Linux kernel that are declared as
> unsigned long, but the return value is negative integer while error
> occurred. An example of these functions is do_mmap_pgoff in mm/mmap.c,
> which is defined as:
>
> unsigned long do_mmap_pgoff(....)
>
> In this function, it returns -ENODEV, -EPERM, -ENOMEM, -EINVAL, -EAGAIN,
> -EACCESS depends on the error type. My question is how should the caller
> perform error check based on the return value?
>
If you want to test for errorness, you could use the macro
IS_ERR_VALUE(). Unfortunately the macro isn't all that safe, in that it
will give you the wrong answer if it's ever used on something that
*isn't* an unsigned long.
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: return negative number for unsigned long function in kernel
2007-03-07 0:39 ` H. Peter Anvin
@ 2007-03-07 13:31 ` Chen, Dongliang
2007-03-07 16:30 ` H. Peter Anvin
0 siblings, 1 reply; 5+ messages in thread
From: Chen, Dongliang @ 2007-03-07 13:31 UTC (permalink / raw)
To: H. Peter Anvin, Andreas Schwab; +Cc: linux-kernel
Peter & Andreas,
Thank you very much for your help.
I understood that the kernel error numbers are limited. The largest
error number for i386 (kernel 2.6) is 131 so far. Assume that the
virtual address returned from do_mmap_pgoff will never exceed (unsigned
long)(-1000L), which is in the address range one page below the maximum
virtual address, then IS_ERR_VALUE() should work.
Dongliang Chen
Staff Engineer
EMS Technologies, Inc - Defense & Space Systems
660 Engineering Dr
Norcross, GA 30092
Tel: 770-263-9200 x 4379
-----Original Message-----
From: H. Peter Anvin [mailto:hpa@zytor.com]
Sent: Tuesday, March 06, 2007 7:39 PM
To: Chen, Dongliang
Cc: linux-kernel@vger.kernel.org
Subject: Re: return negative number for unsigned long function in kernel
H. Peter Anvin wrote:
>If you want to test for errorness, you could use the macro
>IS_ERR_VALUE(). Unfortunately the macro isn't all that safe, in that
it
>will give you the wrong answer if it's ever used on something that
>*isn't* an unsigned long.
-----Original Message-----
From: Andreas Schwab [mailto:schwab@suse.de]
Sent: Tuesday, March 06, 2007 2:06 PM
To: Chen, Dongliang
Cc: linux-kernel@vger.kernel.org
Subject: Re: return negative number for unsigned long function in kernel
Andreas Schwab wrote:
>The return value is directly passed to user space (it's the guts of the
>mmap syscall). The glibc wrapper transforms it appropriately so that
errno >is set and -1 is returned if there is an error.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: return negative number for unsigned long function in kernel
2007-03-07 13:31 ` Chen, Dongliang
@ 2007-03-07 16:30 ` H. Peter Anvin
0 siblings, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2007-03-07 16:30 UTC (permalink / raw)
To: Chen, Dongliang; +Cc: Andreas Schwab, linux-kernel
Chen, Dongliang wrote:
> Peter & Andreas,
>
> Thank you very much for your help.
>
> I understood that the kernel error numbers are limited. The largest
> error number for i386 (kernel 2.6) is 131 so far. Assume that the
> virtual address returned from do_mmap_pgoff will never exceed (unsigned
> long)(-1000L), which is in the address range one page below the maximum
> virtual address, then IS_ERR_VALUE() should work.
>
The error value boundary is defined in <linux/err.h>, currently 4095.
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-03-07 16:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-06 14:52 return negative number for unsigned long function in kernel Chen, Dongliang
2007-03-06 19:05 ` Andreas Schwab
2007-03-07 0:39 ` H. Peter Anvin
2007-03-07 13:31 ` Chen, Dongliang
2007-03-07 16:30 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox