diff --git a/runtime/os_interface/linux/drm_buffer_object.cpp b/runtime/os_interface/linux/drm_buffer_object.cpp index bdebb26332..8fc041160c 100644 --- a/runtime/os_interface/linux/drm_buffer_object.cpp +++ b/runtime/os_interface/linux/drm_buffer_object.cpp @@ -70,11 +70,8 @@ bool BufferObject::softPin(uint64_t offset) { }; bool BufferObject::close() { - struct drm_gem_close close; - - memset(&close, 0, sizeof(close)); + drm_gem_close close = {}; close.handle = this->handle; - close.pad = 0; int ret = this->drm->ioctl(DRM_IOCTL_GEM_CLOSE, &close); if (ret != 0) { @@ -90,10 +87,8 @@ bool BufferObject::close() { } int BufferObject::wait(int64_t timeoutNs) { - struct drm_i915_gem_wait wait; - + drm_i915_gem_wait wait = {}; wait.bo_handle = this->handle; - wait.flags = 0; wait.timeout_ns = -1; int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_WAIT, &wait); @@ -111,16 +106,12 @@ bool BufferObject::setTiling(uint32_t mode, uint32_t stride) { return true; } - drm_i915_gem_set_tiling set_tiling; - - memset(&set_tiling, 0, sizeof(set_tiling)); - + drm_i915_gem_set_tiling set_tiling = {}; set_tiling.handle = this->handle; set_tiling.tiling_mode = mode; set_tiling.stride = stride; - int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - if (ret != 0) { + if (this->drm->ioctl(DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling) != 0) { return false; } @@ -152,14 +143,13 @@ void BufferObject::processRelocs(int &idx) { } int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, bool lowPriority) { - drm_i915_gem_execbuffer2 execbuf; + drm_i915_gem_execbuffer2 execbuf = {}; int idx = 0; processRelocs(idx); this->fillExecObject(execObjectsStorage[idx]); idx++; - memset(&execbuf, 0, sizeof(execbuf)); execbuf.buffers_ptr = reinterpret_cast(execObjectsStorage); execbuf.buffer_count = idx; execbuf.batch_start_offset = static_cast(startOffset); @@ -167,9 +157,9 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo execbuf.flags = flags; if (drm->peekCoherencyDisablePatchActive() && !requiresCoherency) { - execbuf.flags |= (uint64_t)I915_PRIVATE_EXEC_FORCE_NON_COHERENT; + execbuf.flags |= I915_PRIVATE_EXEC_FORCE_NON_COHERENT; } else if (drm->peekDataPortCoherencyPatchActive() && requiresCoherency) { - execbuf.flags |= (uint64_t)I915_EXEC_DATA_PORT_COHERENT; + execbuf.flags |= I915_EXEC_DATA_PORT_COHERENT; } if (lowPriority) { execbuf.rsvd1 = this->drm->lowPriorityContextId & I915_EXEC_CONTEXT_ID_MASK; @@ -186,7 +176,7 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo } int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos) { - drm_i915_gem_execbuffer2 execbuf; + drm_i915_gem_execbuffer2 execbuf = {}; StackVec execObject; reinterpret_cast(this->address)[0] = 0x05000000; @@ -201,7 +191,6 @@ int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos) { this->fillExecObject(execObject[boIndex]); - memset(&execbuf, 0, sizeof(execbuf)); execbuf.buffers_ptr = reinterpret_cast(&execObject[0]); execbuf.buffer_count = boIndex + 1; execbuf.batch_len = alignUp(static_cast(sizeof(uint32_t)), 8); diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 34983a6234..da50395b53 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -145,17 +145,14 @@ uint32_t DrmMemoryManager::unreference(OCLRT::BufferObject *bo, bool synchronous } OCLRT::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, bool softpin) { - struct drm_i915_gem_userptr userptr; - - memset(&userptr, 0, sizeof(userptr)); + drm_i915_gem_userptr userptr = {}; userptr.user_ptr = address; userptr.user_size = size; userptr.flags = static_cast(flags); - int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_USERPTR, - &userptr); - if (ret != 0) + if (this->drm->ioctl(DRM_IOCTL_I915_GEM_USERPTR, &userptr) != 0) { return nullptr; + } auto res = new (std::nothrow) BufferObject(this->drm, userptr.handle, false); if (!res) { @@ -546,17 +543,12 @@ bool DrmMemoryManager::setDomainCpu(GraphicsAllocation &graphicsAllocation, bool return false; // move a buffer object to the CPU read, and possibly write domain, including waiting on flushes to occur - struct drm_i915_gem_set_domain set_domain; - memset(&set_domain, 0, sizeof(set_domain)); + drm_i915_gem_set_domain set_domain = {}; set_domain.handle = bo->peekHandle(); set_domain.read_domains = I915_GEM_DOMAIN_CPU; set_domain.write_domain = writeEnable ? I915_GEM_DOMAIN_CPU : 0; - auto ret = drm->ioctl(DRM_IOCTL_I915_GEM_SET_DOMAIN, - &set_domain); - if (ret != 0) - return false; - return true; + return drm->ioctl(DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain) == 0; } void *DrmMemoryManager::lockResource(GraphicsAllocation *graphicsAllocation) { @@ -575,14 +567,12 @@ void *DrmMemoryManager::lockResource(GraphicsAllocation *graphicsAllocation) { if (bo == nullptr) return nullptr; - struct drm_i915_gem_mmap mmap_arg; - memset(&mmap_arg, 0, sizeof(mmap_arg)); + drm_i915_gem_mmap mmap_arg = {}; mmap_arg.handle = bo->peekHandle(); mmap_arg.size = bo->peekSize(); - auto ret = drm->ioctl(DRM_IOCTL_I915_GEM_MMAP, - &mmap_arg); - if (ret != 0) + if (drm->ioctl(DRM_IOCTL_I915_GEM_MMAP, &mmap_arg) != 0) { return nullptr; + } bo->setLockedAddress(reinterpret_cast(mmap_arg.addr_ptr)); diff --git a/runtime/os_interface/linux/drm_neo.cpp b/runtime/os_interface/linux/drm_neo.cpp index 4398ab5015..e0e41ca6f9 100644 --- a/runtime/os_interface/linux/drm_neo.cpp +++ b/runtime/os_interface/linux/drm_neo.cpp @@ -74,14 +74,11 @@ int Drm::getExecSoftPin(int &execSoftPin) { } int Drm::enableTurboBoost() { - int ret = 0; - struct drm_i915_gem_context_param contextParam; + drm_i915_gem_context_param contextParam = {}; - memset(&contextParam, 0, sizeof(contextParam)); contextParam.param = I915_CONTEXT_PRIVATE_PARAM_BOOST; contextParam.value = 1; - ret = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &contextParam); - return ret; + return ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &contextParam); } int Drm::getEnabledPooledEu(int &enabled) { @@ -136,8 +133,7 @@ std::string Drm::getSysFsPciPath(int deviceID) { std::vector files = Directory::getFiles(sysFsPciDirectory); for (std::vector::iterator file = files.begin(); file != files.end(); ++file) { - PCIConfig config; - memset(&config, 0, sizeof(PCIConfig)); + PCIConfig config = {}; std::string configPath = *file + configFileName; std::string sysfsPath = *file; std::ifstream configFile(configPath, std::ifstream::binary); @@ -173,7 +169,7 @@ bool Drm::hasPreemption() { bool Drm::setLowPriority() { #if defined(I915_PARAM_HAS_PREEMPTION) - struct drm_i915_gem_context_param gcp = {0}; + struct drm_i915_gem_context_param gcp = {}; gcp.ctx_id = lowPriorityContextId; gcp.param = I915_CONTEXT_PARAM_PRIORITY; gcp.value = -1023; @@ -188,10 +184,8 @@ bool Drm::setLowPriority() { bool Drm::contextCreate() { #if defined(I915_PARAM_HAS_PREEMPTION) - struct drm_i915_gem_context_create gcc; - memset(&gcc, 0, sizeof(gcc)); - int ret = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &gcc); - if (ret == 0) { + drm_i915_gem_context_create gcc = {}; + if (ioctl(DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &gcc) == 0) { lowPriorityContextId = gcc.ctx_id; return true; } @@ -201,7 +195,7 @@ bool Drm::contextCreate() { void Drm::contextDestroy() { #if defined(I915_PARAM_HAS_PREEMPTION) - struct drm_i915_gem_context_destroy destroy; + drm_i915_gem_context_destroy destroy = {}; destroy.ctx_id = lowPriorityContextId; ioctl(DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); #endif