From patchwork Sun Jan 28 11:52:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erick Archer X-Patchwork-Id: 13534446 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B17F623745; Sun, 28 Jan 2024 11:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706442779; cv=none; b=IHeN9//OB3QYHgFs1UEfz3syPJZBzVC5cK4SvACc7lScHxpIwvqXu29j1e143RLou4PoBTRvN59aAI9/axlJkUN0zOo1pIGEbHaZyUgMryM/xNv5aCpyXKNslleBAAY53BSzUdvkKGQ9ny4a3PF4SuCFHMMwS0WamH5263V+LOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706442779; c=relaxed/simple; bh=8qgAYxoJEnz0fBm9iJvQjJPfTW90lqM8TrpQVaYANAU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=iT011zMy6eRPGRvh4NAW6AAln1aAgEIIXvxr5UbNV2wZdXz2afuxzkwjgHvQdtp/VKG8UmsKl52GXgz3NuZBoXvhQkHrz9VvGxR5JbsDRcf3xXDD3Fnw1mpeBjCauuuO0Kb5suLdlxGQYGZ6ePGnYPZMOMrx/mjNvpFQCi/ij1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com; spf=pass smtp.mailfrom=gmx.com; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b=nVl1GD4e; arc=none smtp.client-ip=212.227.15.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b="nVl1GD4e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.com; s=s31663417; t=1706442770; x=1707047570; i=erick.archer@gmx.com; bh=8qgAYxoJEnz0fBm9iJvQjJPfTW90lqM8TrpQVaYANAU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=nVl1GD4eYpC6MnLtFA0UzYbsxUtHCpP4SFQ1CJzTGpfUzyEHjN2LB7T5RBvAhv6E 9RvvjVO+Lj8jkkSOrMC8OyWRn1rnPZgEXqlqiULjQA2WqB7m0eIeLdvIw01U55+hZ 1nEyHxiLWLSG7VJEywQgXu2102QMPYoOD5+2s9zN2sU6Kh4EZexqLQAxkgLfxRk4Q Lt+dNk82L3IBmop+fEiiGRLpqk0fIyFudgajxqkzG1dCgDI48r1uuR9gqnpgCJA5j DCgWrDNpSmxV6fy7xWZefyzG0zo0D44U1Y+9yaALoOkHVsE2fyNTHw4EgzkIjcXGa GJlznFKSGIXxosN7Mg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([79.157.194.183]) by mail.gmx.net (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MA7GS-1rMxFg0ZEw-00BeIA; Sun, 28 Jan 2024 12:52:50 +0100 From: Erick Archer To: Vinod Koul , "Gustavo A. R. Silva" Cc: Erick Archer , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] dmaengine: pl08x: Use kcalloc() instead of kzalloc() Date: Sun, 28 Jan 2024 12:52:36 +0100 Message-Id: <20240128115236.4791-1-erick.archer@gmx.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 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hWaQY8SCXeowqf3cV/M0pmKboqJf0VmijKmHQx+38GFbJhI5n86 epx6wOTa5eRHN5dc/Z3Hi1+F42rW+5W5tuXPaSvZ5FPU40PFcNic7XxQgTU1iNoQ2tiFJYjjO 8KisukA11HOlrSnOz6C/svPsobWntEUOePplcuzq8jqgfEUtSId3DBoYqWcLM9W89w+9CNSG+ 1Xww/wifeRY2UF0NVIqEIOzLDyg= This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1]. Here the multiplication is obviously safe because the "channels" member can only be 8 or 2. This value is set when the "vendor_data" structs are initialized. static struct vendor_data vendor_pl080 = { [...] .channels = 8, [...] }; static struct vendor_data vendor_nomadik = { [...] .channels = 8, [...] }; static struct vendor_data vendor_pl080s = { [...] .channels = 8, [...] }; static struct vendor_data vendor_pl081 = { [...] .channels = 2, [...] }; However, using kcalloc() is more appropriate [1] and improves readability. This patch has no effect on runtime behavior. Link: https://github.com/KSPP/linux/issues/162 [1] Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] Signed-off-by: Erick Archer Reviewed-by: Gustavo A. R. Silva --- drivers/dma/amba-pl08x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/drivers/dma/amba-pl08x.c b/drivers/dma/amba-pl08x.c index eea8bd33b4b7..e40766108787 100644 --- a/drivers/dma/amba-pl08x.c +++ b/drivers/dma/amba-pl08x.c @@ -2855,8 +2855,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id) } /* Initialize physical channels */ - pl08x->phy_chans = kzalloc((vd->channels * sizeof(*pl08x->phy_chans)), - GFP_KERNEL); + pl08x->phy_chans = kcalloc(vd->channels, sizeof(*pl08x->phy_chans), + GFP_KERNEL); if (!pl08x->phy_chans) { ret = -ENOMEM; goto out_no_phychans;