[PATCH] KVM: PPC: use assign_bit() where applicable

Peng Fan (OSS) posted 1 patch 4 days, 18 hours ago
arch/powerpc/kvm/powerpc.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
[PATCH] KVM: PPC: use assign_bit() where applicable
Posted by Peng Fan (OSS) 4 days, 18 hours ago
From: Peng Fan <peng.fan@nxp.com>

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

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 arch/powerpc/kvm/powerpc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 9194cf492d1c..a567b63a5f1f 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -2210,10 +2210,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
 			break;
 		if (!kvmppc_book3s_hcall_implemented(kvm, hcall))
 			break;
-		if (cap->args[1])
-			set_bit(hcall / 4, kvm->arch.enabled_hcalls);
-		else
-			clear_bit(hcall / 4, kvm->arch.enabled_hcalls);
+		assign_bit(hcall / 4, kvm->arch.enabled_hcalls, cap->args[1]);
 		r = 0;
 		break;
 	}
-- 
2.51.0
Re: [PATCH] KVM: PPC: use assign_bit() where applicable
Posted by Gautam Menghani 3 days, 8 hours ago
On Sun, Sep 20, 2026 at 10:26:17AM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  arch/powerpc/kvm/powerpc.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 9194cf492d1c..a567b63a5f1f 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -2210,10 +2210,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>  			break;
>  		if (!kvmppc_book3s_hcall_implemented(kvm, hcall))
>  			break;
> -		if (cap->args[1])
> -			set_bit(hcall / 4, kvm->arch.enabled_hcalls);
> -		else
> -			clear_bit(hcall / 4, kvm->arch.enabled_hcalls);
> +		assign_bit(hcall / 4, kvm->arch.enabled_hcalls, cap->args[1]);
>  		r = 0;
>  		break;
>  	}
> -- 
> 2.51.0
> 
> 

Thanks for the cleanup.

Reviewed-by: Gautam Menghani <gautam@linux.ibm.com>
Re: [PATCH] KVM: PPC: use assign_bit() where applicable
Posted by Shrikanth Hegde 3 days, 11 hours ago
Hi Peng.

On 9/20/26 7:56 AM, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.
> 

Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>

> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>   arch/powerpc/kvm/powerpc.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 9194cf492d1c..a567b63a5f1f 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -2210,10 +2210,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>   			break;
>   		if (!kvmppc_book3s_hcall_implemented(kvm, hcall))
>   			break;
> -		if (cap->args[1])
> -			set_bit(hcall / 4, kvm->arch.enabled_hcalls);
> -		else
> -			clear_bit(hcall / 4, kvm->arch.enabled_hcalls);
> +		assign_bit(hcall / 4, kvm->arch.enabled_hcalls, cap->args[1]);
>   		r = 0;
>   		break;
>   	}


Just ensure you have covered all such possible open coding where applicable
in arch/powerpc/.
Re: [PATCH] KVM: PPC: use assign_bit() where applicable
Posted by Peng Fan 3 days, 8 hours ago
Hi Shrikanth,
On Mon, Sep 21, 2026 at 02:39:34PM +0530, Shrikanth Hegde wrote:
>Hi Peng.
>
>On 9/20/26 7:56 AM, Peng Fan (OSS) wrote:
>> From: Peng Fan <peng.fan@nxp.com>
>> 
>> Convert open-coded if/else with set_bit/clear_bit to the assign_bit API.
>> 
>
>Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>
>> Signed-off-by: Peng Fan <peng.fan@nxp.com>
>> ---
>>   arch/powerpc/kvm/powerpc.c | 5 +----
>>   1 file changed, 1 insertion(+), 4 deletions(-)
>> 
>> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
>> index 9194cf492d1c..a567b63a5f1f 100644
>> --- a/arch/powerpc/kvm/powerpc.c
>> +++ b/arch/powerpc/kvm/powerpc.c
>> @@ -2210,10 +2210,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>>   			break;
>>   		if (!kvmppc_book3s_hcall_implemented(kvm, hcall))
>>   			break;
>> -		if (cap->args[1])
>> -			set_bit(hcall / 4, kvm->arch.enabled_hcalls);
>> -		else
>> -			clear_bit(hcall / 4, kvm->arch.enabled_hcalls);
>> +		assign_bit(hcall / 4, kvm->arch.enabled_hcalls, cap->args[1]);
>>   		r = 0;
>>   		break;
>>   	}
>
>
>Just ensure you have covered all such possible open coding where applicable
>in arch/powerpc/.

My cocci rule as below, only one candicate for arch/powerpc/ is found.

// 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);


// __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);

Thanks
Peng
>