Skip to contentSkip to conversation

KVM: s390: gmap: use assign_bit() where applicable

PATCH In review Peng Fan (OSS) 4 participants 5 messages Sep 20 – Sep 21

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

PATCH 1/1 KVM: s390: gmap: use assign_bit() where applicable

From: Peng Fan <[email protected]>

Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.

---
 arch/s390/kvm/gmap/gmap.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
arch/s390/kvm/gmap/gmap.c +5 -12
index 3f3fa864cc36..89a5ed4ac440 100644
@@ -90,20 +90,13 @@ static void gmap_add_child(struct gmap *parent, struct gmap *child)
 
 	child->parent = parent;
 
-	if (is_ucontrol(parent))
-		set_bit(GMAP_FLAG_IS_UCONTROL, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_IS_UCONTROL, &child->flags);
+	assign_bit(GMAP_FLAG_IS_UCONTROL, &child->flags, is_ucontrol(parent));
 
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags));
 
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags));
 
 	if (kvm_is_ucontrol(parent->kvm))
 		clear_bit(GMAP_FLAG_OWNS_PAGETABLES, &child->flags);
Signature · 1 line
2.51.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

From: Peng Fan <[email protected]>

Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Peng Fan (OSS)
Quoted 8 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.

---
 arch/s390/kvm/gmap/gmap.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

...

arch/s390/kvm/gmap/gmap.c static void gmap_add_child(struct gmap *parent, struct gmap *child) · line 99

Quoted 13 lines
arch/s390/kvm/gmap/gmap.c +4 -8
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags));
 
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags));

This turns something which was easily readable into an unreadable mess.

#3 lore raw

Am 20.09.26 um 18:18 schrieb Heiko Carstens:

Quoted 17 lines · Peng Fan (OSS)
Quoted 8 lines

From: Peng Fan <[email protected]>

Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.

---
  arch/s390/kvm/gmap/gmap.c | 17 +++++------------
  1 file changed, 5 insertions(+), 12 deletions(-)

...

Quoted 7 lines
arch/s390/kvm/gmap/gmap.c +2 -4
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags));
Quoted 8 lines

arch/s390/kvm/gmap/gmap.c static void gmap_add_child(struct gmap *parent, struct gmap *child) · line 99

Quoted 6 lines
arch/s390/kvm/gmap/gmap.c +2 -4
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags));

This turns something which was easily readable into an unreadable mess.

I agree, this is not a good use for the assign_bit helper.

author
#4 lore raw
Quoted 28 lines · Christian Borntraeger

Am 20.09.26 um 18:18 schrieb Heiko Carstens:

Quoted 10 lines · Peng Fan (OSS)
Quoted 8 lines

From: Peng Fan <[email protected]>

Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.

---
  arch/s390/kvm/gmap/gmap.c | 17 +++++------------
  1 file changed, 5 insertions(+), 12 deletions(-)

...

Quoted 14 lines

arch/s390/kvm/gmap/gmap.c static void gmap_add_child(struct gmap *parent, struct gmap *child) · line 99

Quoted 12 lines
arch/s390/kvm/gmap/gmap.c +4 -8
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &parent->flags));
-	if (test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags))
-		set_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
-	else
-		clear_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
+	assign_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags,
+		   test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags));

This turns something which was easily readable into an unreadable mess.

Quoted 1 line

I agree, this is not a good use for the assign_bit helper.

No problem. Let's drop the patch.

Thanks,
Peng

Quoted 2 lines