aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Vetter2015-02-11 05:03:12 -0600
committerDaniel Vetter2015-02-11 08:36:39 -0600
commit7e0460c6d4b509983307f3106ad56c6622c0c7f2 (patch)
treeac22a9e815bc357130ee822aafc5722f31872ac1 /xf86drmMode.c
parenteb7a5b6b04271af3b11b81baa8e18dc826b657dc (diff)
downloadexternal-libgbm-7e0460c6d4b509983307f3106ad56c6622c0c7f2.tar.gz
external-libgbm-7e0460c6d4b509983307f3106ad56c6622c0c7f2.tar.xz
external-libgbm-7e0460c6d4b509983307f3106ad56c6622c0c7f2.zip
xf86drmMode: Unconditionally clear ioctl structs
We really have to do this to avoid surprises when extending the ABI later on. Especially when growing the structures. Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Rob Clark <robdclark@gmail.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Diffstat (limited to 'xf86drmMode.c')
-rw-r--r--xf86drmMode.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/xf86drmMode.c b/xf86drmMode.c
index e3e599bd..9ea8fe72 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -61,7 +61,7 @@
61#define VG(x) 61#define VG(x)
62#endif 62#endif
63 63
64#define VG_CLEAR(s) VG(memset(&s, 0, sizeof(s))) 64#define memclear(s) memset(&s, 0, sizeof(s))
65 65
66#define U642VOID(x) ((void *)(unsigned long)(x)) 66#define U642VOID(x) ((void *)(unsigned long)(x))
67#define VOID2U64(x) ((uint64_t)(unsigned long)(x)) 67#define VOID2U64(x) ((uint64_t)(unsigned long)(x))
@@ -164,7 +164,7 @@ drmModeResPtr drmModeGetResources(int fd)
164 drmModeResPtr r = 0; 164 drmModeResPtr r = 0;
165 165
166retry: 166retry:
167 memset(&res, 0, sizeof(struct drm_mode_card_res)); 167 memclear(res);
168 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) 168 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
169 return 0; 169 return 0;
170 170
@@ -259,7 +259,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
259 struct drm_mode_fb_cmd f; 259 struct drm_mode_fb_cmd f;
260 int ret; 260 int ret;
261 261
262 VG_CLEAR(f); 262 memclear(f);
263 f.width = width; 263 f.width = width;
264 f.height = height; 264 f.height = height;
265 f.pitch = pitch; 265 f.pitch = pitch;
@@ -282,6 +282,7 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
282 struct drm_mode_fb_cmd2 f; 282 struct drm_mode_fb_cmd2 f;
283 int ret; 283 int ret;
284 284
285 memclear(f);
285 f.width = width; 286 f.width = width;
286 f.height = height; 287 f.height = height;
287 f.pixel_format = pixel_format; 288 f.pixel_format = pixel_format;
@@ -300,8 +301,6 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
300int drmModeRmFB(int fd, uint32_t bufferId) 301int drmModeRmFB(int fd, uint32_t bufferId)
301{ 302{
302 return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId); 303 return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
303
304
305} 304}
306 305
307drmModeFBPtr drmModeGetFB(int fd, uint32_t buf) 306drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
@@ -309,6 +308,7 @@ drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
309 struct drm_mode_fb_cmd info; 308 struct drm_mode_fb_cmd info;
310 drmModeFBPtr r; 309 drmModeFBPtr r;
311 310
311 memclear(info);
312 info.fb_id = buf; 312 info.fb_id = buf;
313 313
314 if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info)) 314 if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info))
@@ -331,8 +331,9 @@ drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
331int drmModeDirtyFB(int fd, uint32_t bufferId, 331int drmModeDirtyFB(int fd, uint32_t bufferId,
332 drmModeClipPtr clips, uint32_t num_clips) 332 drmModeClipPtr clips, uint32_t num_clips)
333{ 333{
334 struct drm_mode_fb_dirty_cmd dirty = { 0 }; 334 struct drm_mode_fb_dirty_cmd dirty;
335 335
336 memclear(dirty);
336 dirty.fb_id = bufferId; 337 dirty.fb_id = bufferId;
337 dirty.clips_ptr = VOID2U64(clips); 338 dirty.clips_ptr = VOID2U64(clips);
338 dirty.num_clips = num_clips; 339 dirty.num_clips = num_clips;
@@ -350,7 +351,7 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
350 struct drm_mode_crtc crtc; 351 struct drm_mode_crtc crtc;
351 drmModeCrtcPtr r; 352 drmModeCrtcPtr r;
352 353
353 VG_CLEAR(crtc); 354 memclear(crtc);
354 crtc.crtc_id = crtcId; 355 crtc.crtc_id = crtcId;
355 356
356 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc)) 357 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc))
@@ -384,7 +385,7 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
384{ 385{
385 struct drm_mode_crtc crtc; 386 struct drm_mode_crtc crtc;
386 387
387 VG_CLEAR(crtc); 388 memclear(crtc);
388 crtc.x = x; 389 crtc.x = x;
389 crtc.y = y; 390 crtc.y = y;
390 crtc.crtc_id = crtcId; 391 crtc.crtc_id = crtcId;
@@ -394,8 +395,7 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
394 if (mode) { 395 if (mode) {
395 memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo)); 396 memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo));
396 crtc.mode_valid = 1; 397 crtc.mode_valid = 1;
397 } else 398 }
398 crtc.mode_valid = 0;
399 399
400 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETCRTC, &crtc); 400 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
401} 401}
@@ -408,6 +408,7 @@ int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width
408{ 408{
409 struct drm_mode_cursor arg; 409 struct drm_mode_cursor arg;
410 410
411 memclear(arg);
411 arg.flags = DRM_MODE_CURSOR_BO; 412 arg.flags = DRM_MODE_CURSOR_BO;
412 arg.crtc_id = crtcId; 413 arg.crtc_id = crtcId;
413 arg.width = width; 414 arg.width = width;
@@ -421,6 +422,7 @@ int drmModeSetCursor2(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t widt
421{ 422{
422 struct drm_mode_cursor2 arg; 423 struct drm_mode_cursor2 arg;
423 424
425 memclear(arg);
424 arg.flags = DRM_MODE_CURSOR_BO; 426 arg.flags = DRM_MODE_CURSOR_BO;
425 arg.crtc_id = crtcId; 427 arg.crtc_id = crtcId;
426 arg.width = width; 428 arg.width = width;
@@ -436,6 +438,7 @@ int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y)
436{ 438{
437 struct drm_mode_cursor arg; 439 struct drm_mode_cursor arg;
438 440
441 memclear(arg);
439 arg.flags = DRM_MODE_CURSOR_MOVE; 442 arg.flags = DRM_MODE_CURSOR_MOVE;
440 arg.crtc_id = crtcId; 443 arg.crtc_id = crtcId;
441 arg.x = x; 444 arg.x = x;
@@ -452,11 +455,8 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id)
452 struct drm_mode_get_encoder enc; 455 struct drm_mode_get_encoder enc;
453 drmModeEncoderPtr r = NULL; 456 drmModeEncoderPtr r = NULL;
454 457
458 memclear(enc);
455 enc.encoder_id = encoder_id; 459 enc.encoder_id = encoder_id;
456 enc.crtc_id = 0;
457 enc.encoder_type = 0;
458 enc.possible_crtcs = 0;
459 enc.possible_clones = 0;
460 460
461 if (drmIoctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc)) 461 if (drmIoctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc))
462 return 0; 462 return 0;
@@ -483,7 +483,7 @@ drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id)
483 drmModeConnectorPtr r = NULL; 483 drmModeConnectorPtr r = NULL;
484 484
485retry: 485retry:
486 memset(&conn, 0, sizeof(struct drm_mode_get_connector)); 486 memclear(conn);
487 conn.connector_id = connector_id; 487 conn.connector_id = connector_id;
488 488
489 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn)) 489 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
@@ -576,6 +576,7 @@ int drmModeAttachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_inf
576{ 576{
577 struct drm_mode_mode_cmd res; 577 struct drm_mode_mode_cmd res;
578 578
579 memclear(res);
579 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo)); 580 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
580 res.connector_id = connector_id; 581 res.connector_id = connector_id;
581 582
@@ -586,6 +587,7 @@ int drmModeDetachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_inf
586{ 587{
587 struct drm_mode_mode_cmd res; 588 struct drm_mode_mode_cmd res;
588 589
590 memclear(res);
589 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo)); 591 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
590 res.connector_id = connector_id; 592 res.connector_id = connector_id;
591 593
@@ -598,13 +600,8 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
598 struct drm_mode_get_property prop; 600 struct drm_mode_get_property prop;
599 drmModePropertyPtr r; 601 drmModePropertyPtr r;
600 602
601 VG_CLEAR(prop); 603 memclear(prop);
602 prop.prop_id = property_id; 604 prop.prop_id = property_id;
603 prop.count_enum_blobs = 0;
604 prop.count_values = 0;
605 prop.flags = 0;
606 prop.enum_blob_ptr = 0;
607 prop.values_ptr = 0;
608 605
609 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) 606 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
610 return 0; 607 return 0;
@@ -667,8 +664,7 @@ drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id)
667 struct drm_mode_get_blob blob; 664 struct drm_mode_get_blob blob;
668 drmModePropertyBlobPtr r; 665 drmModePropertyBlobPtr r;
669 666
670 blob.length = 0; 667 memclear(blob);
671 blob.data = 0;
672 blob.blob_id = blob_id; 668 blob.blob_id = blob_id;
673 669
674 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) 670 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob))
@@ -708,6 +704,7 @@ int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property
708{ 704{
709 struct drm_mode_connector_set_property osp; 705 struct drm_mode_connector_set_property osp;
710 706
707 memclear(osp);
711 osp.connector_id = connector_id; 708 osp.connector_id = connector_id;
712 osp.prop_id = property_id; 709 osp.prop_id = property_id;
713 osp.value = value; 710 osp.value = value;
@@ -818,6 +815,7 @@ int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
818{ 815{
819 struct drm_mode_crtc_lut l; 816 struct drm_mode_crtc_lut l;
820 817
818 memclear(l);
821 l.crtc_id = crtc_id; 819 l.crtc_id = crtc_id;
822 l.gamma_size = size; 820 l.gamma_size = size;
823 l.red = VOID2U64(red); 821 l.red = VOID2U64(red);
@@ -832,6 +830,7 @@ int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
832{ 830{
833 struct drm_mode_crtc_lut l; 831 struct drm_mode_crtc_lut l;
834 832
833 memclear(l);
835 l.crtc_id = crtc_id; 834 l.crtc_id = crtc_id;
836 l.gamma_size = size; 835 l.gamma_size = size;
837 l.red = VOID2U64(red); 836 l.red = VOID2U64(red);
@@ -897,11 +896,11 @@ int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
897{ 896{
898 struct drm_mode_crtc_page_flip flip; 897 struct drm_mode_crtc_page_flip flip;
899 898
899 memclear(flip);
900 flip.fb_id = fb_id; 900 flip.fb_id = fb_id;
901 flip.crtc_id = crtc_id; 901 flip.crtc_id = crtc_id;
902 flip.user_data = VOID2U64(user_data); 902 flip.user_data = VOID2U64(user_data);
903 flip.flags = flags; 903 flip.flags = flags;
904 flip.reserved = 0;
905 904
906 return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip); 905 return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip);
907} 906}
@@ -916,6 +915,7 @@ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
916{ 915{
917 struct drm_mode_set_plane s; 916 struct drm_mode_set_plane s;
918 917
918 memclear(s);
919 s.plane_id = plane_id; 919 s.plane_id = plane_id;
920 s.crtc_id = crtc_id; 920 s.crtc_id = crtc_id;
921 s.fb_id = fb_id; 921 s.fb_id = fb_id;
@@ -939,7 +939,7 @@ drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
939 drmModePlanePtr r = 0; 939 drmModePlanePtr r = 0;
940 940
941retry: 941retry:
942 memset(&ovr, 0, sizeof(struct drm_mode_get_plane)); 942 memclear(ovr);
943 ovr.plane_id = plane_id; 943 ovr.plane_id = plane_id;
944 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr)) 944 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
945 return 0; 945 return 0;
@@ -999,7 +999,7 @@ drmModePlaneResPtr drmModeGetPlaneResources(int fd)
999 drmModePlaneResPtr r = 0; 999 drmModePlaneResPtr r = 0;
1000 1000
1001retry: 1001retry:
1002 memset(&res, 0, sizeof(struct drm_mode_get_plane_res)); 1002 memclear(res);
1003 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res)) 1003 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
1004 return 0; 1004 return 0;
1005 1005
@@ -1056,7 +1056,7 @@ drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
1056 uint32_t count; 1056 uint32_t count;
1057 1057
1058retry: 1058retry:
1059 memset(&properties, 0, sizeof(struct drm_mode_obj_get_properties)); 1059 memclear(properties);
1060 properties.obj_id = object_id; 1060 properties.obj_id = object_id;
1061 properties.obj_type = object_type; 1061 properties.obj_type = object_type;
1062 1062
@@ -1122,6 +1122,7 @@ int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type,
1122{ 1122{
1123 struct drm_mode_obj_set_property prop; 1123 struct drm_mode_obj_set_property prop;
1124 1124
1125 memclear(prop);
1125 prop.value = value; 1126 prop.value = value;
1126 prop.prop_id = property_id; 1127 prop.prop_id = property_id;
1127 prop.obj_id = object_id; 1128 prop.obj_id = object_id;