[Cbe-oss-dev] [PATCH 10/22]MARS/base: context negative num mpus segfault
Yuji Mano
yuji.mano at am.sony.com
Fri Mar 20 07:54:17 EST 2009
This patch fixes a bug that would result in a segfault if a negative number of
mpus are requested when creating a MARS context.
Also the internal function mars_mpu_max() now returns 0 as a successful result.
The caller is responsible for handling a return of 0 appropriately.
MARS_ERROR_INTERNAL is only returned if there was some error to retrieve the
count.
Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
base/include/host/mars/context.h | 5 +++--
base/src/host/lib/context.c | 6 ++++--
base/src/host/lib/context_internal.h | 2 +-
base/src/host/lib/mpu_cell.c | 12 ++++++++----
4 files changed, 16 insertions(+), 9 deletions(-)
--- a/base/include/host/mars/context.h
+++ b/base/include/host/mars/context.h
@@ -88,12 +88,13 @@ extern "C" {
* each MARS context will suffer the large over head of MPU context switches.
*
* \param[out] mars - address of pointer to MARS context
- * \param[in] num_mpus - number of mpus utilized by MARS context
+ * \param[in] num_mpus - number of mpus requested by MARS context
* \param[in] shared - specifies if context is shared or not
* \return
* MARS_SUCCESS - successfully created MARS context
* \n MARS_ERROR_NULL - null pointer specified
- * \n MARS_ERROR_PARAMS - bad MARS params specified
+ * \n MARS_ERROR_LIMIT - no more available MPUs
+ * \n MARS_ERROR_PARAMS - more MPUs requested than there are available
* \n MARS_ERROR_MEMORY - not enough memory
* \n MARS_ERROR_INTERNAL - some internal error occurred
*/
--- a/base/src/host/lib/context.c
+++ b/base/src/host/lib/context.c
@@ -183,7 +183,7 @@ int mars_context_create(struct mars_cont
uint8_t shared)
{
int ret;
- int num_mpus_max;
+ uint32_t num_mpus_max;
struct mars_context *mars = NULL;
/* check function params */
@@ -194,7 +194,9 @@ int mars_context_create(struct mars_cont
ret = mars_mpu_max(&num_mpus_max);
if (ret != MARS_SUCCESS)
return ret;
- if (num_mpus_max < (int)num_mpus)
+ if (!num_mpus_max)
+ return MARS_ERROR_LIMIT;
+ if (num_mpus > num_mpus_max)
return MARS_ERROR_PARAMS;
if (!num_mpus)
num_mpus = num_mpus_max;
--- a/base/src/host/lib/context_internal.h
+++ b/base/src/host/lib/context_internal.h
@@ -72,7 +72,7 @@ struct mars_context {
mars_callback_t callback_handler;
};
-int mars_mpu_max(int *num);
+int mars_mpu_max(uint32_t *num);
int mars_mpu_run(mars_mpu_context_t *mpu, uint64_t params_ea);
int mars_mpu_wait(mars_mpu_context_t *mpu);
--- a/base/src/host/lib/mpu_cell.c
+++ b/base/src/host/lib/mpu_cell.c
@@ -89,16 +89,20 @@ static int numa_mpu_max(void)
extern const unsigned char mars_kernel_entry[];
-int mars_mpu_max(int *num)
+int mars_mpu_max(uint32_t *num)
{
+ int mpu_max;
+
if (mars_numa_enabled())
- *num = numa_mpu_max();
+ mpu_max = numa_mpu_max();
else
- *num = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1);
+ mpu_max = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1);
- if (*num <= 0)
+ if (mpu_max < 0)
return MARS_ERROR_INTERNAL;
+ *num = mpu_max;
+
return MARS_SUCCESS;
}
More information about the cbe-oss-dev
mailing list