Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp711656lqp; Thu, 21 Mar 2024 13:10:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVF3hTK4KlCHN2zBYu0U3Z2SKOvSJdNVKyvOJx/Bdarhs5223zKPpELwKzaDWhcTEqFoRy8mhWddFn1z/dkj6x/mwf3CwRBXR3UqlXapw== X-Google-Smtp-Source: AGHT+IEBxRglzuIrE4oVKZkYNiitWU7v0LZUrQiXQ+LVAse0FstnzlByogcX66goRU5mhb5Gh0sK X-Received: by 2002:a17:906:7f86:b0:a46:61ef:2846 with SMTP id f6-20020a1709067f8600b00a4661ef2846mr309037ejr.66.1711051828750; Thu, 21 Mar 2024 13:10:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711051828; cv=pass; d=google.com; s=arc-20160816; b=nHpoeD19WQk7LjSgY2K3pLMJVaxDC584xJaH08Nif9dGEDYrVjZ8o9c69Rd70tnJx0 hGmPGtb+/3flMzfre3GBSGcZwE6237Dn0qapv4kP/2YeC2dF0kOnUWzd9XLnbjItTRtl pg/vNR8IC4iCjQT/dvYtWtH/MmfyuwDn7URqJtoh9ZPsTyNjr/7ttqT2Eln9ntlw9nJw hsu50LK5dWHrsV/Zk4OsuE/1Qz6B+uhEtqguDZRVG8zQFJGq2KHqgedPiM20yOzPrM1C P2HLQIAvEqzhKRpk38Dm4nSZiCutdO91ZidLtVGsKCIugngaPA+rtrV028bKwlYhbQSp xyig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=Eb6K5oovm67eA2MqQVFdKN97AFgRU83d114MwSaVLHQ=; fh=C8vSNxJ4pGZPezqabtzGtNZ44MyVCuFIIdFE1MqDIxQ=; b=ij31Dod0G6eRgbxQ2yBYEnqnedNANCqX3LM1Epm3hvo57OMp/sds09RQRKTrtSJsCz Ks8BrFe2CpWqu04BkFQY75Ia8TIgUvDgXaQ7T+vsfQ3nQkp8IbPblkjQY7P3hjqERnti Io6LP3E9c5iIuHzOOQfcnTawZ3jECSCtziEsIDNDxmC7PZBWDt7qnX+HWDWlM/iOS9b2 ZRIzsdYiJwpj7PSdRUUmkeDo2bolYJVBvI/5jGdV4EmjdGWv7QQdwnHjn923Eu+fY/R3 lvA1d6jC2COEgLcJlzytfEacG2TJyWQdk+c3TCa5edmqcb97u7dGYsZMS+Qp4wcs34WM MHlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bhJIYjW+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-110628-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110628-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e23-20020a1709061e9700b00a463c3828besi223760ejj.491.2024.03.21.13.10.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 13:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110628-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bhJIYjW+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-110628-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110628-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 79E7A1F22B7C for ; Thu, 21 Mar 2024 20:10:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53A55134723; Thu, 21 Mar 2024 20:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bhJIYjW+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EUWvwVjn" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 0AE1A847B; Thu, 21 Mar 2024 20:10:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711051821; cv=none; b=DHg7xw8w59cQTroteLPB3DORuJgmGAbUWN/CQtVL14jFUr+wLWYYraXJiSVw5zDOzqNwmsrY17WuCwuXpIn3Bl7ys5Yfp44hsJkvJIpaFdlmeXn4x3nN+0hhcRnGyPvgsPDy/FcxjalY7Ed1tnIk+kkxocuhweadXBxyISvB85M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711051821; c=relaxed/simple; bh=Lf3HfrYLrzAhvEjepEXMVanxjHeOHhN8pY5Shd4ocfk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=N0aMX9TlELRPASryQ4dPS7nRprh73t7sZ1ImyXRu6rbgJR/6MIDSbDPzDX6bta//Cj0lPZp/TTs3wLfH/bZ9EL+YRezjnTz+vJllQq1kLjtyEypIF2bnG96HXnR5DhURhdsJB09sSCZ6fICLw7XNt4CRBKhW0cjiJ56aFRtNeQ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bhJIYjW+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EUWvwVjn; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Thu, 21 Mar 2024 20:10:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1711051818; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Eb6K5oovm67eA2MqQVFdKN97AFgRU83d114MwSaVLHQ=; b=bhJIYjW+hQuiYq1kNFpPzOh+DGYTbtCHYKtwAR0uK5HLL3izxMsHUZQHiGwLoTNGFm1scN FMdGz2Xeo70tL1itbkdBIJxXCq3Dr901gN0gODoRKN2nBSjRQcGUwTLaZa+g4x+j4PkhMA S+urejKDdtLqXgGfcDkePcMTxjLsUGyRk8fye+r677ZXm3N3Y6//o4PKa4hpceU9zil/Iy Mo81wfNp5LY0Fd94jzvx9LZTcJiA7TdrbbNZKWDqHMZlVMm47u4howY6nDxKwo3tZfW0ZK WIUdmh1xm+mNoIaCAsJpPGR76V6Igy2ty4Md6zB6WN/2ZfRi5xzHPVlSej+KNA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1711051818; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Eb6K5oovm67eA2MqQVFdKN97AFgRU83d114MwSaVLHQ=; b=EUWvwVjntADpkN3/nPwS3YDaHjmkVbw8tqUrvdKtrqsssy0jv4lREyXI9MNBmHKnkZkLZm Tu3TF/S3Lv+ZdyBg== From: "tip-bot2 for Erick Archer" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/rapl: Prefer struct_size() over open coded arithmetic Cc: Erick Archer , Ingo Molnar , "Gustavo A. R. Silva" , Kees Cook , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240317164442.6729-1-erick.archer@gmx.com> References: <20240317164442.6729-1-erick.archer@gmx.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171105181695.10875.13663803002214703429.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the perf/core branch of tip: Commit-ID: dfbc411e0a5ea72fdd563b2c7d627e9d993d865c Gitweb: https://git.kernel.org/tip/dfbc411e0a5ea72fdd563b2c7d627e9d993d865c Author: Erick Archer AuthorDate: Sun, 17 Mar 2024 17:44:42 +01:00 Committer: Ingo Molnar CommitterDate: Thu, 21 Mar 2024 20:58:43 +01:00 perf/x86/rapl: Prefer struct_size() over open coded arithmetic This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments https://github.com/KSPP/linux/issues/160 As the "rapl_pmus" variable is a pointer to "struct rapl_pmus" and this structure ends in a flexible array: struct rapl_pmus { [...] struct rapl_pmu *pmus[] __counted_by(maxdie); }; the preferred way in the kernel is to use the struct_size() helper to do the arithmetic instead of the calculation "size + count * size" in the kzalloc() function. This way, the code is more readable and safer. Signed-off-by: Erick Archer Signed-off-by: Ingo Molnar Reviewed-by: Gustavo A. R. Silva Reviewed-by: Kees Cook Link: https://lore.kernel.org/r/20240317164442.6729-1-erick.archer@gmx.com --- arch/x86/events/rapl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index fb2b196..8ef08b5 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -675,10 +675,8 @@ static const struct attribute_group *rapl_attr_update[] = { static int __init init_rapl_pmus(void) { int maxdie = topology_max_packages() * topology_max_dies_per_package(); - size_t size; - size = sizeof(*rapl_pmus) + maxdie * sizeof(struct rapl_pmu *); - rapl_pmus = kzalloc(size, GFP_KERNEL); + rapl_pmus = kzalloc(struct_size(rapl_pmus, pmus, maxdie), GFP_KERNEL); if (!rapl_pmus) return -ENOMEM;