KVM: s390: pci: Fix allocation size of aift kzdev elements

Message ID 20221026013234.960859-1-rafaelmendsr@gmail.com
State New
Headers
Series KVM: s390: pci: Fix allocation size of aift kzdev elements |

Commit Message

Rafael Mendonca Oct. 26, 2022, 1:32 a.m. UTC
  The 'kzdev' field of struct 'zpci_aift' is an array of pointers to
'kvm_zdev' structs. Allocate the proper size accordingly.

Reported by Coccinelle:
  WARNING: Use correct pointer type argument for sizeof

Fixes: 98b1d33dac5f ("KVM: s390: pci: do initial setup for AEN interpretation")
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
---
 arch/s390/kvm/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Matthew Rosato Oct. 26, 2022, 1:36 p.m. UTC | #1
On 10/25/22 9:32 PM, Rafael Mendonca wrote:
> The 'kzdev' field of struct 'zpci_aift' is an array of pointers to
> 'kvm_zdev' structs. Allocate the proper size accordingly.
> 
> Reported by Coccinelle:
>   WARNING: Use correct pointer type argument for sizeof
> 
> Fixes: 98b1d33dac5f ("KVM: s390: pci: do initial setup for AEN interpretation")
> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>

Thanks for reporting & fixing.

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>

> ---
>  arch/s390/kvm/pci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
> index c50c1645c0ae..ded1af2ddae9 100644
> --- a/arch/s390/kvm/pci.c
> +++ b/arch/s390/kvm/pci.c
> @@ -126,7 +126,7 @@ int kvm_s390_pci_aen_init(u8 nisc)
>  		return -EPERM;
>  
>  	mutex_lock(&aift->aift_lock);
> -	aift->kzdev = kcalloc(ZPCI_NR_DEVICES, sizeof(struct kvm_zdev),
> +	aift->kzdev = kcalloc(ZPCI_NR_DEVICES, sizeof(struct kvm_zdev *),
>  			      GFP_KERNEL);
>  	if (!aift->kzdev) {
>  		rc = -ENOMEM;
  
Christian Borntraeger Oct. 26, 2022, 1:40 p.m. UTC | #2
Am 26.10.22 um 03:32 schrieb Rafael Mendonca:
> The 'kzdev' field of struct 'zpci_aift' is an array of pointers to
> 'kvm_zdev' structs. Allocate the proper size accordingly.
> 
> Reported by Coccinelle:
>    WARNING: Use correct pointer type argument for sizeof
> 
> Fixes: 98b1d33dac5f ("KVM: s390: pci: do initial setup for AEN interpretation")
> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>

Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>

> ---
>   arch/s390/kvm/pci.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
> index c50c1645c0ae..ded1af2ddae9 100644
> --- a/arch/s390/kvm/pci.c
> +++ b/arch/s390/kvm/pci.c
> @@ -126,7 +126,7 @@ int kvm_s390_pci_aen_init(u8 nisc)
>   		return -EPERM;
>   
>   	mutex_lock(&aift->aift_lock);
> -	aift->kzdev = kcalloc(ZPCI_NR_DEVICES, sizeof(struct kvm_zdev),
> +	aift->kzdev = kcalloc(ZPCI_NR_DEVICES, sizeof(struct kvm_zdev *),
>   			      GFP_KERNEL);
>   	if (!aift->kzdev) {
>   		rc = -ENOMEM;
  
Janosch Frank Oct. 26, 2022, 2:54 p.m. UTC | #3
On 10/26/22 15:36, Matthew Rosato wrote:
> On 10/25/22 9:32 PM, Rafael Mendonca wrote:
>> The 'kzdev' field of struct 'zpci_aift' is an array of pointers to
>> 'kvm_zdev' structs. Allocate the proper size accordingly.
>>
>> Reported by Coccinelle:
>>    WARNING: Use correct pointer type argument for sizeof
>>
>> Fixes: 98b1d33dac5f ("KVM: s390: pci: do initial setup for AEN interpretation")
>> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
> 
> Thanks for reporting & fixing.
> 
> Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>

After consulting Matt I've put this into the CI and I'll pick it once it 
received a bit of coverage.
  

Patch

diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
index c50c1645c0ae..ded1af2ddae9 100644
--- a/arch/s390/kvm/pci.c
+++ b/arch/s390/kvm/pci.c
@@ -126,7 +126,7 @@  int kvm_s390_pci_aen_init(u8 nisc)
 		return -EPERM;
 
 	mutex_lock(&aift->aift_lock);
-	aift->kzdev = kcalloc(ZPCI_NR_DEVICES, sizeof(struct kvm_zdev),
+	aift->kzdev = kcalloc(ZPCI_NR_DEVICES, sizeof(struct kvm_zdev *),
 			      GFP_KERNEL);
 	if (!aift->kzdev) {
 		rc = -ENOMEM;