Skip to contentSkip to conversation

drm/amdgpu: avoid null pointer dereference

PATCH In review Chen, Guchun 2 participants 3 messages Sep 18, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: avoid null pointer dereference

null ptr should be checked first to avoid null ptr access

Change-Id I85c0a096eef77cad3a34265c995b1845451e04d0
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -2
index 090daf595469..c3090f0eb604 100644
@@ -1334,13 +1334,13 @@ static int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 	struct ras_err_handler_data *data;
-	struct amdgpu_ras_eeprom_control *control =
-					&adev->psp.ras.ras->eeprom_control;
+	struct amdgpu_ras_eeprom_control *control;
 	int save_count;
 
 	if (!con || !con->eh_data)
 		return 0;
 
+	control = &adev->psp.ras.ras->eeprom_control;
 	data = con->eh_data;
 	save_count = data->count - control->num_recs;
 	/* only new entries are saved */
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 2/2 drm/amdgpu: remove redundant variable definition

No need to define the same variables in each loop of the function.

Change-Id Id8bbcc5a2ac87e9d31a72244345fde2d6bb99d42
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +8 -7
index d0e020ef73e3..20af0a17d00b 100644
@@ -359,8 +359,9 @@ int amdgpu_ras_eeprom_process_recods(struct amdgpu_ras_eeprom_control *control,
 					    int num)
 {
 	int i, ret = 0;
-	struct i2c_msg *msgs;
-	unsigned char *buffs;
+	struct i2c_msg *msgs, *msg;
+	unsigned char *buffs, *buff;
+	struct eeprom_table_record *record;
 	struct amdgpu_device *adev = to_amdgpu_device(control);
 
 	if (adev->asic_type != CHIP_VEGA20)
@@ -390,9 +391,9 @@ int amdgpu_ras_eeprom_process_recods(struct amdgpu_ras_eeprom_control *control,
 	 * 256b
 	 */
 	for (i = 0; i < num; i++) {
-		unsigned char *buff = &buffs[i * (EEPROM_ADDRESS_SIZE + EEPROM_TABLE_RECORD_SIZE)];
-		struct eeprom_table_record *record = &records[i];
-		struct i2c_msg *msg = &msgs[i];
+		buff = &buffs[i * (EEPROM_ADDRESS_SIZE + EEPROM_TABLE_RECORD_SIZE)];
+		record = &records[i];
+		msg = &msgs[i];
 
 		control->next_addr = __correct_eeprom_dest_address(control->next_addr);
 
@@ -432,8 +433,8 @@ int amdgpu_ras_eeprom_process_recods(struct amdgpu_ras_eeprom_control *control,
 
 	if (!write) {
 		for (i = 0; i < num; i++) {
-			unsigned char *buff = &buffs[i*(EEPROM_ADDRESS_SIZE + EEPROM_TABLE_RECORD_SIZE)];
-			struct eeprom_table_record *record = &records[i];
+			buff = &buffs[i*(EEPROM_ADDRESS_SIZE + EEPROM_TABLE_RECORD_SIZE)];
+			record = &records[i];
 
 			__decode_table_record_from_buff(control, record, buff + EEPROM_ADDRESS_SIZE);
 		}
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by Tao Zhou
#3 lore raw
In reply to a message not in the archive

"control = &con->eeprom_control" is suggested, apart from this, the series is:

Quoted 39 lines

-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: 2019年9月18日 11:38
To: [email protected]; Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Grodzovsky, Andrey <[email protected]>
Cc: Chen, Guchun <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: avoid null pointer dereference

null ptr should be checked first to avoid null ptr access

Change-Id I85c0a096eef77cad3a34265c995b1845451e04d0
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -3
index 090daf595469..c3090f0eb604 100644
@@ -1334,13 +1334,13 @@ static int amdgpu_ras_save_bad_pages(struct
 amdgpu_device *adev)  {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 	struct ras_err_handler_data *data;
-	struct amdgpu_ras_eeprom_control *control =
-					&adev->psp.ras.ras->eeprom_control;
+	struct amdgpu_ras_eeprom_control *control;
 	int save_count;
 
 	if (!con || !con->eh_data)
 		return 0;
 
+	control = &adev->psp.ras.ras->eeprom_control;
 	data = con->eh_data;
 	save_count = data->count - control->num_recs;
 	/* only new entries are saved */
--
Quoted 1 line

2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx