[PATCH v2] arm64: Refactor conditional logic
Hardevsinh Palaniya
hardevsinh.palaniya at siliconsignals.io
Thu Nov 14 06:37:13 PST 2024
Hi all,
> Unnecessarily checks ftr_ovr == tmp in an extra else if, which is not
> needed because that condition would already be true by default if the
> previous conditions are not satisfied.
>
> if (ftr_ovr != tmp) {
> } else if (ftr_new != tmp) {
> } else if (ftr_ovr == tmp) {
>
> Logic: The first and last conditions are inverses of each other, so
> the last condition must be true if the first two conditions are false.
>
> Additionally, all branches set the variable str, making the subsequent
> "if (str)" check redundant
>
> Reviewed-by: Mark Brown <broonie at kernel.org>
> Signed-off-by: Hardevsinh Palaniya <hardevsinh.palaniya at siliconsignals.io>
Please consider this patch as v3. Apologies for the inconvenience.
Best regards,
Hardev
________________________________________
From: Hardevsinh Palaniya <hardevsinh.palaniya at siliconsignals.io>
Sent: Thursday, November 14, 2024 7:52 PM
To: will at kernel.org <will at kernel.org>; broonie at kernel.org <broonie at kernel.org>
Cc: Hardevsinh Palaniya <hardevsinh.palaniya at siliconsignals.io>; Catalin Marinas <catalin.marinas at arm.com>; Oliver Upton <oliver.upton at linux.dev>; Marc Zyngier <maz at kernel.org>; Ard Biesheuvel <ardb at kernel.org>; Mark Rutland <mark.rutland at arm.com>; Joey Gouly <joey.gouly at arm.com>; Ryan Roberts <ryan.roberts at arm.com>; linux-arm-kernel at lists.infradead.org <linux-arm-kernel at lists.infradead.org>; linux-kernel at vger.kernel.org <linux-kernel at vger.kernel.org>
Subject: [PATCH v2] arm64: Refactor conditional logic
Unnecessarily checks ftr_ovr == tmp in an extra else if, which is not
needed because that condition would already be true by default if the
previous conditions are not satisfied.
if (ftr_ovr != tmp) {
} else if (ftr_new != tmp) {
} else if (ftr_ovr == tmp) {
Logic: The first and last conditions are inverses of each other, so
the last condition must be true if the first two conditions are false.
Additionally, all branches set the variable str, making the subsequent
"if (str)" check redundant
Reviewed-by: Mark Brown <broonie at kernel.org>
Signed-off-by: Hardevsinh Palaniya <hardevsinh.palaniya at siliconsignals.io>
---
Changelog in V2:
- remove str check
Change in V3:
- Add logic in commit msg
- Add review tag
---
arch/arm64/kernel/cpufeature.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 718728a85430..728709483fb7 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -989,17 +989,16 @@ static void init_cpu_ftr_reg(u32 sys_reg, u64 new)
/* Override was valid */
ftr_new = tmp;
str = "forced";
- } else if (ftr_ovr == tmp) {
+ } else {
/* Override was the safe value */
str = "already set";
}
- if (str)
- pr_warn("%s[%d:%d]: %s to %llx\n",
- reg->name,
- ftrp->shift + ftrp->width - 1,
- ftrp->shift, str,
- tmp & (BIT(ftrp->width) - 1));
+ pr_warn("%s[%d:%d]: %s to %llx\n",
+ reg->name,
+ ftrp->shift + ftrp->width - 1,
+ ftrp->shift, str,
+ tmp & (BIT(ftrp->width) - 1));
} else if ((ftr_mask & reg->override->val) == ftr_mask) {
reg->override->val &= ~ftr_mask;
pr_warn("%s[%d:%d]: impossible override, ignored\n",
--
2.43.0
More information about the linux-arm-kernel
mailing list