From b3153a5f4173f5e012021ed977cfcd50af15d6cc Mon Sep 17 00:00:00 2001 From: Marko Arandjelovic Date: Tue, 23 Jul 2024 10:22:58 +0200 Subject: [PATCH] SWDEV-475114 - Prevent segfaults in hipBindTexture Change-Id: I050f36a5c74a5d4542155040ccce043fee6b73ad --- hipamd/src/hip_texture.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hipamd/src/hip_texture.cpp b/hipamd/src/hip_texture.cpp index 3d2d184dbc..57ecfe3848 100644 --- a/hipamd/src/hip_texture.cpp +++ b/hipamd/src/hip_texture.cpp @@ -392,7 +392,9 @@ hipError_t ihipDestroyTextureObject(hipTextureObject_t texObject) { return hipErrorNotSupported; } - texObject->image->release(); + if (texObject != nullptr && texObject->image) { + texObject->image->release(); + } // The texture object always owns the sampler SRD. texObject->sampler->release(); @@ -554,7 +556,8 @@ hipError_t ihipBindTexture(size_t* offset, } // Align the user ptr to HW requirments. - resDesc.res.linear.devPtr = static_cast(const_cast(devPtr)) - *offset; + resDesc.res.linear.devPtr = + static_cast(const_cast(devPtr)) - (offset != nullptr ? *offset : 0); hipTextureDesc texDesc = hip::getTextureDesc(texref); return ihipCreateTextureObject(const_cast(&texref->textureObject), &resDesc, &texDesc, nullptr); @@ -569,7 +572,8 @@ hipError_t ihipBindTexture2D(size_t* offset, size_t pitch) { if ((texref == nullptr) || (devPtr == nullptr) || - (desc == nullptr)) { + (desc == nullptr) || + (pitch == 0)) { return hipErrorInvalidValue; } @@ -594,7 +598,8 @@ hipError_t ihipBindTexture2D(size_t* offset, } // Align the user ptr to HW requirments. - resDesc.res.pitch2D.devPtr = static_cast(const_cast(devPtr)) - *offset; + resDesc.res.pitch2D.devPtr = + static_cast(const_cast(devPtr)) - (offset != nullptr ? *offset : 0); hipTextureDesc texDesc = hip::getTextureDesc(texref); return ihipCreateTextureObject(const_cast(&texref->textureObject), &resDesc, &texDesc, nullptr);