Skip to contentSkip to conversation

drm/amdgpu: Modify for_each_inst macro

PATCH In review Lijo Lazar 2 participants 2 messages Jun 19, 2023 – Jun 20, 2023

Subsystems (2)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: Modify for_each_inst macro

Modify it such that it doesn't change the instance mask parameter.

---
v2:
Take care of bit-shift beyond width (Victor)

 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -3
index f4029c13a9be..aa42347bd67d 100644
@@ -1295,9 +1295,10 @@ int emu_soc_asic_init(struct amdgpu_device *adev);
 
 #define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter));
 
-#define for_each_inst(i, inst_mask)                                            \
-	for (i = ffs(inst_mask) - 1; inst_mask;                                \
-	     inst_mask &= ~(1U << i), i = ffs(inst_mask) - 1)
+#define BIT_MASK_UPPER(i) ((i) >= BITS_PER_LONG ? 0 : ~0UL << (i))
+#define for_each_inst(i, inst_mask)        \
+	for (i = ffs(inst_mask); i-- != 0; \
+	     i = ffs(inst_mask & BIT_MASK_UPPER(i + 1)))
 
 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
 
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#1 lore raw

[AMD Official Use Only - General]

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, June 19, 2023 3:30 AM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Skvortsov, Victor <[email protected]>
Subject: [PATCH v2] drm/amdgpu: Modify for_each_inst macro

Modify it such that it doesn't change the instance mask parameter.

---
v2:
Take care of bit-shift beyond width (Victor)

 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -3
index f4029c13a9be..aa42347bd67d 100644
@@ -1295,9 +1295,10 @@ int emu_soc_asic_init(struct amdgpu_device *adev);
 
 #define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter));
 
-#define for_each_inst(i, inst_mask)                                            \
-       for (i = ffs(inst_mask) - 1; inst_mask;                                \
-            inst_mask &= ~(1U << i), i = ffs(inst_mask) - 1)
+#define BIT_MASK_UPPER(i) ((i) >= BITS_PER_LONG ? 0 : ~0UL << (i))
+#define for_each_inst(i, inst_mask)        \
+       for (i = ffs(inst_mask); i-- != 0; \
+            i = ffs(inst_mask & BIT_MASK_UPPER(i + 1)))
 
 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
 

--
2.25.1