xf86drmMode: smoke-test the atomic API

As going through the modetest patches for atomic support I've noticed
that if we pass NULL for the drmModeAtomicReqPtr argument we'll crash.

So let's handle things appropriately if the user forgot to check the
return value of drmModeAtomicAlloc and drmModeAtomicDuplicate or made a
typo somewhere along the way.

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Rob Clark <robclark@freedesktop.org>
Cc: Daniel Stone <daniels@collabora.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
main
Emil Velikov 2015-09-05 17:20:53 +01:00
parent 00808a99d0
commit ed3c665548
1 changed files with 16 additions and 1 deletions

View File

@ -1189,6 +1189,9 @@ drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old)
{ {
drmModeAtomicReqPtr new; drmModeAtomicReqPtr new;
if (!old)
return NULL;
new = drmMalloc(sizeof *new); new = drmMalloc(sizeof *new);
if (!new) if (!new)
return NULL; return NULL;
@ -1213,6 +1216,9 @@ drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old)
int drmModeAtomicMerge(drmModeAtomicReqPtr base, drmModeAtomicReqPtr augment) int drmModeAtomicMerge(drmModeAtomicReqPtr base, drmModeAtomicReqPtr augment)
{ {
if (!base)
return -EINVAL;
if (!augment || augment->cursor == 0) if (!augment || augment->cursor == 0)
return 0; return 0;
@ -1239,12 +1245,15 @@ int drmModeAtomicMerge(drmModeAtomicReqPtr base, drmModeAtomicReqPtr augment)
int drmModeAtomicGetCursor(drmModeAtomicReqPtr req) int drmModeAtomicGetCursor(drmModeAtomicReqPtr req)
{ {
if (!req)
return -EINVAL;
return req->cursor; return req->cursor;
} }
void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor) void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor)
{ {
req->cursor = cursor; if (req)
req->cursor = cursor;
} }
int drmModeAtomicAddProperty(drmModeAtomicReqPtr req, int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
@ -1252,6 +1261,9 @@ int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
uint32_t property_id, uint32_t property_id,
uint64_t value) uint64_t value)
{ {
if (!req)
return -EINVAL;
if (req->cursor >= req->size_items) { if (req->cursor >= req->size_items) {
drmModeAtomicReqItemPtr new; drmModeAtomicReqItemPtr new;
@ -1309,6 +1321,9 @@ int drmModeAtomicCommit(int fd, drmModeAtomicReqPtr req, uint32_t flags,
int obj_idx = -1; int obj_idx = -1;
int ret = -1; int ret = -1;
if (!req)
return -EINVAL;
if (req->cursor == 0) if (req->cursor == 0)
return 0; return 0;