[Cbe-oss-dev] [PATCH 1/4] libspe2: Eliminate explicit (void*)-1

Kazunori Asayama asayama at sm.sony.co.jp
Wed Apr 25 22:34:30 EST 2007


Here is a patch to eliminate internal use of explicit (void*)-1.

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>

Index: libspe2-public/spebase/accessors.c
===================================================================
--- libspe2-public.orig/spebase/accessors.c
+++ libspe2-public/spebase/accessors.c
@@ -21,6 +21,7 @@
 
 #include <fcntl.h>
 #include <errno.h>
+#include <sys/mman.h>
 
  /*
  * accessor functions for private members 
@@ -62,7 +63,7 @@ void* _base_spe_ps_area_get(spe_context_
 			break;
 	}
 
-	if (ptr == (void*)-1) {
+	if (ptr == MAP_FAILED) {
 		errno = EACCES;
 		return NULL;
 	}
Index: libspe2-public/spebase/create.c
===================================================================
--- libspe2-public.orig/spebase/create.c
+++ libspe2-public/spebase/create.c
@@ -63,7 +63,7 @@ void *mapfileat( int dir, const char* fi
 	if (fd_temp < 0) {
 		DEBUG_PRINTF ("ERROR: Could not open SPE %s file.\n",filename);
 		errno=EFAULT;
-		return (void *)-1;
+		return MAP_FAILED;
 	}
 	ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_temp, 0);
 	close(fd_temp);
@@ -136,23 +136,23 @@ static int free_spe_context(struct spe_c
 {
 	int i;
 
-	if(spe->base_private->psmap_mmap_base != (void*)-1) {
+	if(spe->base_private->psmap_mmap_base != MAP_FAILED) {
 		munmap(spe->base_private->psmap_mmap_base, PSMAP_SIZE);
 	}
 	else {
-		if(spe->base_private->mfc_mmap_base != (void*)-1)
+		if(spe->base_private->mfc_mmap_base != MAP_FAILED)
 			munmap(spe->base_private->mfc_mmap_base, MFC_SIZE);
-		if(spe->base_private->mssync_mmap_base != (void*)-1)
+		if(spe->base_private->mssync_mmap_base != MAP_FAILED)
 			munmap(spe->base_private->mssync_mmap_base, MSS_SIZE);
-		if(spe->base_private->cntl_mmap_base != (void*)-1)
+		if(spe->base_private->cntl_mmap_base != MAP_FAILED)
 			munmap(spe->base_private->cntl_mmap_base, CNTL_SIZE);
-		if(spe->base_private->signal1_mmap_base != (void*)-1)
+		if(spe->base_private->signal1_mmap_base != MAP_FAILED)
 			munmap(spe->base_private->signal1_mmap_base,SIGNAL_SIZE);
-		if(spe->base_private->signal2_mmap_base != (void*)-1)
+		if(spe->base_private->signal2_mmap_base != MAP_FAILED)
 			munmap(spe->base_private->signal2_mmap_base, SIGNAL_SIZE);
 	}
 
-	if(spe->base_private->mem_mmap_base != (void*)-1)
+	if(spe->base_private->mem_mmap_base != MAP_FAILED)
 		munmap(spe->base_private->mem_mmap_base, LS_SIZE);
 
 	for ( i=0;i<NUM_MBOX_FDS;i++){
@@ -198,13 +198,13 @@ spe_context_ptr_t _base_spe_context_crea
 
 	spe->base_private->fd_spe_dir = -1;
 	
-	spe->base_private->mem_mmap_base = (void*) -1;
-	spe->base_private->psmap_mmap_base = (void*) -1;
-	spe->base_private->mssync_mmap_base = (void*) -1;
-	spe->base_private->mfc_mmap_base = (void*) -1;
-	spe->base_private->cntl_mmap_base = (void*) -1;
-	spe->base_private->signal1_mmap_base = (void*) -1;
-	spe->base_private->signal2_mmap_base = (void*) -1;
+	spe->base_private->mem_mmap_base = MAP_FAILED;
+	spe->base_private->psmap_mmap_base = MAP_FAILED;
+	spe->base_private->mssync_mmap_base = MAP_FAILED;
+	spe->base_private->mfc_mmap_base = MAP_FAILED;
+	spe->base_private->cntl_mmap_base = MAP_FAILED;
+	spe->base_private->signal1_mmap_base = MAP_FAILED;
+	spe->base_private->signal2_mmap_base = MAP_FAILED;
 	
 	for ( i=0;i<NUM_MBOX_FDS;i++){
 		spe->base_private->spe_fds_array[i]=-1;



More information about the cbe-oss-dev mailing list