From patchwork Thu Jan 20 02:01:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 12718168 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 1700FC433EF for ; Thu, 20 Jan 2022 01:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358126AbiATBzX (ORCPT ); Wed, 19 Jan 2022 20:55:23 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:46728 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232742AbiATBzX (ORCPT ); Wed, 19 Jan 2022 20:55:23 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BFD3DB81C97; Thu, 20 Jan 2022 01:55:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53833C004E1; Thu, 20 Jan 2022 01:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642643720; bh=UBA9EAgXb+ndoEEnlylpF1zO8z2g96V3hPj15HRcAfo=; h=Date:From:To:Cc:Subject:From; b=hTAD6NZzQUZRVWlrg08cB/oSXOrRYxSxV43MFikx9DTJBxdy2ucAbg84idFWkdNRV B/RDhzWSaiRnbsCVaoksK6xFGqjGYypV3fgghZqQ8a3pV+b3yM3C3odylOF+l5UT8P 3I31vwTMa9reYVdt0tVbUKM6tXyDkgcuhE/Lahh6VX/WId8kWRRsAwUQYRCWiFa9IN g1DuJawcjB8ViBxapaF4dYorah58Z9hSOtigQWJ/rIjYVtPHoz/Y2/LyF4b0b8aPyI X3Cegww/ufVf8wgpbvKbHT0QanEPrE/oVOY71G75SRvz5PL2pmtUmvEjAp5fcHnooN 545XOG3Iz5T2g== Date: Wed, 19 Jan 2022 20:01:55 -0600 From: "Gustavo A. R. Silva" To: Felipe Balbi , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] usb: gadget: f_phonet: Use struct_size() helper in kzalloc() Message-ID: <20220120020155.GA76981@embeddedor> MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/usb/gadget/function/f_phonet.c:673:16: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/160 Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva --- drivers/usb/gadget/function/f_phonet.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/f_phonet.c b/drivers/usb/gadget/function/f_phonet.c index 068ed8417e5a..0bebbdf3f213 100644 --- a/drivers/usb/gadget/function/f_phonet.c +++ b/drivers/usb/gadget/function/f_phonet.c @@ -668,10 +668,8 @@ static struct usb_function *phonet_alloc(struct usb_function_instance *fi) { struct f_phonet *fp; struct f_phonet_opts *opts; - int size; - size = sizeof(*fp) + (phonet_rxq_size * sizeof(struct usb_request *)); - fp = kzalloc(size, GFP_KERNEL); + fp = kzalloc(struct_size(fp, out_reqv, phonet_rxq_size), GFP_KERNEL); if (!fp) return ERR_PTR(-ENOMEM);