Skip to contentSkip to conversation

drm/amd/powerplay: implement smu7 hwmgr to manager asics with smu ip version 7.

DISCUSSION Dan Carpenter 3 participants 3 messages Oct 11, 2016

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

Hello Rex Zhu,

This is a semi-automatic email about new static checker warnings.

The patch 599a7e9fe1b6: "drm/amd/powerplay: implement smu7 hwmgr to manager asics with smu ip version 7." from Sep 9, 2016, leads to the following Smatch complaint:

drivers/gpu/drm/amd/amdgpu/../powerplay/hwmgr/smu7_hwmgr.c:3809 smu7_check_states_equal()
warn: variable dereferenced before check 'pstate1' (see line 3805)

drivers/gpu/drm/amd/amdgpu/../powerplay/hwmgr/smu7_hwmgr.c
3804 {

  3805		const struct smu7_power_state *psa = cast_const_phw_smu7_power_state(pstate1);
                                                                                     ^^^^^^^
  3806		const struct smu7_power_state *psb = cast_const_phw_smu7_power_state(pstate2);
                                                                                     ^^^^^^^

New dereferences.

3807 int i;
3808
3809 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)

                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Checked too late.

Just as an aside. People really don't review code in initializers. I've commented on this before, and other people have noted it as well but other people are like "In that case, those people shouldn't be kernel devs!" which is so ignorant. Everyone consistently makes the same mistakes. I've spent so many hours looking at basically this same bug over and over and everyone does it.

That's nothing to do with your code, in particular, I just wanted to update you on how my morning has been going. (Pretty well, thanks, although I'm due for a second cup of coffee).

3810 return -EINVAL;
3811

regards,
dan carpenter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

Thanks.
Please review the attached patches.

Best Regards
Rex

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, October 11, 2016 3:11 PM
To: Zhu, Rex
Cc: [email protected]
Subject: re: drm/amd/powerplay: implement smu7 hwmgr to manager asics with smu ip version 7.

Hello Rex Zhu,

This is a semi-automatic email about new static checker warnings.

The patch 599a7e9fe1b6: "drm/amd/powerplay: implement smu7 hwmgr to manager asics with smu ip version 7." from Sep 9, 2016, leads to the following Smatch complaint:

drivers/gpu/drm/amd/amdgpu/../powerplay/hwmgr/smu7_hwmgr.c:3809 smu7_check_states_equal()
warn: variable dereferenced before check 'pstate1' (see line 3805)

drivers/gpu/drm/amd/amdgpu/../powerplay/hwmgr/smu7_hwmgr.c
3804 {

  3805		const struct smu7_power_state *psa = cast_const_phw_smu7_power_state(pstate1);
                                                                                     ^^^^^^^
  3806		const struct smu7_power_state *psb = cast_const_phw_smu7_power_state(pstate2);
                                                                                     ^^^^^^^ New dereferences.

3807 int i;
3808
3809 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)

                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Checked too late.

Just as an aside. People really don't review code in initializers.
I've commented on this before, and other people have noted it as well but other people are like "In that case, those people shouldn't be kernel devs!" which is so ignorant. Everyone consistently makes the same mistakes. I've spent so many hours looking at basically this same bug over and over and everyone does it.

That's nothing to do with your code, in particular, I just wanted to update you on how my morning has been going. (Pretty well, thanks, although I'm due for a second cup of coffee).

3810 return -EINVAL;
3811

regards,
dan carpenter

From d8530e76a53f9a340305f7fb4bd59949d680e2ee Mon Sep 17 00:00:00 2001
From: Rex Zhu <[email protected]>
Date: Tue, 11 Oct 2016 18:44:46 +0800
Subject: [PATCH 1/2] drm/amd/powerplay: add array length check to avoid buffer
overflow.

Change-Id I14a4c7e365fddc14ddfbaec62b3e27e100f2b36f
---
 drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c +1 -1
index eda802b..8c889ca 100644
@@ -2458,7 +2458,7 @@ static int iceland_set_mc_special_registers(struct pp_hwmgr *hwmgr,
 			PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
 				"Invalid VramInfo table.", return -EINVAL);
 
-			if (!data->is_memory_gddr5) {
+			if (!data->is_memory_gddr5 && j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE) {
 				table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
 				table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
 				for (k = 0; k < table->num_entries; k++) {
Signature · 1 line
1.9.1

From bd50449ce9b19c574354be286f11e85d1e5ededc Mon Sep 17 00:00:00 2001
From: Rex Zhu <[email protected]>
Date: Tue, 11 Oct 2016 18:51:16 +0800
Subject: [PATCH 2/2] drm/amd/powerplay: fix bug variable dereferenced before
check it

Change-Id I23c6aded68ab9b20671ad99382b71a910465e5da
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c +4 -2
index f6afa6a..d6b3fd1 100644
@@ -3821,13 +3821,15 @@ static int smu7_check_states_equal(struct pp_hwmgr *hwmgr,
 		const struct pp_hw_power_state *pstate1,
 		const struct pp_hw_power_state *pstate2, bool *equal)
 {
-	const struct smu7_power_state *psa = cast_const_phw_smu7_power_state(pstate1);
-	const struct smu7_power_state *psb = cast_const_phw_smu7_power_state(pstate2);
+	const struct smu7_power_state *psa;
+	const struct smu7_power_state *psb;
 	int i;
 
 	if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
 		return -EINVAL;
 
+	psa = cast_const_phw_smu7_power_state(pstate1);
+	psb = cast_const_phw_smu7_power_state(pstate2);
 	/* If the two states don't even have the same number of performance levels they cannot be the same state. */
 	if (psa->performance_level_count != psb->performance_level_count) {
 		*equal = false;
Signature · 1 line
1.9.1

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

#2 lore raw

Some commit messages would be nice.

You could make the subject line shorter (something like "fix some warning in xyz.c") and actually use the current subject line as commit message.

With that fixed the patches are Reviewed-by: Christian König <[email protected]>.

Regards,
Christian.

Am 11.10.2016 um 13:17 schrieb Zhu, Rex:

Quoted 44 lines

Thanks.
Please review the attached patches.

Best Regards
Rex

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, October 11, 2016 3:11 PM
To: Zhu, Rex
Cc: [email protected]
Subject: re: drm/amd/powerplay: implement smu7 hwmgr to manager asics with smu ip version 7.

Hello Rex Zhu,

This is a semi-automatic email about new static checker warnings.

The patch 599a7e9fe1b6: "drm/amd/powerplay: implement smu7 hwmgr to manager asics with smu ip version 7." from Sep 9, 2016, leads to the following Smatch complaint:

drivers/gpu/drm/amd/amdgpu/../powerplay/hwmgr/smu7_hwmgr.c:3809 smu7_check_states_equal()
warn: variable dereferenced before check 'pstate1' (see line 3805)

drivers/gpu/drm/amd/amdgpu/../powerplay/hwmgr/smu7_hwmgr.c

   3804	{
   3805		const struct smu7_power_state *psa = cast_const_phw_smu7_power_state(pstate1);
                                                                                      ^^^^^^^
   3806		const struct smu7_power_state *psb = cast_const_phw_smu7_power_state(pstate2);
                                                                                      ^^^^^^^ New dereferences.

   3807		int i;
   3808	
   3809		if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Checked too late.

Just as an aside. People really don't review code in initializers.
I've commented on this before, and other people have noted it as well but other people are like "In that case, those people shouldn't be kernel devs!" which is so ignorant. Everyone consistently makes the same mistakes. I've spent so many hours looking at basically this same bug over and over and everyone does it.

That's nothing to do with your code, in particular, I just wanted to update you on how my morning has been going. (Pretty well, thanks, although I'm due for a second cup of coffee).

   3810			return -EINVAL;
   3811	
Quoted 8 lines

regards,
dan carpenter

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

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