From patchwork Wed Apr 3 05:26:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 10882859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E00F139A for ; Wed, 3 Apr 2019 05:39:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F07CD285E5 for ; Wed, 3 Apr 2019 05:39:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E444328640; Wed, 3 Apr 2019 05:39:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4185F285E5 for ; Wed, 3 Apr 2019 05:39:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hBYaR-0001Wc-G9; Wed, 03 Apr 2019 05:37:23 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hBYQ5-0000lZ-8H for xen-devel@lists.xenproject.org; Wed, 03 Apr 2019 05:26:41 +0000 X-Inumbo-ID: 0ec332d0-55d1-11e9-9f73-1f67b4bf027e Received: from youngberry.canonical.com (unknown [91.189.89.112]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 0ec332d0-55d1-11e9-9f73-1f67b4bf027e; Wed, 03 Apr 2019 05:26:39 +0000 (UTC) Received: from mail-wm1-f70.google.com ([209.85.128.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hBYQ2-0003xU-Gx for xen-devel@lists.xenproject.org; Wed, 03 Apr 2019 05:26:38 +0000 Received: by mail-wm1-f70.google.com with SMTP id t20so3693074wmi.1 for ; Tue, 02 Apr 2019 22:26:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=ECodeZO9T5iZTHTW0pQrH8foCwy+FC2Ouv0VI/SA1Ss=; b=Tt4bCW/AyDvuwebB09x/NnnLcLO/0vYElydt82Wej6A8oB/daqcGVebTVcSCSjx0WA 14fGQfoDrQV/BBVUTeNSHUJC14pivMVO1OzjWhSu5St4/qSfzMMumcep5pWe6uGoEFOC K33/v3+7lGtCx6M3MZZCvkDC2+qcwdQ99QAdPwXAf2z/THk/OCwxPEbWfN5F8dgjbp/k 12xBtenUbr4FlxCWMguIzYQfHJqazqe49gQ0OCoZuE1A/WcVbRbHazFcW0un45qUQghg TwZ+qAQyVosrYZ5VrOB3JecwK5mmEcjvKDXLry2y/mF6Izb0XTEheqTMJ95zp5kQhdg9 KHdQ== X-Gm-Message-State: APjAAAVp3Wf4FWVrp3aYUPToykxwiiTLbyBprtKJ3zYd7Vd0KsGPc/LB 16j/8rG231Yl1KVmkRPc3U0hNmFJxTQniNySMh3V2Q2U83SBqFhyWouiE093N4GK0ztobsYGmmc sQblvkNSHQCOYDE2SmArmOR9l50PCg3+xC0ZznCR7Gk4E X-Received: by 2002:adf:ffc2:: with SMTP id x2mr35849750wrs.86.1554269198285; Tue, 02 Apr 2019 22:26:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6wn4GAs3/mxi7+HnSA463u1EJIYzbDZCtS52uQteIk76aOQLqlNSa8Cx4aYgCamrCNj4FSA== X-Received: by 2002:adf:ffc2:: with SMTP id x2mr35849738wrs.86.1554269198113; Tue, 02 Apr 2019 22:26:38 -0700 (PDT) Received: from localhost (host141-127-dynamic.17-87-r.retail.telecomitalia.it. [87.17.127.141]) by smtp.gmail.com with ESMTPSA id z18sm24988643wrr.90.2019.04.02.22.26.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 22:26:37 -0700 (PDT) Date: Wed, 3 Apr 2019 07:26:36 +0200 From: Andrea Righi To: Boris Ostrovsky , Juergen Gross Message-ID: <20190403052636.GC21532@xps-13> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Mailman-Approved-At: Wed, 03 Apr 2019 05:37:22 +0000 Subject: [Xen-devel] [PATCH] xen: use struct_size() helper in kzalloc() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, Stefano Stabellini , linux-kernel@vger.kernel.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP struct privcmd_buf_vma_private has a zero-sized array at the end (pages), use the new struct_size() helper to determine the proper allocation size and avoid potential type mistakes. Signed-off-by: Andrea Righi Reviewed-by: Juergen Gross --- drivers/xen/privcmd-buf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/xen/privcmd-buf.c b/drivers/xen/privcmd-buf.c index de01a6d0059d..a1c61e351d3f 100644 --- a/drivers/xen/privcmd-buf.c +++ b/drivers/xen/privcmd-buf.c @@ -140,8 +140,7 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) if (!(vma->vm_flags & VM_SHARED)) return -EINVAL; - vma_priv = kzalloc(sizeof(*vma_priv) + count * sizeof(void *), - GFP_KERNEL); + vma_priv = kzalloc(struct_size(vma_priv, pages, count), GFP_KERNEL); if (!vma_priv) return -ENOMEM;