diff options
Diffstat (limited to 'firmware/2lib/2misc.c')
-rw-r--r-- | firmware/2lib/2misc.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c index 5d82fc03..95cbae35 100644 --- a/firmware/2lib/2misc.c +++ b/firmware/2lib/2misc.c @@ -121,9 +121,18 @@ int vb2_init_context(struct vb2_context *ctx) { struct vb2_shared_data *sd = vb2_get_sd(ctx); - /* Don't do anything if the context has already been initialized */ - if (ctx->workbuf_used) + /* Don't do anything if context and workbuf have already been + * initialized. */ + if (ctx->workbuf_used) { + if (sd->magic != VB2_SHARED_DATA_MAGIC) + return VB2_ERROR_SHARED_DATA_MAGIC; + + if (sd->struct_version_major != VB2_SHARED_DATA_VERSION_MAJOR || + sd->struct_version_minor < VB2_SHARED_DATA_VERSION_MINOR) + return VB2_ERROR_SHARED_DATA_VERSION; + return VB2_SUCCESS; + } /* * Workbuf had better be big enough for our shared data struct and @@ -137,6 +146,9 @@ int vb2_init_context(struct vb2_context *ctx) /* Initialize the shared data at the start of the work buffer */ memset(sd, 0, sizeof(*sd)); + sd->magic = VB2_SHARED_DATA_MAGIC; + sd->struct_version_major = VB2_SHARED_DATA_VERSION_MAJOR; + sd->struct_version_minor = VB2_SHARED_DATA_VERSION_MINOR; ctx->workbuf_used = vb2_wb_round_up(sizeof(*sd)); return VB2_SUCCESS; } |