From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F534C3A59E for ; Wed, 4 Sep 2019 04:56:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 010C522CF7 for ; Wed, 4 Sep 2019 04:56:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="R87gEr9b"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qru4PME1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 010C522CF7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cQzZIhvf1NSBagVUqES1QmoqVVTaCW1mDSx5dFCz5Fs=; b=R87gEr9bfdpABe oHVrpszdtqHot1ymMKXs2m9rYJ8zyzQD1ritTvxPr5V237ScknFEHLPdRlZCNid1kkQPtA1Z+tlVv +7e9T1f/UME8zKAa8UMvD240Iy4gWtqfESIQWSupg4NWF8xq9VYtok96nl+LzLuZvpYdwTCGtKFfS TXQCMpnuR3CC+tleXZ2gWxxdrHiThZ5fU8Ow5JwMMbyPAYNIBPZHeeJH43dSQAp4g4f+IUM4CLvbX OWLzuVvm84UObqzCQYAVATJ/VM/PI/nXar7gB7wyprPVOT0Ez4jpQBl/sA9cHkBVpdp16WTMg9HC7 yKGnRxwWA+ryL7waFsIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i5NLL-0007Ep-9k; Wed, 04 Sep 2019 04:56:31 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i5NLH-0007EN-TN for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2019 04:56:29 +0000 Received: from localhost (unknown [122.182.201.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A4AB12077B; Wed, 4 Sep 2019 04:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567572987; bh=xkQZikYEyY3c7L/C+i3x3dyZJTWQdFUTYOzei9xlyQk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Qru4PME1plSqZSD3Y0yICIVW9mG8C6MIOggnFtQeOImhWC+FBN6IDZmu3YNXSXfsp /CtM4d+VWQw/4xbdRL1f5E/kqn+X8vqamBF55CBzDkJAaWkH6pNZU4tRZd+X+E6DqX V7Xgvu0JOuirnwEN3Hsu9poD7z85dNhWmTT4l4mg= Date: Wed, 4 Sep 2019 10:25:19 +0530 From: Vinod Koul To: "Gustavo A. R. Silva" Subject: Re: [PATCH] dmaengine: stm32-dma: Use struct_size() helper Message-ID: <20190904045519.GZ2672@vkoul-mobl> References: <20190830161423.GA3483@embeddedor> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190830161423.GA3483@embeddedor> User-Agent: Mutt/1.12.0 (2019-05-25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190903_215627_974658_18D797BE X-CRM114-Status: GOOD ( 11.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Torgue , linux-kernel@vger.kernel.org, Maxime Coquelin , dmaengine@vger.kernel.org, Dan Williams , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Kees Cook Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 30-08-19, 11:14, Gustavo A. R. Silva wrote: > One of the more common cases of allocation size calculations is finding > the size of a structure that has a zero-sized array at the end, along > with memory for some number of elements for that array. For example: > > struct stm32_dma_desc { > ... > struct stm32_dma_sg_req sg_req[]; > }; > > > Make use of the struct_size() helper instead of an open-coded version > in order to avoid any potential type mistakes. > > So, replace the following function: > > static struct stm32_dma_desc *stm32_dma_alloc_desc(u32 num_sgs) > { > return kzalloc(sizeof(struct stm32_dma_desc) + > sizeof(struct stm32_dma_sg_req) * num_sgs, GFP_NOWAIT); > } > > with: > > kzalloc(struct_size(desc, sg_req, num_sgs), GFP_NOWAIT) > > This code was detected with the help of Coccinelle. Applied, thanks -- ~Vinod _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel