From nobody Tue Jun 23 08:14:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A616C433EF for ; Tue, 8 Mar 2022 16:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348352AbiCHQeX (ORCPT ); Tue, 8 Mar 2022 11:34:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348345AbiCHQeU (ORCPT ); Tue, 8 Mar 2022 11:34:20 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D62B33379 for ; Tue, 8 Mar 2022 08:33:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646757203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cvF6mTwU2sioCsPJ8tNKFYB0plPjCVi6fMhKN3lJBTA=; b=iMtTB3vDeggUWtkyaodND3H6LeCyEperUx1tiM4zkPoUPIAKBc6C4O7aRgF+sAUzowqzrY vNdh4umsKvB4nz/xwccLaUqfo8BnzW3v1crVfReq9aNx9P+BNdrqBPIynic6DItd1pchaV xShr8BoE7NrSbpUyvCl11LauqO+Ob84= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-596-A8bHgDhLOYed5lrdnJg18A-1; Tue, 08 Mar 2022 11:33:20 -0500 X-MC-Unique: A8bHgDhLOYed5lrdnJg18A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2289E8145F6; Tue, 8 Mar 2022 16:33:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6EAC797C3; Tue, 8 Mar 2022 16:33:18 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH] KVM: use kvcalloc for array allocations Date: Tue, 8 Mar 2022 11:33:18 -0500 Message-Id: <20220308163318.819164-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of using array_size, use a function that takes care of the multiplication. While at it, switch to kvcalloc since this allocation should not be very large. Signed-off-by: Paolo Bonzini Reviewed-by: Oliver Upton --- arch/x86/kvm/cpuid.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index afcdd4e693e5..419eb8e14f79 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1248,8 +1248,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, if (sanity_check_entries(entries, cpuid->nent, type)) return -EINVAL; =20 - array.entries =3D vzalloc(array_size(sizeof(struct kvm_cpuid_entry2), - cpuid->nent)); + array.entries =3D kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, = GFP_KERNEL); if (!array.entries) return -ENOMEM; =20 @@ -1267,7 +1266,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, r =3D -EFAULT; =20 out_free: - vfree(array.entries); + kvfree(array.entries); return r; } =20 --=20 2.31.1