[v3,6/8] ml/cnxk: check for null pointer before dereference

Message ID 20230316212904.9318-7-syalavarthi@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series Fixes to ml/cnxk driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Srikanth Yalavarthi March 16, 2023, 9:29 p.m. UTC
  Fix deference before null check. Issue reported by coverity scan.

Coverity issue: 383665
Fixes: 817e3e55bb18 ("ml/cnxk: support simulator environment")

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
---
 drivers/ml/cnxk/cn10k_ml_dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/ml/cnxk/cn10k_ml_dev.c b/drivers/ml/cnxk/cn10k_ml_dev.c
index 6f9a1015a6..bba3c9022e 100644
--- a/drivers/ml/cnxk/cn10k_ml_dev.c
+++ b/drivers/ml/cnxk/cn10k_ml_dev.c
@@ -779,8 +779,8 @@  cn10k_ml_fw_load(struct cn10k_ml_dev *mldev)
 	if (roc_env_is_emulator() || roc_env_is_hw()) {
 		/* Read firmware image to a buffer */
 		ret = rte_firmware_read(fw->path, &fw_buffer, &fw_size);
-		if (ret < 0) {
-			plt_err("Can't read firmware data: %s\n", fw->path);
+		if ((ret < 0) || (fw_buffer == NULL)) {
+			plt_err("Unable to read firmware data: %s\n", fw->path);
 			return ret;
 		}