Commit 8135adb5 authored by Jens Korinth's avatar Jens Korinth
Browse files

Fix tapasco_create/destroy_device

parent 96367750
......@@ -62,7 +62,7 @@ tapasco_res_t _tapasco_init(const char *const version, tapasco_ctx_t **ctx)
return TAPASCO_ERR_VERSION_MISMATCH;
}
*ctx = (tapasco_ctx_t *)malloc(sizeof(**ctx));
*ctx = (tapasco_ctx_t *)calloc(sizeof(**ctx), 1);
tapasco_ctx_t *c = *ctx;
if (! c) {
ERR("could not allocate tapasco context");
......@@ -110,11 +110,9 @@ void tapasco_deinit(tapasco_ctx_t *ctx)
{
LOG(LALL_INIT, "shutting down TaPaSCo");
if (ctx) {
if (ctx->devinfo) {
free(ctx->devinfo);
}
if (ctx->pctx) {
platform_deinit(ctx->pctx);
ctx->pctx = NULL;
}
free(ctx);
}
......
......@@ -46,17 +46,23 @@ tapasco_res_t tapasco_create_device(tapasco_ctx_t *ctx,
tapasco_devctx_t **pdevctx,
tapasco_device_create_flag_t const flags)
{
tapasco_devctx_t *p = (tapasco_devctx_t *)
malloc(sizeof(struct tapasco_devctx));
tapasco_devctx_t *p = (tapasco_devctx_t *)malloc(sizeof(struct tapasco_devctx));
if (! p) {
ERR("could not allocate tapasco device context");
return TAPASCO_ERR_OUT_OF_MEMORY;
}
platform_res_t pr = platform_init(&p->pctx);
assert(ctx->pctx);
platform_access_t access;
switch (flags) {
case TAPASCO_DEVICE_CREATE_SHARED: access = PLATFORM_SHARED_ACCESS; break;
case TAPASCO_DEVICE_CREATE_MONITOR: access = PLATFORM_MONITOR_ACCESS; break;
default: access = PLATFORM_EXCLUSIVE_ACCESS; break;
}
platform_res_t pr = platform_create_device(ctx->pctx, dev_id, access, &p->pdctx);
if (pr != PLATFORM_SUCCESS) {
ERR("platform context init failed, error: %s (%d)",
platform_strerror(pr), pr);
ERR("creating platform device failed, error: %s (%d)", platform_strerror(pr), pr);
return TAPASCO_ERR_PLATFORM_FAILURE;
}
......@@ -78,7 +84,7 @@ void tapasco_destroy_device(tapasco_ctx_t *ctx, tapasco_devctx_t *devctx)
tapasco_local_mem_deinit(devctx->lmem);
tapasco_jobs_deinit(devctx->jobs);
tapasco_pemgmt_deinit(devctx->pemgmt);
platform_deinit(devctx->pctx);
platform_destroy_device(ctx->pctx, devctx->pdctx);
free(devctx);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment