[Mesa-dev] [PATCH] i965: Use C99 struct initializers in brw_bufmgr.c.
Chris Wilson
chris at chris-wilson.co.uk
Sun Nov 26 10:21:01 UTC 2017
Quoting Kenneth Graunke (2017-11-26 10:08:49)
> This is cleaner than using a non-standard memclear macro (which does a
> memset to 0) and then initializing fields after the fact. We move the
> declarations to where we initialized the fields. While we're at it, we
> move the declaration of 'ret' that goes with the ioctl, eliminating the
> declaration section altogether.
> ---
> @@ -990,15 +965,15 @@ brw_bo_subdata(struct brw_bo *bo, uint64_t offset,
> uint64_t size, const void *data)
> {
> struct brw_bufmgr *bufmgr = bo->bufmgr;
> - struct drm_i915_gem_pwrite pwrite;
> - int ret;
>
> - memclear(pwrite);
> - pwrite.handle = bo->gem_handle;
> - pwrite.offset = offset;
> - pwrite.size = size;
> - pwrite.data_ptr = (uint64_t) (uintptr_t) data;
> - ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
> + struct drm_i915_gem_pwrite pwrite = {
> + .handle = bo->gem_handle,
> + .offset = offset,
> + .size = size,
> + .data_ptr = (uint64_t) (uintptr_t) data,
The (uint64_t) here is implicit in the assignment, just (uintptr_t) is
required to keep gcc quiet.
> + };
> +
> + int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
> if (ret != 0) {
> ret = -errno;
> DBG("%s:%d: Error writing data to buffer %d: "
> @@ -1050,17 +1025,16 @@ int
> brw_bo_wait(struct brw_bo *bo, int64_t timeout_ns)
> {
> struct brw_bufmgr *bufmgr = bo->bufmgr;
> - struct drm_i915_gem_wait wait;
> - int ret;
>
> /* If we know it's idle, don't bother with the kernel round trip */
> if (bo->idle && !bo->external)
> return 0;
>
> - memclear(wait);
> - wait.bo_handle = bo->gem_handle;
> - wait.timeout_ns = timeout_ns;
> - ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_WAIT, &wait);
> + struct drm_i915_gem_wait wait = {
> + .bo_handle = bo->gem_handle,
> + .timeout_ns = timeout_ns,
> + };
> + int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_WAIT, &wait);
> if (ret == -1)
> return -errno;
if (ret != 0) should be tidier for gcc, but more about being consistent.
> @@ -1330,11 +1299,8 @@ init_cache_buckets(struct brw_bufmgr *bufmgr)
> uint32_t
> brw_create_hw_context(struct brw_bufmgr *bufmgr)
> {
> - struct drm_i915_gem_context_create create;
> - int ret;
> -
> - memclear(create);
> - ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
> + struct drm_i915_gem_context_create create = { };
= { /* keep valgrind happy */ } ?
> + int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
> if (ret != 0) {
> DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
> return 0;
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
-Chris
More information about the mesa-dev
mailing list