[PATCH 067/109] drm/amd/ras: fix silent error swallowing in get_record_count paths

Alex Deucher <[email protected]>
Newsgroups org.freedesktop.lists.amd-gfx
Message-ID <[email protected]>
From: YiPeng Chai <[email protected]>

Fix silent error swallowing in get_record_count paths.

Signed-off-by: YiPeng Chai <[email protected]>
Reviewed-by: Hawking Zhang <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/ras/core/core.c           |  4 ++--
 drivers/gpu/drm/amd/ras/core/eeprom.c         |  4 ++--
 drivers/gpu/drm/amd/ras/core/eeprom_fw.c      |  4 ++--
 drivers/gpu/drm/amd/ras/core/ras_eeprom_mgr.h |  2 +-
 drivers/gpu/drm/amd/ras/core/ras_umc.c        | 17 ++++++++++-------
 5 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/ras/core/core.c b/drivers/gpu/drm/amd/ras/core/core.c
index f093f29635888..00dc6084454cd 100644
--- a/drivers/gpu/drm/amd/ras/core/core.c
+++ b/drivers/gpu/drm/amd/ras/core/core.c
@@ -274,8 +274,8 @@ static int ras_core_eeprom_recovery(struct ras_core_context *ras_core)
 	int ret;
 
 	count = ras_eeprom_mgr_get_record_count(ras_core);
-	if (!count)
-		return 0;
+	if (count <= 0)
+		return count;
 
 	/* Avoid bad page to be loaded again after gpu reset */
 	if (ras_umc_get_saved_eeprom_count(ras_core) >= count)
diff --git a/drivers/gpu/drm/amd/ras/core/eeprom.c b/drivers/gpu/drm/amd/ras/core/eeprom.c
index 3c16446ddfc47..61cc0538f4622 100644
--- a/drivers/gpu/drm/amd/ras/core/eeprom.c
+++ b/drivers/gpu/drm/amd/ras/core/eeprom.c
@@ -1141,12 +1141,12 @@ static int ras_eeprom_hw_fini(struct ras_core_context *ras_core)
 	return 0;
 }
 
-static uint32_t ras_eeprom_get_record_count(struct ras_core_context *ras_core)
+static int ras_eeprom_get_record_count(struct ras_core_context *ras_core)
 {
 	struct ras_eeprom_control *control = ras_core->eeprom_mgr.ras_eeprom;
 
 	if (!control)
-		return 0;
+		return -EINVAL;
 
 	return control->ras_num_recs;
 }
diff --git a/drivers/gpu/drm/amd/ras/core/eeprom_fw.c b/drivers/gpu/drm/amd/ras/core/eeprom_fw.c
index 5f86ff54d9ed7..02369d54bdffd 100644
--- a/drivers/gpu/drm/amd/ras/core/eeprom_fw.c
+++ b/drivers/gpu/drm/amd/ras/core/eeprom_fw.c
@@ -97,12 +97,12 @@ static int fw_eeprom_sync_data(struct ras_core_context *ras_core,
 	return ret;
 }
 
-static u32 fw_eeprom_get_record_count(struct ras_core_context *ras_core)
+static int fw_eeprom_get_record_count(struct ras_core_context *ras_core)
 {
 	struct fw_eeprom_control *ctl;
 
 	if (!ras_core->eeprom_mgr.ras_eeprom)
-		return 0;
+		return -EINVAL;
 
 	ctl = ras_core->eeprom_mgr.ras_eeprom;
 
diff --git a/drivers/gpu/drm/amd/ras/core/ras_eeprom_mgr.h b/drivers/gpu/drm/amd/ras/core/ras_eeprom_mgr.h
index 873c96b287845..b15682b44a6ef 100644
--- a/drivers/gpu/drm/amd/ras/core/ras_eeprom_mgr.h
+++ b/drivers/gpu/drm/amd/ras/core/ras_eeprom_mgr.h
@@ -80,7 +80,7 @@ struct ras_eeprom_ops {
 		struct eeprom_umc_record *records, u32 num);
 	int (*append_records)(struct ras_core_context *ras_core,
 		struct eeprom_umc_record *records, u32 num);
-	u32 (*get_record_count)(struct ras_core_context *ras_core);
+	int (*get_record_count)(struct ras_core_context *ras_core);
 	int (*get_eeprom_info)(struct ras_core_context *ras_core,
 		struct ras_eeprom_info *eeprom_info, bool fast_mode);
 	int (*unlock_eeprom)(struct ras_core_context *ras_core);
diff --git a/drivers/gpu/drm/amd/ras/core/ras_umc.c b/drivers/gpu/drm/amd/ras/core/ras_umc.c
index 3558d4633a4e7..32203e85ef14b 100644
--- a/drivers/gpu/drm/amd/ras/core/ras_umc.c
+++ b/drivers/gpu/drm/amd/ras/core/ras_umc.c
@@ -676,12 +676,12 @@ int ras_umc_add_bad_pages(struct ras_core_context *ras_core,
 int ras_umc_load_bad_pages(struct ras_core_context *ras_core)
 {
 	struct eeprom_umc_record *bps;
-	uint32_t ras_num_recs, c = 0;
-	int ret;
+	uint32_t c = 0;
+	int ras_num_recs, ret;
 
 	ras_num_recs = ras_eeprom_mgr_get_record_count(ras_core);
-	if (!ras_num_recs)
-		return 0;
+	if (ras_num_recs <= 0)
+		return ras_num_recs;
 
 	bps = kzalloc_objs(*bps, ras_num_recs);
 	if (!bps)
@@ -710,7 +710,7 @@ static int ras_umc_save_bad_pages(struct ras_core_context *ras_core)
 	struct ras_umc *ras_umc = &ras_core->ras_umc;
 	struct eeprom_store_record *data = &ras_umc->umc_err_data.rom_data;
 	struct eeprom_store_record *ram_data = &ras_umc->umc_err_data.ram_data;
-	uint32_t eeprom_record_num, logical_count = 0;
+	int eeprom_record_num, logical_count = 0;
 	int save_count;
 	int ret = -ENODATA;
 
@@ -722,6 +722,9 @@ static int ras_umc_save_bad_pages(struct ras_core_context *ras_core)
 		return -EINVAL;
 
 	eeprom_record_num = ras_eeprom_mgr_get_record_count(ras_core);
+	if (eeprom_record_num < 0)
+		return eeprom_record_num;
+
 	mutex_lock(&ras_umc->umc_lock);
 	save_count = data->count - eeprom_record_num;
 	logical_count = ram_data->bad_page_num - ram_data->bad_page_num_old;
@@ -981,8 +984,8 @@ int ras_umc_dump_fw_records(struct ras_core_context *ras_core)
 
 	eeprom_count = ras_eeprom_mgr_get_record_count(ras_core);
 	/* no bad page record, skip eeprom access */
-	if (!eeprom_count)
-		return 0;
+	if (eeprom_count <= 0)
+		return eeprom_count;
 
 	umc_count = ras_umc_get_saved_eeprom_count(ras_core);
 	if (umc_count == eeprom_count) {
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.