Skip to contentSkip to conversation

drm/amd/display: Fixed the unused-but-set-variable warning

PATCH Superseded Aashish Sharma 3 participants 4 messages Mar 17, 2022 – Mar 18, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: Fixed the unused-but-set-variable warning

Fixed this kernel test robot warning:

drivers/gpu/drm/amd/amdgpu/../display/dmub/inc/dmub_cmd.h:2893:12:
warning: variable 'temp' set but not used [-Wunused-but-set-variable]

Replaced the assignment to the unused temp variable with READ_ONCE() macro to flush the writes.

---
 drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +2 -3
index 873ecd04e01d..b7981a781701 100644
@@ -2913,13 +2913,12 @@ static inline void dmub_rb_flush_pending(const struct dmub_rb *rb)
 	uint32_t wptr = rb->wrpt;
 
 	while (rptr != wptr) {
-		uint64_t volatile *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
+		uint64_t *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
 		//uint64_t volatile *p = (uint64_t volatile *)data;
-		uint64_t temp;
 		uint8_t i;
 
 		for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
-			temp = *data++;
+			(void)READ_ONCE(*data++);
 
 		rptr += DMUB_RB_CMD_SIZE;
 		if (rptr >= rb->capacity)
Signature · 1 line
2.35.1.723.g4982287a31-goog
#1 lore raw
Quoted 19 lines · Aashish Sharma

Fixed this kernel test robot warning:

drivers/gpu/drm/amd/amdgpu/../display/dmub/inc/dmub_cmd.h:2893:12:
warning: variable 'temp' set but not used [-Wunused-but-set-variable]

Replaced the assignment to the unused temp variable with READ_ONCE() macro to flush the writes.

---
 drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +0 -0
index 873ecd04e01d..b7981a781701 100644

drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h static inline void dmub_rb_flush_pending(const struct dmub_rb *rb) · line 2916

Quoted 5 lines
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +1 -1
@@ -2913,13 +2913,12 @@ static inline void dmub_rb_flush_pending(const struct dmub_rb *rb)
        uint32_t wptr = rb->wrpt;
 
        while (rptr != wptr) {
-               uint64_t volatile *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
+               uint64_t *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);

also drop the volatile in the typecast

drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h static inline void dmub_rb_flush_pending(const struct dmub_rb *rb) · line 2917

Quoted 1 line
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +0 -0
                //uint64_t volatile *p = (uint64_t volatile *)data;

The above commented out code serves no purpose and should be removed as well.

Thanks,
Guenter

Quoted 12 lines
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +1 -3
-               uint64_t temp;
                uint8_t i;
 
                for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
-                       temp = *data++;
+                       (void)READ_ONCE(*data++);
 
                rptr += DMUB_RB_CMD_SIZE;
                if (rptr >= rb->capacity)
--

2.35.1.723.g4982287a31-goog

#2 lore raw
In reply to Aashish Sharma

Dear Aashish,

Am 17.03.22 um 15:01 schrieb Aashish Sharma:

Thank you for your patch. If you are going to send a v2, please use imperative mood. Maybe:

drm/amd/display: Fix unused-but-set-variable warning

Quoted 1 line

Fixed this kernel test robot warning:

Maybe:

Fix the kernel test robot warning below:

Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/../display/dmub/inc/dmub_cmd.h:2893:12:
warning: variable 'temp' set but not used [-Wunused-but-set-variable]

Replaced the assignment to the unused temp variable with READ_ONCE() macro to flush the writes.

Replace …

Excuse my ignorance regarding READ_ONCE(), but is that the reason you remove the volatile qualifier?

Some robots ask in their report to add a Found-by tag. If so, please add one.

Quoted 12 lines
---
  drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +0 -0
index 873ecd04e01d..b7981a781701 100644
@@ -2913,13 +2913,12 @@ static inline void dmub_rb_flush_pending(const struct dmub_rb *rb)
  	uint32_t wptr = rb->wrpt;
 

drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h static inline void dmub_rb_flush_pending(const struct dmub_rb *rb) · line 2921

Quoted 10 lines
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +2 -3
  	while (rptr != wptr) {
-		uint64_t volatile *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
+		uint64_t *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
  		//uint64_t volatile *p = (uint64_t volatile *)data;
-		uint64_t temp;
  		uint8_t i;
 
  		for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
-			temp = *data++;
+			(void)READ_ONCE(*data++);

Did you verify, that the generated code is the same now, or what the differences are. If it’s different from before, you should document in the commit message, that it’s wanted, as otherwise, it’s an invasive change just to fix a warning.

drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h static inline void dmub_rb_flush_pending(const struct dmub_rb *rb) · line 2924

Quoted 2 lines
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +0 -0
  		rptr += DMUB_RB_CMD_SIZE;
  		if (rptr >= rb->capacity)

Kind regards,

Paul

#3 lore raw

Hi Paul,

Quoted 9 lines · Paul Menzel

Dear Aashish,

Am 17.03.22 um 15:01 schrieb Aashish Sharma:

Thank you for your patch. If you are going to send a v2, please use imperative mood. Maybe:

Uuh, sorry, I have to take the blame for that. I am guiding Aashish through the process of submitting patches upstream, and I completely missed that.

Quoted 12 lines

drm/amd/display: Fix unused-but-set-variable warning

Quoted 1 line

Fixed this kernel test robot warning:

Maybe:

Fix the kernel test robot warning below:

Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/../display/dmub/inc/dmub_cmd.h:2893:12:
warning: variable 'temp' set but not used [-Wunused-but-set-variable]

Quoted 8 lines
Quoted 2 lines

Replaced the assignment to the unused temp variable with READ_ONCE() macro to flush the writes.

Replace …

Excuse my ignorance regarding READ_ONCE(), but is that the reason you remove the volatile qualifier?

It is not the reason to remove volatile, it is to enable removing it. I had suggested using it, following its description " ... Ensuring that the compiler does not fold, spindle, or otherwise * mutilate accesses ... ", to avoid the use of volatile, and to make it obvious from the code that the read is intentional. My apologies if that is the wrong approach. A simpler solution would be to just remove the temp variable if that is preferred.

Quoted 2 lines

Some robots ask in their report to add a Found-by tag. If so, please add one.

I think that should be "Reported-by", or more specifically

Quoted 20 lines
Quoted 20 lines
---
  drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +1 -2
index 873ecd04e01d..b7981a781701 100644
@@ -2913,13 +2913,12 @@ static inline void dmub_rb_flush_pending(const struct dmub_rb *rb)
      uint32_t wptr = rb->wrpt;
 
      while (rptr != wptr) {
-             uint64_t volatile *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
+             uint64_t *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
              //uint64_t volatile *p = (uint64_t volatile *)data;
-             uint64_t temp;
              uint8_t i;
 
Quoted 9 lines

drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h static inline void dmub_rb_flush_pending(const struct dmub_rb *rb) · line 2921

Quoted 3 lines
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +1 -1
              for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
-                     temp = *data++;
+                     (void)READ_ONCE(*data++);

Did you verify, that the generated code is the same now, or what the differences are. If it’s different from before, you should document in the commit message, that it’s wanted, as otherwise, it’s an invasive change just to fix a warning.

The generated code is exactly the same on x86.

Thanks,
Guenter

Quoted 7 lines

drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h static inline void dmub_rb_flush_pending(const struct dmub_rb *rb) · line 2924

Quoted 2 lines
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h +0 -0
              rptr += DMUB_RB_CMD_SIZE;
              if (rptr >= rb->capacity)

Kind regards,

Paul