Skip to contentSkip to conversation

s390/time: use assign_bit() where applicable

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/time: 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/kernel/time.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
arch/s390/kernel/time.c +2 -8
index 2b989bebd220..3225a66abfce 100644
@@ -501,10 +501,7 @@ static int __store_stpinfo(void)
 {
 	int rc = chsc_sstpi(stp_page, &stp_info, sizeof(struct stp_sstpi));
 
-	if (rc)
-		clear_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags);
-	else
-		set_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags);
+	assign_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags, !rc);
 	return rc;
 }
 
@@ -795,10 +792,7 @@ static ssize_t online_store(struct device *dev,
 		return -EOPNOTSUPP;
 	mutex_lock(&stp_mutex);
 	stp_online = value;
-	if (stp_online)
-		set_bit(CLOCK_SYNC_STP, &clock_sync_flags);
-	else
-		clear_bit(CLOCK_SYNC_STP, &clock_sync_flags);
+	assign_bit(CLOCK_SYNC_STP, &clock_sync_flags, stp_online);
 	queue_work(time_sync_wq, &stp_work);
 	mutex_unlock(&stp_mutex);
 	return count;
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/kernel/time.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

...

Quoted 6 lines
arch/s390/kernel/time.c +1 -4
-	if (rc)
-		clear_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags);
-	else
-		set_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags);
+	assign_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags, !rc);
 	return rc;

...

arch/s390/kernel/time.c static ssize_t online_store(struct device *dev, · line 795

Quoted 7 lines
arch/s390/kernel/time.c +1 -4
 	mutex_lock(&stp_mutex);
 	stp_online = value;
-	if (stp_online)
-		set_bit(CLOCK_SYNC_STP, &clock_sync_flags);
-	else
-		clear_bit(CLOCK_SYNC_STP, &clock_sync_flags);
+	assign_bit(CLOCK_SYNC_STP, &clock_sync_flags, stp_online);

I don't know why all those trivial helper functions which obfuscate the code are introduced. Before it was very obvious what the code did, now I have to look up assign_bit() just to figure out that it is a completely trivial helper function, with close to zero benefit.

author
#3 lore raw
Quoted 17 lines · Heiko Carstens
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/kernel/time.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

...

Quoted 6 lines
arch/s390/kernel/time.c +1 -4
-	if (rc)
-		clear_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags);
-	else
-		set_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags);
+	assign_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags, !rc);
 	return rc;

...

Quoted 12 lines

arch/s390/kernel/time.c static ssize_t online_store(struct device *dev, · line 795

Quoted 7 lines
arch/s390/kernel/time.c +1 -4
 	mutex_lock(&stp_mutex);
 	stp_online = value;
-	if (stp_online)
-		set_bit(CLOCK_SYNC_STP, &clock_sync_flags);
-	else
-		clear_bit(CLOCK_SYNC_STP, &clock_sync_flags);
+	assign_bit(CLOCK_SYNC_STP, &clock_sync_flags, stp_online);

I don't know why all those trivial helper functions which obfuscate the code are introduced. Before it was very obvious what the code did, now I have to look up assign_bit() just to figure out that it is a completely trivial helper function, with close to zero benefit.

This API was introduced by
9a8ac3ae682e ("dm mpath: cleanup QUEUE_IF_NO_PATH bit manipulation by introducing assign_bit()")

And moved to include/linux/bitops.h for broader usage.

I think it would be good for us to save lines.

Drop this patch since you disable it.

Thanks,
Peng

Quoted 2 lines