Fixed false positive mmap return value error checks.

Normally a pointer with its topmost bits set may cause false errors
due to the fact that such pointers result in negative integer casts.

The remedy is to use IS_ERR() macro that accepts only down to -1000
as error and any values below as valid.
This commit is contained in:
Bahadir Balban
2009-12-04 13:34:14 +02:00
parent 2b89fed572
commit 21545152c8
2 changed files with 3 additions and 3 deletions

View File

@@ -33,7 +33,7 @@ int mmaptest(void)
if (write(fd, &x, sizeof(x)) < 0)
goto out_err;
if ((int)(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) < 0)
if (IS_ERR(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)))
goto out_err;
*(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;

View File

@@ -49,8 +49,8 @@ int user_mutex_test(void)
* Create a shared anonymous memory region. This can be
* accessed by both parent and child after a fork.
*/
if ((int)(base = mmap(0, map_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, 0, 0)) < 0) {
if (IS_ERR(base = mmap(0, map_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, 0, 0))) {
printf("%s: mmap for extended ipc buffer failed: %x\n",
__FUNCTION__, (int)base);
goto out_err;