From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>,
Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>
Cc: linux-kernel@vger.kernel.org, Peng Fan <peng.fan@nxp.com>,
linux-raid@vger.kernel.org
Subject: [Patch V2] md/raid: use assign_bit() where applicable
Date: Mon, 21 Sep 2026 16:10:08 +0800 [thread overview]
Message-ID: <20260921081009.278532-2-peng.fan@oss.nxp.com> (raw)
In-Reply-To: <20260921081009.278532-1-peng.fan@oss.nxp.com>
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/md.c | 22 ++++++----------------
drivers/md/raid5-cache.c | 6 ++----
drivers/md/raid5.c | 6 ++----
3 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63cb3..6b2a397f8a9c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3586,10 +3586,7 @@ static ssize_t recovery_start_store(struct md_rdev *rdev, const char *buf, size_
return -EBUSY;
rdev->recovery_offset = recovery_start;
- if (recovery_start == MaxSector)
- set_bit(In_sync, &rdev->flags);
- else
- clear_bit(In_sync, &rdev->flags);
+ assign_bit(In_sync, &rdev->flags, recovery_start == MaxSector);
return len;
}
@@ -5915,10 +5912,7 @@ fail_last_dev_store(struct mddev *mddev, const char *buf, size_t len)
if (ret)
return ret;
- if (value)
- set_bit(MD_FAILLAST_DEV, &mddev->flags);
- else
- clear_bit(MD_FAILLAST_DEV, &mddev->flags);
+ assign_bit(MD_FAILLAST_DEV, &mddev->flags, value);
return len;
}
@@ -7574,14 +7568,10 @@ int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info)
}
clear_bit(In_sync, &rdev->flags); /* just to be sure */
- if (info->state & (1<<MD_DISK_WRITEMOSTLY))
- set_bit(WriteMostly, &rdev->flags);
- else
- clear_bit(WriteMostly, &rdev->flags);
- if (info->state & (1<<MD_DISK_FAILFAST))
- set_bit(FailFast, &rdev->flags);
- else
- clear_bit(FailFast, &rdev->flags);
+ assign_bit(WriteMostly, &rdev->flags,
+ info->state & (1 << MD_DISK_WRITEMOSTLY));
+ assign_bit(FailFast, &rdev->flags,
+ info->state & (1 << MD_DISK_FAILFAST));
if (info->state & (1<<MD_DISK_JOURNAL)) {
struct md_rdev *rdev2;
diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
index 7b7546bfa21f..b442a4de61fb 100644
--- a/drivers/md/raid5-cache.c
+++ b/drivers/md/raid5-cache.c
@@ -432,10 +432,8 @@ static inline void r5c_update_log_state(struct r5l_log *log)
wake_reclaim = true;
clear_bit(R5C_LOG_CRITICAL, &conf->cache_state);
}
- if (free_space < 3 * reclaim_space)
- set_bit(R5C_LOG_TIGHT, &conf->cache_state);
- else
- clear_bit(R5C_LOG_TIGHT, &conf->cache_state);
+ assign_bit(R5C_LOG_TIGHT, &conf->cache_state,
+ free_space < 3 * reclaim_space);
if (wake_reclaim)
r5l_wake_reclaim(log, 0);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b91545ce090d..713596ee933c 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -4748,10 +4748,8 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)
RAID5_STRIPE_SECTORS(conf)))
set_bit(R5_ReadRepl, &dev->flags);
else {
- if (rdev && !test_bit(Faulty, &rdev->flags))
- set_bit(R5_NeedReplace, &dev->flags);
- else
- clear_bit(R5_NeedReplace, &dev->flags);
+ assign_bit(R5_NeedReplace, &dev->flags,
+ rdev && !test_bit(Faulty, &rdev->flags));
rdev = conf->disks[i].rdev;
clear_bit(R5_ReadRepl, &dev->flags);
}
--
2.51.0
next prev parent reply other threads:[~2026-09-21 8:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 8:10 [Patch V2] dm: " Peng Fan (OSS)
2026-09-21 8:10 ` Peng Fan (OSS) [this message]
2026-09-23 11:15 ` [Patch V2] md/raid: " yu kuai
2026-09-21 14:16 ` [Patch V2] dm: " Mikulas Patocka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260921081009.278532-2-peng.fan@oss.nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=peng.fan@nxp.com \
--cc=song@kernel.org \
--cc=xiao@kernel.org \
--cc=yukuai@fygo.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®