Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1174781rdb; Fri, 19 Jan 2024 10:19:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1rL0wGG0pmZWckHvRqJgnZVhfrgPjow9HERafeK5fDVcvvaJdNW5Bvr6RCtxOvyMLV17+ X-Received: by 2002:ad4:5dee:0:b0:681:9ac6:a31d with SMTP id jn14-20020ad45dee000000b006819ac6a31dmr1905046qvb.56.1705688389129; Fri, 19 Jan 2024 10:19:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705688389; cv=pass; d=google.com; s=arc-20160816; b=H27b/EmmFmYIJP05MpnBXM3hxDZ8GncOIXAEghsasLzt48S/fWpYVAuL1OvmuVk8M/ nDrygxPZjm09E53BoFfctsZQCkiAKSBQr4IJe++D7sHiQr0NoPCbPtiTnbUsjRBJru9o qywANId2QNonBVALLokfsd+zZfkFmskAmO4t/eQX5X++gFyxIK5Z1DtsqWlAdleVE1B9 B4GbeDkLj0OPeIr9n/JLE5BSbkXXVanobt27vQGxXh1U4uRtwdwkcy2/8FD5lgNdrItX kdNVkFv8lyuuTikjxeciZKRkvndDznmjQv0QP15c3PfzHxX7ByaqTJYp9706a2im3KdQ lVkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=Tzt2iTW/DOcsLYbRgv59xanfeVlUGVxd5Y5vtZKFgZ0=; fh=b/CG43Ua/oMHHvLnmYT/a1dNDj7pCUx/H0Cf/MVfPE4=; b=hdbzLqeIe35pI9ZdiL4HXV8sxDWDt3oulfC+nTR6innsDXGGLh9p/ygEg4N/3I/Fgx NEGnjqrUf6V/HGObRHqu4MITAz7VXvW34qX7jKkW6NeE9p9lWEE+Obnh23Q8vVzcJSW0 wz6ItTnF4degeiy0xJGGQL8LOVscTMCqC25MadSVXpVyyhQaitBQvveisbJJ+4/HxEox bADBmdJg7Sk6K6UnZH7WLqTpi5BjKfEdhIat+Yl02Jg4tSSxiAkr6Nn7dFFNBf/76IGc /F+Sh7JhTMUplNCuQzYi3Jw16vL8lywrNFUDbdEgGtGliWoutipd348gNwC/6cuBjk3u HicA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=r+Gv4n3N; arc=pass (i=1 spf=pass spfdomain=gmx.com dkim=pass dkdomain=gmx.com dmarc=pass fromdomain=gmx.com); spf=pass (google.com: domain of linux-kernel+bounces-31468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31468-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n15-20020a0c8c0f000000b0068059ec19b2si16887147qvb.73.2024.01.19.10.19.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 10:19:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=r+Gv4n3N; arc=pass (i=1 spf=pass spfdomain=gmx.com dkim=pass dkdomain=gmx.com dmarc=pass fromdomain=gmx.com); spf=pass (google.com: domain of linux-kernel+bounces-31468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31468-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DD19E1C249DB for ; Fri, 19 Jan 2024 18:19:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE8A15645B; Fri, 19 Jan 2024 18:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b="r+Gv4n3N" Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 E77D656447; Fri, 19 Jan 2024 18:19:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705688381; cv=none; b=ZJF7WFQnb7ydQbSxRje6b9XJr8KdO7VhLEM0x7U7fDaureLDbuLOvvKUDBbXdBKrCjIpi9s1qUjrhN0qnkfZUEullTFtpy4KcpNZkwBNgr5nYbpgYrJbRx4X6We/nxOfQk+oav8V0ktczu8J1grcaRgLBYRLcB1AfSGayIWSKZw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705688381; c=relaxed/simple; bh=sBqFdsnrpG5B2aVYepB4f2kUIlIRBbAjsJR6pnILbSk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tBoOG6DAJ93VdQ9u3dqz4zOJEHGzESwtKZfH8GReX5J52oRBSuyTwY1+pctjInbdOImW+2rGWToAL+IMlyKeCWzdntDhN0PkU1LXD6Wf0WFmRTVp0RdGS5cOPre4eZBpk7vEAc98k3Dzjv4L6fOU0whpgSp3FGv/7UJxeiCujvM= 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=r+Gv4n3N; arc=none smtp.client-ip=212.227.15.19 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.com; s=s31663417; t=1705688362; x=1706293162; i=erick.archer@gmx.com; bh=sBqFdsnrpG5B2aVYepB4f2kUIlIRBbAjsJR6pnILbSk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=r+Gv4n3N0kqDcshWjM149MnwQbnVFG+pNKS0sAe9hXZRo2ymuTbnngBxSMvBt1pQ 5bDmwnP1fSyRHCg8ib12FDEtpefdJkGyKxVa5wNi4NPNSA/heEp1V8HO+yJOdJ0Fj GdOAP35qxYYlKXTsn9eR0LNvVqbdC8qXBW17B4h3cbao8L19co0SgphZ+1jmN5d2V mKh0ATMg1qXXinsxLGbeyVV1/7xSkU/jKbypkYrsrOi6ivm8PD8joRLGZhX4OjCea V7DXBpB8puodWgzmsg0QOcZWpGGhyBzbeDt0cN5f9hFru6elOGsHCRCKxKd+pJYFW Inci3UMJ3Gs7B+6Ggg== 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 1MPokD-1rmfbm3wId-00MrKt; Fri, 19 Jan 2024 19:19:22 +0100 From: Erick Archer To: Linus Walleij , Michal Simek , "Gustavo A. R. Silva" Cc: Erick Archer , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] pinctrl: pinctrl-zynqmp: Use devm_kcalloc() instead of devm_kzalloc() Date: Fri, 19 Jan 2024 19:19:09 +0100 Message-Id: <20240119181909.7079-1-erick.archer@gmx.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:KENkPdNVovQVg33hH+1L5lSU0tTV7tRXp9M+P2HMwnVAPTlbIbL PweBJcCplxH72i91i8mgFr5KWChN98onhXv6h0ZIbcxqjjsXvFY+rYFXe8TDQixEbV783cF /JdyingxCL0j0rqQzM4f/PWAgV9PNBReQ4Rp0dGAaIBXdCzNNXwmRmJXfxfQdoHBkGFIOrG A/amwTK/l8cXqaszrCxkQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:u/hSC2xNnJ4=;Le7EPSL310H42OZtCq1g0w7KJq0 OoKMQ1MPvTJ9XaGVPc6RO7TqvN1mqqhQCYYO50EJ4FEXFjfE3MUYymywEheZrOWSp68TtOj8l sxzcHXsQYlXkpSVJ3c5Eq/sCul3W3oh5JDZo1aidunFmcoRg191IWxUVFuyq8W/5aN7SLpFWQ +oEVidHQtnavFyNenPY7vZsjWWuA53nHJlZ9eAG3A/cpthPciVY8oZ7OMG/5BPRuB7Yss1v9y xibpdriWNDM1XW/tMjLoeE5WiLC7tej6nuPi2KyKoAbBlLQrtHI3jBIlC8/9P1QLBT8na6mQU 2Ctxs5pWuqBMZ8WdF27SexQXJFNPEHzVGrnPokDzMVIWxvHJpcfL97VeiwyD/1UbgVPq8uWK/ 8J5QHc4d0MeXU6YoRgEEz4PGAQY9ISBYNZek208dlC/T1ziH2vNcd65/1pCfXP7pcPafBywyo GCsYE/41wi3vE1k+c1b9UXh9KVtC/Jj4Dbm3AS4PTGIHoQ09CwYa3NTlUlTpbOjz5tj98bO7M tujTHUIJ/ybasx6GfGObe65n2R2PZYjnTCVrkcztiePLq9Zng4qZrTCZqPso94aQZFrl9dOM0 P4EcbYPgkQ4LzLYzxjuo/VXfNvnt2aEKHeSTJPyCtqtRidll/4oavaOJktMDOxB/t+gl7uvSM dd1Vd2zzyxub9vGzUAfqdaXMBmNWiGjY0UFcc+IaqexxQ6v80fK2b2FYqhQ4cHhf5dR5Gf2pK 1eecqAOArHVoUh+8SKp8/WDvvvJWIuk+MTdd4rA4cFYg3T4zXhnBUNhkCtV/kkd4tD3LLWxq5 v2cPlEnaJuDLwrXXeup7U87sgLSSlC6TFU36BIZTkyzEKFQveM/dRwLThoTqjTRnZQdOSnD7F egc5kHoBTMeFHZ2t3WzNcm7tExe4woNci5M07XQz77SAy3kFi8493bZ679F3l5Y4PLlOurI/B nxzqcpqKBUX+q1QjvniClAM2wiY= As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. So, use the purpose specific devm_kcalloc() function instead of the argument size * count in the devm_kzalloc() function. Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-co= ded-arithmetic-in-allocator-arguments [1] Link: https://github.com/KSPP/linux/issues/162 Signed-off-by: Erick Archer =2D-- drivers/pinctrl/pinctrl-zynqmp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zy= nqmp.c index f2be341f73e1..5c46b7d7ebcb 100644 =2D-- a/drivers/pinctrl/pinctrl-zynqmp.c +++ b/drivers/pinctrl/pinctrl-zynqmp.c @@ -562,7 +562,7 @@ static int zynqmp_pinctrl_prepare_func_groups(struct d= evice *dev, u32 fid, const char **fgroups; int ret, index, i; - fgroups =3D devm_kzalloc(dev, sizeof(*fgroups) * func->ngroups, GFP_KERN= EL); + fgroups =3D devm_kcalloc(dev, func->ngroups, sizeof(*fgroups), GFP_KERNE= L); if (!fgroups) return -ENOMEM; @@ -754,7 +754,7 @@ static int zynqmp_pinctrl_prepare_function_info(struct= device *dev, if (ret) return ret; - funcs =3D devm_kzalloc(dev, sizeof(*funcs) * pctrl->nfuncs, GFP_KERNEL); + funcs =3D devm_kcalloc(dev, pctrl->nfuncs, sizeof(*funcs), GFP_KERNEL); if (!funcs) return -ENOMEM; @@ -768,7 +768,7 @@ static int zynqmp_pinctrl_prepare_function_info(struct= device *dev, pctrl->ngroups +=3D funcs[i].ngroups; } - groups =3D devm_kzalloc(dev, sizeof(*groups) * pctrl->ngroups, GFP_KERNE= L); + groups =3D devm_kcalloc(dev, pctrl->ngroups, sizeof(*groups), GFP_KERNEL= ); if (!groups) return -ENOMEM; @@ -830,7 +830,7 @@ static int zynqmp_pinctrl_prepare_pin_desc(struct devi= ce *dev, if (ret) return ret; - pins =3D devm_kzalloc(dev, sizeof(*pins) * *npins, GFP_KERNEL); + pins =3D devm_kcalloc(dev, *npins, sizeof(*pins), GFP_KERNEL); if (!pins) return -ENOMEM; =2D- 2.25.1