mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [Patch V2] dm: use assign_bit() where applicable
@ 2026-09-21  8:10 Peng Fan (OSS)
  2026-09-21  8:10 ` [Patch V2] md/raid: " Peng Fan (OSS)
  2026-09-21 14:16 ` [Patch V2] dm: " Mikulas Patocka
  0 siblings, 2 replies; 3+ messages in thread
From: Peng Fan (OSS) @ 2026-09-21  8:10 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski
  Cc: linux-kernel, Peng Fan, dm-devel

From: Peng Fan <peng.fan@nxp.com>

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

Done with Coccinelle semantic patch:
    // set_bit -> clear_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        set_bit(bit, addr);
    -else
    -        clear_bit(bit, addr);
    +assign_bit(bit, addr, cond);

    // clear_bit -> set_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        clear_bit(bit, addr);
    -else
    -        set_bit(bit, addr);
    +assign_bit(bit, addr, !cond);

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---

V2:
 Separate device-mapper and mraid
 https://lore.kernel.org/all/20260918141737.3023011-1-peng.fan@oss.nxp.com/

 drivers/md/dm-mpath.c                  | 5 +----
 drivers/md/dm-zone.c                   | 6 ++----
 drivers/md/persistent-data/dm-bitset.c | 5 +----
 3 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 7cb7bb6233b6..ae9318f5f21b 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1604,10 +1604,7 @@ static void pg_init_done(void *data, int errors)
 		goto out;
 
 	if (test_bit(MPATHF_PG_INIT_REQUIRED, &m->flags)) {
-		if (delay_retry)
-			set_bit(MPATHF_PG_INIT_DELAY_RETRY, &m->flags);
-		else
-			clear_bit(MPATHF_PG_INIT_DELAY_RETRY, &m->flags);
+		assign_bit(MPATHF_PG_INIT_DELAY_RETRY, &m->flags, delay_retry);
 
 		if (__pg_init_all_paths(m))
 			goto out;
diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c
index f29acf64429a..35916c6e490e 100644
--- a/drivers/md/dm-zone.c
+++ b/drivers/md/dm-zone.c
@@ -447,10 +447,8 @@ void dm_finalize_zone_settings(struct dm_table *t, struct queue_limits *lim)
 	struct mapped_device *md = t->md;
 
 	if (lim->features & BLK_FEAT_ZONED) {
-		if (dm_table_supports_zone_append(t))
-			clear_bit(DMF_EMULATE_ZONE_APPEND, &md->flags);
-		else
-			set_bit(DMF_EMULATE_ZONE_APPEND, &md->flags);
+		assign_bit(DMF_EMULATE_ZONE_APPEND, &md->flags,
+			   !dm_table_supports_zone_append(t));
 	} else {
 		clear_bit(DMF_EMULATE_ZONE_APPEND, &md->flags);
 		md->disk->nr_zones = 0;
diff --git a/drivers/md/persistent-data/dm-bitset.c b/drivers/md/persistent-data/dm-bitset.c
index 00c0a3f186b7..6680f05c25ec 100644
--- a/drivers/md/persistent-data/dm-bitset.c
+++ b/drivers/md/persistent-data/dm-bitset.c
@@ -59,10 +59,7 @@ static int pack_bits(uint32_t index, void *value, void *context)
 		if (r)
 			return r;
 
-		if (bv)
-			set_bit(bit, (unsigned long *) &word);
-		else
-			clear_bit(bit, (unsigned long *) &word);
+		assign_bit(bit, (unsigned long *)&word, bv);
 	}
 
 	*((__le64 *) value) = cpu_to_le64(word);
-- 
2.51.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-21 14:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-21  8:10 [Patch V2] dm: use assign_bit() where applicable Peng Fan (OSS)
2026-09-21  8:10 ` [Patch V2] md/raid: " Peng Fan (OSS)
2026-09-21 14:16 ` [Patch V2] dm: " Mikulas Patocka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®