From patchwork Sun Feb 11 17:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erick Archer X-Patchwork-Id: 199501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2035231dyd; Sun, 11 Feb 2024 09:52:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxPfAqB8tngh8skgJ/WUp4flweZ5yp+W05N6MooDjFyHoFEpLpRZGXa7JJvLtDtv02CSPq X-Received: by 2002:a17:906:b7cb:b0:a3b:d7c3:a73e with SMTP id fy11-20020a170906b7cb00b00a3bd7c3a73emr4253256ejb.1.1707673957040; Sun, 11 Feb 2024 09:52:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673957; cv=pass; d=google.com; s=arc-20160816; b=0XfU7j15dF72mFOmeTmxHpm9dWjfBD1WE/UGbaePVvl4GBHnwjRajAMploLKDqlOTn 1f07F3+sfzsDaNNpCB5o3Y/Gbidog1bQBCOw2RpRwcgv44zg3LvEazQqAx/K5v2VBbH+ 6OpSc+yD/DqyxEi8ABdMu7tX24A14eh5ttoMq4ml+VSWX5gPXnpCTzjc8TcfJipVbUff YdEY/u/By+SIK3SSjWH+evRRBGSdW7nzyr95r4Lk2S0YXWa/w5IWDS2sa7HNdBXcyRG6 g0WDQgbcrLUhElaRultQ9X29AdXOTF/u47ZgWBlawy8cDI4/IsVC3pXOR73lgnZpotxV Vgrg== 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=ERD1c/mF56uJIxn2vi13g3cEtEosEUFDswuA4CjfRk8=; fh=rGAAUDxVAnxmvJKr6quX/7BKOj1WcST+HUd9BphpA0I=; b=gV3LnHzdJMxpPNZ4Ev7ChXCBTEHFGzDE+px1qZNaMQBmOaIVln5QlMxcvz1N1W4nXa VD7HjeHWB9vHRCACeX7paty8KqLHw9jz9OPzAujx892FgHcqwfWYgCVf4t3IugyYfccY 8ELsGerQ9gZiRTnaZcTrcF6/N9UVe/TnpCpNkJi1arLo8RvsIp0epffeMf6u4XpHxlk3 vzrX6bjmFWPulTz5rIKFM8z0WrmSsaPCTWzMx4WuN0IwHsKOdAzfmUMcF/cP7P7f9bUR H49YYHLbgRJNcv3F3c212xilZL9KFkfLHboswe+6qzUQFlDZgryiXiEql9euDXmcg7dS h8GQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=mOkaH3mA; 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-60900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60900-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com X-Forwarded-Encrypted: i=2; AJvYcCX52pdrPvWsbkytclFcBhZY+mVbUJ5Z03y2JH4L/4FjMEYNnk5x4W+SyB3xn4E3CJwhKAj02xpXRofdUxGfaULcAPw0Cg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n18-20020a170906379200b00a365dd3a86asi3058507ejc.155.2024.02.11.09.52.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:52:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=mOkaH3mA; 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-60900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60900-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 90F301F21770 for ; Sun, 11 Feb 2024 17:52:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBCF35D493; Sun, 11 Feb 2024 17:52:22 +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="mOkaH3mA" Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (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 0F6715B685; Sun, 11 Feb 2024 17:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673940; cv=none; b=KvYByoXriYz5KfVFjLezr5FStxxshCc1qxbrx1suBhq/iCwPEgpsd+YoOofbz7JjMMmaKFTbafdOXX7/LuiqpWbDk1bhb1M+U6FLlcL7PskRfb9itXC7Rspc6xYpqN4b1W59v3EY/dRr0KEfaKzIpcPK/jag8y2IHISnw36OmvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673940; c=relaxed/simple; bh=f2eO+FYHFwTKrMLX02BEOBpAa90tEHpnB9dG/oL3+XA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=nqQzZ4ti4KYi7HyBAKxxi969n14QjTb9rSaHY96c0az5A0XcJeOmELA0Alm9bDrN/laVCHiH0Qfj1YjODTYwMhuFtWUsSpZNPj4/PhMDTAry4qRsx6jyTuoPAx0yIwjzv5t2LuVePQJ9D222QQJbXNnE7ZArue+cHfUs/87WySY= 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=mOkaH3mA; arc=none smtp.client-ip=212.227.17.20 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=1707673917; x=1708278717; i=erick.archer@gmx.com; bh=f2eO+FYHFwTKrMLX02BEOBpAa90tEHpnB9dG/oL3+XA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=mOkaH3mAEJGrziOsOi4RRqM+m5yie11GF8/ywPfvdYiLDH4ANKlu6ab6K5yRi32+ zt56lXHlEp4SBeAuCSv9K60dhmuepmNVLeo3+xAT7nQJsEqR8g8mcoECD9/QDiyER dg9CnlTeAYKZGhqtc3XnhHVH+7q8HGNVoB+vqF/+P4VOSFtNF03aKXantsbTdxIO2 RjOPWXi1Vp2YZ9lVhxpltPG9cTNfAwJXhFARcF1nPPLJRszWvh5+h4cbgyY7hXavm tF+YZ2YlWTq78sRCnAoJeOUjAv23vtszTGM+mdm2Z83aWSUwZTJTOcqsX+RWvN9dP O8UAWWs1bcb/MjDpMQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([79.157.194.183]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1N2V4J-1qqdmM2Yd5-013vIV; Sun, 11 Feb 2024 18:51:57 +0100 From: Erick Archer To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy , "Gustavo A. R. Silva" , Kees Cook Cc: Erick Archer , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] iommu/vt-d: Use kcalloc() instead of kzalloc() Date: Sun, 11 Feb 2024 18:51:43 +0100 Message-Id: <20240211175143.9229-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 X-Provags-ID: V03:K1:fRNt/jnU+EgR445uI1FodxKwopT7+a/mrfXW9mIP0JCRBnynv8J CqQm+x7fJyJXcPNr3eUv/TQY/vFvLiOqKuoYBepSxBIFvumB67rV1UZhqkR3CkMTF+dcNPI Yl21yBArAfKTKhhwT9PP0TNpjtCJk0fb5aWbmZ09eHpjHSt2iYvkRyAJQaIngPXJTyWTBT9 f45FaliNraYjGZ2kM3m5A== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:wI4IgzOPPy0=;TDkhQ6yQenORkRkTgJLiNmfm6Gi 5iW80IJ/ey3QnC1veoGSCMBdQbMHXSGaWqyEyg0wEIeiJke8XUPZGcuoFemWgbf8YOwJSmWOY F5WLHfRBGpROAxcxX7i5AK3bb/oDGrZFl6tQP7K1ZciNJk9Deom6B4U9Y7QDNOpH74JRJZ/0Q g1aaV2LnMscM8uHovQ6YF443hcmzZsAwIGe0wtMB1a4ECoX8h5gVszW+8SwZkajYnZow8TJkQ lMqf5ytzcbUN7IDBck3E+A1QubFlpYNYfQiilPG+NDJtYJhoY53u/fvUGOEeSJI5AIOJ57Sfu MuwG8zh+zOkBWv0p+rmGsmnW1vc7AiGBhByxJmNTr3ZgbnEuBja1u0kKgItQMecs1knwBJxDb 32i7iM8Ra91F1N5UW8gHRL3cAy9y3LbDksnP5J3bPqcL7SnvPuwFB/kyzjAfEyZCpBe4okbdM r/yMFgBWhQucTTmivdwGWnP3zx+jSve0ndgQWZ/wvAs4Nb4giAd8ZVYcecd+GxlY6NGELRQPt uhV0KoiSV5FlPphrNUhAOAPEWyuvRT8hsnIQzJnD0RfWBeGwEQvoUQnHS226QxXREyu9Tc7Nf qytb8yVAA42UVzM133l+eX0uvQJUxaTJ1lA8CC/6+h59q5zV64+zM3G9/UezNwW3t5i74Jrb6 FXxCgm8ZpOSohQJ9tpb7qjwukxVX8eGexTsYA2qAFg0knoqgktimtMLdFF9KLO3vpFUZlVL5J 0xbiUEQdQzPX5h9BZBL4J575YFZJWOrC0g5OG0lDd/61KYkpzo0aG5/MsKeilGuPMR567zEeH ztmsDBEbq8AU0Z7RHD18T4AKAQq0Ig0xBirZYLAvtpjqs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625927322840373 X-GMAIL-MSGID: 1790625927322840373 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 DMAR_LATENCY_NUM is the number of latency types defined in the "latency_type" enum. enum latency_type { DMAR_LATENCY_INV_IOTLB = 0, DMAR_LATENCY_INV_DEVTLB, DMAR_LATENCY_INV_IEC, DMAR_LATENCY_PRQ, DMAR_LATENCY_NUM }; However, using kcalloc() is more appropriate [2] 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 [2] Signed-off-by: Erick Archer Reviewed-by: Kees Cook Reviewed-by: Gustavo A. R. Silva --- drivers/iommu/intel/perf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.25.1 diff --git a/drivers/iommu/intel/perf.c b/drivers/iommu/intel/perf.c index 94ee70ac38e3..adc4de6bbd88 100644 --- a/drivers/iommu/intel/perf.c +++ b/drivers/iommu/intel/perf.c @@ -33,7 +33,7 @@ int dmar_latency_enable(struct intel_iommu *iommu, enum latency_type type) spin_lock_irqsave(&latency_lock, flags); if (!iommu->perf_statistic) { - iommu->perf_statistic = kzalloc(sizeof(*lstat) * DMAR_LATENCY_NUM, + iommu->perf_statistic = kcalloc(DMAR_LATENCY_NUM, sizeof(*lstat), GFP_ATOMIC); if (!iommu->perf_statistic) { ret = -ENOMEM;