riscv: Simplify base extension checks and direct boolean return
PATCH 1/1 riscv: Simplify base extension checks and direct boolean return
Reduce three lines checking to single line using a ternary conditional expression for getting the base extension word. In addition, the test_bit macro function already return a boolean which matches the return type of the caller, so directly return the result of the test_bit macro function.
--- arch/riscv/kernel/cpufeature.c | 6 ++---- arch/riscv/kernel/vendor_extensions.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -4
@@ -49,9 +49,7 @@ struct riscv_isainfo hart_isa[NR_CPUS];*/ unsigned long riscv_isa_extension_base (const unsigned long *isa_bitmap) { -if (!isa_bitmap) -return riscv_isa[0 ]; -return isa_bitmap[0 ]; +return !isa_bitmap ? riscv_isa[0 ] : isa_bitmap[0 ]; }EXPORT_SYMBOL_GPL (riscv_isa_extension_base);
@@ -72,7 +70,7 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned iif (bit >=RISCV_ISA_EXT_MAX )return false; -return test_bit (bit, bmap) ? true : false; +return test_bit (bit, bmap); }EXPORT_SYMBOL_GPL (__riscv_isa_extension_available);
arch/riscv/kernel/vendor_extensions.c +1 -1
@@ -51,6 +51,6 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsigif (bit >=RISCV_ISA_VENDOR_EXT_MAX )return false; -return test_bit (bit, bmap->isa) ? true : false; +return test_bit (bit, bmap->isa); }EXPORT_SYMBOL_GPL (__riscv_isa_vendor_extension_available);
Signature · 1 line
2.34.1
Quoted 51 lines · Chin Yik Ming
Reduce three lines checking to single line using a ternary conditional expression for getting the base extension word. In addition, the
test_bitmacro function already return a boolean which matches the return type of the caller, so directly return the result of thetest_bitmacro function.Signed-off-by Chin Yik Ming <[email protected]>--- arch/riscv/kernel/cpufeature.c | 6 ++---- arch/riscv/kernel/vendor_extensions.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)arch/riscv/kernel/cpufeature.c +2
-4@@ -49,9 +49,7 @@ struct riscv_isainfo hart_isa[NR_CPUS];*/ unsigned long riscv_isa_extension_base (const unsigned long *isa_bitmap) { -if (!isa_bitmap) -return riscv_isa[0 ]; -return isa_bitmap[0 ]; +return !isa_bitmap ? riscv_isa[0 ] : isa_bitmap[0 ]; }EXPORT_SYMBOL_GPL (riscv_isa_extension_base);@@ -72,7 +70,7 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned iif (bit >=RISCV_ISA_EXT_MAX )return false; -return test_bit (bit, bmap) ? true : false; +return test_bit (bit, bmap); }EXPORT_SYMBOL_GPL (__riscv_isa_extension_available);arch/riscv/kernel/vendor_extensions.c +1
-1@@ -51,6 +51,6 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsigif (bit >=RISCV_ISA_VENDOR_EXT_MAX )return false; -return test_bit (bit, bmap->isa) ? true : false; +return test_bit (bit, bmap->isa); }EXPORT_SYMBOL_GPL (__riscv_isa_vendor_extension_available);Signature · 1 line
2.34.1
Since the changes are harmless and I do prefer the way the code looks with them,
but these types of changes are pretty much just pointless churn...
Thanks,
drew
This patch was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:
Quoted 9 lines · On Thu, 30 Jan 2025 04:38:43 +0800 you wrote:
Reduce three lines checking to single line using a ternary conditional expression for getting the base extension word. In addition, the
test_bitmacro function already return a boolean which matches the return type of the caller, so directly return the result of thetest_bitmacro function.Signed-off-by Chin Yik Ming <[email protected]>[...]
Here is the summary with links:
- riscv: Simplify base extension checks and direct boolean return
https://git.kernel.org/riscv/c/7f238b12660e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html