Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp788613ybt; Wed, 17 Jun 2020 14:08:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5KqcZAp7i4V1ty1iiiOMB1P9r92HY03EsE7kVdWioTlZknqA7kVZoh4Qfhj5WWoRDTJey X-Received: by 2002:a17:906:1e95:: with SMTP id e21mr1072613ejj.240.1592428124024; Wed, 17 Jun 2020 14:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592428124; cv=none; d=google.com; s=arc-20160816; b=n6HIsLXH5UrotBikinStF7LZIneCF7Kn1Em+iD/otWZ5avtj2Oj/dnwbjOv3P7sBnI IIZN6WBeOZ2iP+RkBB9gAcprSZ1pkULM+f/cRU6MZc3qaLXguz0VqRod+4OseSQPojd5 5BSWXPB6y3FuOrdUuMysnsRCtFV/g/E2GnVJTowVbP2f2bpaMjPwjqmlaRE8z1ORI5fn 65juT5+cFgv2NWgvdHLJEMqI+Gv9QCiIXOMQnprCngEOCCu2Y1XzcsSOYC2V01QoQ9hF 4d4pahOWI+66l1G9Jfl3opauUPxwC/Cc5c85sg76//t8C8gpemo/1pMr2Xz4pc7HiL3q 8y1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=RNX6rs6H8RWro8Rl2SA0404ZbHTlnQCkFTHGVkeAF5Y=; b=fay1SNEomWDQHqymyrAdo9KH4eXKb/II289hAtIuHwxEbtz+OQ8X7pviRYx1hDPeFO DXPAtjZS2qy6vgdM0cmHaeHky/PzSD+KXjNi0n7kGasuPHygeQ5wG8/UCXDwPKZwI4Tk UM2qz2qthv1XdRpiT2c0i5muC2jRQSbB1jeKwNHwNxuOcZq9lbPvP4MW68u0Z5pcOF9o t86/2A9nTuRoaQklwLrD9zXwN53hXEpBXxc1PZDecP6sEWPtmbp/07Ev8ZM09l9Z6rfa vDvlQoivtniOcJIivat2FsyMWSScjStLhzJRoUTi2D0rZ5UJ4CQmId/rtOrEjai93a5g Y88w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zBAD2pPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mh16si587344ejb.129.2020.06.17.14.08.03; Wed, 17 Jun 2020 14:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zBAD2pPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbgFQVGP (ORCPT + 99 others); Wed, 17 Jun 2020 17:06:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:43942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbgFQVGP (ORCPT ); Wed, 17 Jun 2020 17:06:15 -0400 Received: from embeddedor (unknown [189.207.59.248]) (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 7F8CE2186A; Wed, 17 Jun 2020 21:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592427975; bh=PxleSRdzxhbBNA5Z6VGYwX4pwZygLkPhy8QDrAX3jCk=; h=Date:From:To:Cc:Subject:From; b=zBAD2pPyr5zueEtIkpdCXgi7IRAM+MnOtTEf0cFRMdnBMiDG6HfNpnK76KbKhg5rY nL9uhthDQKlT/UphVgxG81qqyn4Q9UCBABeqek8Om/jsddbJ0cGZyPSl1rCKFPUmoD 2bKIGoBBqDcN4Wm5z+YGkK1H4c1f34HUfl1WHbbc= Date: Wed, 17 Jun 2020 16:11:35 -0500 From: "Gustavo A. R. Silva" To: Zhou Wang , Dan Williams , Vinod Koul Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] dmaengine: hisilicon: Use struct_size() in devm_kzalloc() Message-ID: <20200617211135.GA8660@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva --- drivers/dma/hisi_dma.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/dma/hisi_dma.c b/drivers/dma/hisi_dma.c index ed3619266a48..e1a958ae7925 100644 --- a/drivers/dma/hisi_dma.c +++ b/drivers/dma/hisi_dma.c @@ -511,7 +511,6 @@ static int hisi_dma_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct device *dev = &pdev->dev; struct hisi_dma_dev *hdma_dev; struct dma_device *dma_dev; - size_t dev_size; int ret; ret = pcim_enable_device(pdev); @@ -534,9 +533,7 @@ static int hisi_dma_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret) return ret; - dev_size = sizeof(struct hisi_dma_chan) * HISI_DMA_CHAN_NUM + - sizeof(*hdma_dev); - hdma_dev = devm_kzalloc(dev, dev_size, GFP_KERNEL); + hdma_dev = devm_kzalloc(dev, struct_size(hdma_dev, chan, HISI_DMA_CHAN_NUM), GFP_KERNEL); if (!hdma_dev) return -EINVAL; -- 2.27.0