Subject: Miscellaneous fixes for SPU profiling code

From: Maynard Johnson <maynardj@us.ibm.com>

After applying the "cleanup spu oprofile code" patch posted by Arnd Bergmann
on Feb 26, 2007, I found a few issues that required fixing up:
  -  Bug fix:  Initialize retval in spu_task_sync.c, line 95, otherwise this
         function returns non-zero and OProfile fails.
  -  Remove unused codes in include/linux/oprofile.h
  -  Compile warnings:  Initialize offset and spu_cookie at lines 283 and 284
         in spu_task_sync.c.
 
Additionally, in a separate email, Arnd pointed out a bug in
spu_task_sync.c:process_context_switch, where we were ignoring invalid
values in the dcookies returned from get_exec_dcookie_and_offset.  This is
fixed in this patch so that we now fail with ENOENT if either cookie is invalid.

Signed-off-by: Maynard Johnson <maynardj@us.ibm.com>

diff -paur linux-orig/arch/powerpc/oprofile/cell/spu_task_sync.c linux-new/arch/powerpc/oprofile/cell/spu_task_sync.c
--- linux-orig/arch/powerpc/oprofile/cell/spu_task_sync.c	2007-02-27 17:10:24.000000000 -0600
+++ linux-new/arch/powerpc/oprofile/cell/spu_task_sync.c	2007-02-28 15:46:45.000000000 -0600
@@ -92,7 +92,7 @@ prepare_cached_spu_info(struct spu * spu
 {
 	unsigned long flags;
 	struct vma_to_fileoffset_map * new_map;
-	int retval;
+	int retval = 0;
 	struct cached_info * info;
 
         /* We won't bother getting cache_lock here since
@@ -280,8 +280,8 @@ static int process_context_switch(struct
 {
 	unsigned long flags;
 	int retval;
-	unsigned int offset;
-	unsigned long spu_cookie, app_dcookie;
+	unsigned int offset = 0;
+	unsigned long spu_cookie = 0, app_dcookie;
 	retval = prepare_cached_spu_info(spu, objectId);
 	if (retval)
 		goto out;
@@ -290,6 +290,10 @@ static int process_context_switch(struct
 	 * code path, so interrupts must not be disabled.
 	 */
 	app_dcookie = get_exec_dcookie_and_offset(spu, &offset, &spu_cookie, objectId);
+	if (!app_dcookie || !spu_cookie) {
+		retval  = -ENOENT;
+		goto out;
+	}
 
         /* Record context info in event buffer */
 	spin_lock_irqsave(&buffer_lock, flags);
diff -paur linux-orig/include/linux/oprofile.h linux-new/include/linux/oprofile.h
--- linux-orig/include/linux/oprofile.h	2007-02-27 14:41:29.000000000 -0600
+++ linux-new/include/linux/oprofile.h	2007-02-27 14:43:18.000000000 -0600
@@ -36,9 +36,6 @@
 #define XEN_ENTER_SWITCH_CODE          10
 #define SPU_PROFILING_CODE             11
 #define SPU_CTX_SWITCH_CODE            12
-#define SPU_OFFSET_CODE                13
-#define SPU_COOKIE_CODE                14
-#define SPU_SHLIB_COOKIE_CODE          15
 
 struct super_block;
 struct dentry;
