Subject: Miscellaneous fixes for SPU profiling code From: Maynard Johnson 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 Signed-off-by: Arnd Bergmann Index: linux-2.6/arch/powerpc/oprofile/cell/spu_task_sync.c =================================================================== --- linux-2.6.orig/arch/powerpc/oprofile/cell/spu_task_sync.c +++ linux-2.6/arch/powerpc/oprofile/cell/spu_task_sync.c @@ -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) @@ -291,6 +291,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); Index: linux-2.6/include/linux/oprofile.h =================================================================== --- linux-2.6.orig/include/linux/oprofile.h +++ linux-2.6/include/linux/oprofile.h @@ -23,22 +23,19 @@ * These #defines live in this file so that arch-specific * buffer sync'ing code can access them. */ -#define ESCAPE_CODE ~0UL -#define CTX_SWITCH_CODE 1 -#define CPU_SWITCH_CODE 2 -#define COOKIE_SWITCH_CODE 3 -#define KERNEL_ENTER_SWITCH_CODE 4 -#define KERNEL_EXIT_SWITCH_CODE 5 -#define MODULE_LOADED_CODE 6 -#define CTX_TGID_CODE 7 -#define TRACE_BEGIN_CODE 8 -#define TRACE_END_CODE 9 +#define ESCAPE_CODE ~0UL +#define CTX_SWITCH_CODE 1 +#define CPU_SWITCH_CODE 2 +#define COOKIE_SWITCH_CODE 3 +#define KERNEL_ENTER_SWITCH_CODE 4 +#define KERNEL_EXIT_SWITCH_CODE 5 +#define MODULE_LOADED_CODE 6 +#define CTX_TGID_CODE 7 +#define TRACE_BEGIN_CODE 8 +#define TRACE_END_CODE 9 #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;