virgl: more checks against init args

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 4 years ago
parent bd6540c6ba
commit f875c3a288
  1. 26
      src/virglrenderer.c

@ -44,7 +44,9 @@
#include "virgl_resource.h" #include "virgl_resource.h"
struct global_state { struct global_state {
bool client_initialized;
void *cookie; void *cookie;
int flags;
const struct virgl_renderer_callbacks *cbs; const struct virgl_renderer_callbacks *cbs;
bool resource_initialized; bool resource_initialized;
@ -468,14 +470,22 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks
{ {
int ret; int ret;
if (!cookie || !cbs) if (state.client_initialized && (state.cookie != cookie ||
return -1; state.flags != flags ||
state.cbs != cbs))
if (cbs->version < 1 || cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION) return -EBUSY;
return -1;
if (!state.client_initialized) {
state.cookie = cookie; if (!cookie || !cbs)
state.cbs = cbs; return -1;
if (cbs->version < 1 || cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION)
return -1;
state.cookie = cookie;
state.flags = flags;
state.cbs = cbs;
state.client_initialized = true;
}
if (!state.resource_initialized) { if (!state.resource_initialized) {
ret = virgl_resource_table_init(vrend_renderer_get_pipe_callbacks()); ret = virgl_resource_table_init(vrend_renderer_get_pipe_callbacks());

Loading…
Cancel
Save