Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU] Add checks for potential null pointers (#33547)

Alexandru Enache96863b85dc99
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
index d54649a551b..03662b02bab 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
@@ -91,8 +91,9 @@ std::pair<uint64_t, std::optional<std::vector<uint64_t>>> Graph::export_blob(std
OPENVINO_THROW("Model was imported and released after initialization. Model export is not allowed anymore.");
}
- if (_blob ==
- std::nullopt) { // when compiling the model using Compiler in Driver, the blob is handled by the driver
+ if (_blob == std::nullopt) {
+ OPENVINO_ASSERT(_zeGraphExt != nullptr, "Zero compiler adapter wasn't initialized");
+ // when compiling the model using Compiler in Driver, the blob is handled by the driver
_zeGraphExt->getGraphBinary(_graphDesc, blobVec, blobPtr, blobSize);
} else { // in all other cases, the blob is handled by the plugin
blobPtr = static_cast<const uint8_t*>(_blob->data());
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
index 85f0bebec74..7839a9181a8 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
@@ -75,13 +75,11 @@ PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStruc
_logger.info("Loading PLUGIN compiler");
try {
auto vclCompilerPtr = VCLCompilerImpl::getInstance();
+ OPENVINO_ASSERT(vclCompilerPtr != nullptr, "VCL compiler is nullptr");
auto vclLib = vclCompilerPtr->getLinkedLibrary();
_logger.info("PLUGIN VCL compiler is loading");
- if (vclCompilerPtr && vclLib) {
- _compiler = ov::SoPtr<intel_npu::ICompiler>(vclCompilerPtr, vclLib);
- } else {
- throw std::runtime_error("VCL compiler or library is nullptr");
- }
+ OPENVINO_ASSERT(vclLib != nullptr, "VCL library is nullptr");
+ _compiler = ov::SoPtr<intel_npu::ICompiler>(vclCompilerPtr, vclLib);
} catch (const std::exception& vcl_exception) {
_logger.info("VCL compiler load failed: %s. Trying to load MLIR compiler...", vcl_exception.what());
std::string baseName = "npu_mlir_compiler";
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp
index ddd40288081..a5f4d75aabe 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp
@@ -198,6 +198,7 @@ std::pair<uint64_t, std::optional<std::vector<uint64_t>>> WeightlessGraph::expor
std::vector<uint8_t> blob;
if (blobTensor == std::nullopt) {
+ OPENVINO_ASSERT(_zeGraphExt != nullptr, "Zero compiler adapter wasn't initialized");
// when compiling the model using Compiler in Driver, the blob is handled by the driver
_zeGraphExt->getGraphBinary(_graphDesc, blob, blobRawPtr, blobSize);
} else {