Skip to content

Commit 575445d

Browse files
Minor code cleanup
prevent nullptr dereference Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent c2ab7fc commit 575445d

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

opencl/source/memory_manager/migration_controller.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include "opencl/source/mem_obj/mem_obj.h"
1818

1919
namespace NEO {
20-
class MemoryManager;
21-
class CommandStreamReceiver;
22-
class MultiGraphicsAllocation;
2320
void MigrationController::handleMigration(Context &context, CommandStreamReceiver &targetCsr, MemObj *memObj) {
2421
auto memoryManager = targetCsr.getMemoryManager();
2522
auto targetRootDeviceIndex = targetCsr.getRootDeviceIndex();

shared/source/memory_manager/multi_graphics_allocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ StackVec<GraphicsAllocation *, 1> const &MultiGraphicsAllocation::getGraphicsAll
7474
void MultiGraphicsAllocation::setMultiStorage(bool value) {
7575
isMultiStorage = value;
7676
if (isMultiStorage && !migrationSyncData) {
77-
migrationSyncData = createMigrationSyncDataFunc(getDefaultGraphicsAllocation()->getUnderlyingBufferSize());
77+
auto graphicsAllocation = getDefaultGraphicsAllocation();
78+
UNRECOVERABLE_IF(!graphicsAllocation);
79+
migrationSyncData = createMigrationSyncDataFunc(graphicsAllocation->getUnderlyingBufferSize());
7880
migrationSyncData->incRefInternal();
7981
}
8082
}

shared/test/unit_test/memory_manager/multi_graphics_allocation_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ TEST_F(MigrationSyncDataTests, whenMigrationSyncDataExistsAndSetMultiStorageIsCa
255255
EXPECT_EQ(migrationSyncData, multiGraphicsAllocation.getMigrationSyncData());
256256
}
257257

258+
TEST(MigrationSyncDataTest, givenEmptyMultiGraphicsAllocationWhenSetMultiStorageIsCalledThenAbortIsCalled) {
259+
MultiGraphicsAllocation multiGraphicsAllocation(1);
260+
EXPECT_EQ(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation());
261+
EXPECT_THROW(multiGraphicsAllocation.setMultiStorage(true), std::exception);
262+
}
263+
258264
TEST_F(MigrationSyncDataTests, whenMigrationIsNotStartedThenMigrationIsNotInProgress) {
259265
EXPECT_FALSE(migrationSyncData->isMigrationInProgress());
260266

0 commit comments

Comments
 (0)