From patchwork Fri Feb 2 09:21:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp306482dyc; Fri, 2 Feb 2024 01:23:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IF45nQPazdPuNQrJGE3PEMC06N5N5qhMyTKxE4m3F/4fT+haekmW8FjTj05eEqxqbfR+rcG X-Received: by 2002:a17:906:7256:b0:a36:c8fa:45a8 with SMTP id n22-20020a170906725600b00a36c8fa45a8mr1146526ejk.24.1706865786502; Fri, 02 Feb 2024 01:23:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706865786; cv=pass; d=google.com; s=arc-20160816; b=UZs9noogCO77ZMjW6qa6djs7B3ImerZxdSGM8byGIDQiOCgnPVIYDfdzl9ZMT8m7B4 EEyRMK/mgH71JsRvxVb80KU9M3YCR8WFGvX3kwCCwKwFQtN+K00Zkuu597irGRZkJraU bvV6MmiZlHFSDmAC+uL0PQVgDtkt+1UsUq/YX9pSbwUFktVCn5G9UPcXu3aF8o5rcADB 1QBhJOzmKWKuzbgsGRlMcEGF5S/NtTc7gpmgO/X/v9NBslo5pFdQsKzS2LX1wkqqaup9 LgQRTroIlxdtO6ljfrnjSs5mGY1HqmI1B0QwQ0biaY1rY/tD1vK67R9HHsI4DBYR7gny 3sCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=l0m/Gjp7SDRbDsYlkSWeJqSGW2Lh0YbHKLO2XoJqFfE=; fh=48y86Xg40k57qOxCKGDDGvPzKXVfs0B2441n+8+VDjg=; b=wOMwIcsdHYUjB8QjLfOGpXKNtiXE8tkjUEmwOrBi3WwjhwAaOues6delvLZJJVM/lu FubmLrBDoXuQPvmhxbpbqY3YxUT2sl2DEKlJGzcu9pPyXNnzHPk5V/Jv2t2c0u+v4MHf gv09O6MNJwlxWKE9+FPoLZRKvkkoU7LPvLxlEhm8xz4eNhiy3spG8DMrSnCbeH/0BQZj i7zqM5jl7bzinVVPqoKGBZyrsXZ21R6ztq8+MFA4ykeLFMDy9pdt70QXdy3MsNUllfcy hDYmxPw8C340qHrGzalOg8teXX82VVY07qOu7dc3awVgjKoTR7cXnyiM/3BxDzPRZ/hy AHdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="e1vluO/7"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49554-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49554-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCW7hiKSvsDjkFbDxrTBFxJ0sROz3VZpWur5n74M7f0fD37e/R2mPC11W1Un+a0EDy40hCdHRsGNUFYUrW6F54xP4mX/+A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qt10-20020a170906ecea00b00a35cf874965si647420ejb.681.2024.02.02.01.23.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:23:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49554-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=@intel.com header.s=Intel header.b="e1vluO/7"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49554-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49554-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 0B0871F2494E for ; Fri, 2 Feb 2024 09:23:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32F9A7A700; Fri, 2 Feb 2024 09:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e1vluO/7" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 8FB5577F2F; Fri, 2 Feb 2024 09:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865720; cv=none; b=hpHF57H6uHFZn62sA2w0PiP7gDeILyvNwlsrkUBHNPy+UcKFwt/HvTeND1SJVNNrNpM6IrxbnUM1ii4rLax4DUDhi9Lg6e/u8LLfZDkyh4Ql6XTH104ii6pOKymQQCmAg54gsnYlzIWZq1uOGTi2gA8qoBXUOWfIoUV/loTycNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865720; c=relaxed/simple; bh=5xEYbhycCuhMZxcJFYEmbEaTkihqPSlxlZTL6ZsEoEQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gyqBQa+ndr7rJga0rzlUdlKySk20IphykEYHZZnMBgGvwMc2Z4BEbGBYmxzPJ2N0d8CaIIs7+Ed44Xs7IjnSglSsb0kmGfPsajS3WwY22RvvMKDcGZYSqs7efsq1wPBsrMOLDf2J+rlp3NkHVvMSi6gUfaciK/TM0lVVIBSKZHc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=e1vluO/7; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865719; x=1738401719; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5xEYbhycCuhMZxcJFYEmbEaTkihqPSlxlZTL6ZsEoEQ=; b=e1vluO/7IhLYa2JI6v+6uaUNaey8qJ2GBgCn/Nf4DGpzcA9b0fl296qa AQLVIgIodBmTDl4FWmlQRD+pIG0WpsKHlWm6oq5anpbDGDz11AhpAbMUf OuolOwo/ViI8TM/mFRKOJDj3uiAd/rHWFYyvx5qCZ639BFz0scjec3b5R FsiLwPaX2mA2xVoIEg2gulFSmCvAvTzgVJ9g+MHiN7JebFY5o55BzcyEh 3PKGFaTc1sguezIQSJ+0ja+XcjUXQO92MxYBktcAq60yOgtOewsrVYQjJ UgSP5UBP2Fh1YGPo5bZRL/eri88VUBMMqew2rHpkBu1L/Lj4Vr3NWjpVE A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483041" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483041" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:21:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639679" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:21:55 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 01/11] hwmon: (coretemp) Fix out-of-bounds memory access Date: Fri, 2 Feb 2024 17:21:34 +0800 Message-Id: <20240202092144.71180-2-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789778498807558069 X-GMAIL-MSGID: 1789778498807558069 Fix a bug that pdata->cpu_map[] is set before out-of-bounds check. The problem might be triggered on systems with more than 128 cores per package. Fixes: 7108b80a542b ("hwmon/coretemp: Handle large core ID value") Signed-off-by: Zhang Rui Cc: --- drivers/hwmon/coretemp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index ba82d1e79c13..e78c76919111 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -509,18 +509,14 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, if (pkg_flag) { attr_no = PKG_SYSFS_ATTR_NO; } else { - index = ida_alloc(&pdata->ida, GFP_KERNEL); + index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); if (index < 0) return index; + pdata->cpu_map[index] = topology_core_id(cpu); attr_no = index + BASE_SYSFS_ATTR_NO; } - if (attr_no > MAX_CORE_DATA - 1) { - err = -ERANGE; - goto ida_free; - } - tdata = init_temp_data(cpu, pkg_flag); if (!tdata) { err = -ENOMEM; From patchwork Fri Feb 2 09:21:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp308837dyc; Fri, 2 Feb 2024 01:29:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbhcnXuokPiVbVMdlBxfTwpivdqO5Kl1ZxS/ixydg4D/1kew82kZpo2bLFB4Y7LDCy+8eF X-Received: by 2002:a9d:6f10:0:b0:6dd:e021:51df with SMTP id n16-20020a9d6f10000000b006dde02151dfmr8550601otq.9.1706866197289; Fri, 02 Feb 2024 01:29:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706866197; cv=pass; d=google.com; s=arc-20160816; b=jPDvLRT2pS/QGnfre3uVUtFTLpRt4uo8Q/D6AW5mNl+XAXmQ4XvLi8lwv2ZGKGQBlY M+T8w79x4kPPgDpTFYkuERjKFjUE298/JXWOX01jYX2i2VuGgpPTyyR2HU4ZQlfwX0qO fIMiLUrYgkurGtM4kSuEZj9nwYRTkn2HaY36KHhp9EvL85QtAgxnBdZRGSZLprgjJZwM Ak+McgzaCi5Ps7I1QjJRHuebQiKq+qPqVkaTB92g1rlTk/OSq4VN41pW1fMg+Gd3G1YA OWlWaM/zhCuhqKnsHAG6BeUmCK0Kvf0VNSSZCOl0efRVk1gQWpgaj13ZGpelU1TuEMf/ M4qQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dcJg5NWm1R1ds696M4rPB8QcaLmIMqu010IDhd9XE/o=; fh=GJ+1KutBwEYMto4S8LheEbrLZfUhHcZNlC6UZwdKEAo=; b=J/MPAH7vgnS3k4IVcOgQo2zrZ4CnEGzLnnHswI1rLlr3leHb7ef0SLBG1cj6HQSrKS yK1Gv8pq7kDry+IEb4jLPsgtpr3oGmpP5PSBel+tJEBSlDCoCJqkqUmWDZaJ7v0vylRr ws/wlDtaQxJerok1oIzR5i+fralm5Yrr/yV+Ustx8cfK8nblZ7cSbXPQRTIB2bmrgvOW ET2qsHqjYXHC6Q+CeR34n2lN2XdL2EYO06w8WNea5EY6GOquF74yeifC8lIQrT424uOP GR5c2OJB5x8KQa6GR7aSc7VOKGyvNrd2MLUex4TEhMx42W5i3q/Vnq4idmBb99IhTp9X RtGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bN+j0fVq; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49555-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49555-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVassUGi2cnuVrMCFvv+yqcozVWNyRuP4RdEEgQ5hEqQ5142Wd2xd8SnQutGQwbvb+qMYdhScHaMdMYVeOEoX6F1IEtvw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c16-20020a634e10000000b005cde3cc04c5si1286778pgb.821.2024.02.02.01.29.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:29:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49555-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bN+j0fVq; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49555-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49555-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2D830296F91 for ; Fri, 2 Feb 2024 09:23:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73ED17A727; Fri, 2 Feb 2024 09:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bN+j0fVq" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 55E717992E; Fri, 2 Feb 2024 09:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865723; cv=none; b=SZ2SR74YsWbN5GYQtqPxic3Sfbf6XOFX9MkN3ZouoRABcQ0jdfs5P4qES/10vzyNm9uNTuouncy5LpQC9Ih/PyRgXkVxL5InklOWY9E7jV+Guyzg1986dD31KlvZ28ijJTdZPuSR2iQXGIc7i+SFcWhFnDc1cnKaviH+sJficQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865723; c=relaxed/simple; bh=75bHn3ApwS9Yr/xJ5rTI2RtddH16T0sqfaVRSuFSsD0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Uif34HsLzteo7azbuH4JZ9ycVL3smOs201wqNUV62mXhpnmaBBksMlvITWe5uNGTA/3tEfBmNA+3D4QkqWK7Sba/BAQx7PFau98wRFBs1zQrz1UO2CDcQ8izjF5ypJEL0n1Mo1DumkDmOoXp4xCpw4TavFVCqfEDQtd4xJ4b+rM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bN+j0fVq; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865722; x=1738401722; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=75bHn3ApwS9Yr/xJ5rTI2RtddH16T0sqfaVRSuFSsD0=; b=bN+j0fVqbrKnxBxaN+7WZIcTCIlJsFaFr4FvoxJN00M2tkxyZAa1CtVy MhE8xBTpI1gPjPDMQBtvVaYNi52kvUs1g4VAWT+HhL7qSoutwMxmFldT3 8CSNb9buYkmUk5Yz2Keix6YI12XNI98kq7cqUPk/CtUnEiMOMTKyi7Gqj uYNKF+gP/zatWpNBG4JD6ubZEN++0cmOGEuSig7yXVMYmaQ3k6X2ut3FF TR0RUBrC2/GCnq7sxok2pDjdf+wf8/0uV1BO9y/PXVco6tOHcVHINTCuy eagnVdDvfazN8HUM6noT++/ZrKABPtP/3LOGeSDtgHASywGSs2h6NsP68 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483048" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483048" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639688" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:21:58 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 02/11] hwmon: (coretemp) Fix bogus core_id to attr name mapping Date: Fri, 2 Feb 2024 17:21:35 +0800 Message-Id: <20240202092144.71180-3-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789778929476147765 X-GMAIL-MSGID: 1789778929476147765 Before commit 7108b80a542b ("hwmon/coretemp: Handle large core ID value"), there is a fixed mapping between 1. cpu_core_id 2. the index in pdata->core_data[] array 3. the sysfs attr name, aka "tempX_" The later two always equal cpu_core_id + 2. After the commit, pdata->core_data[] index is got from ida so that it can handle sparse core ids and support more cores within a package. However, the commit erroneously maps the sysfs attr name to pdata->core_data[] index instead of cpu_core_id + 2. As a result, the code is not aligned with the comments, and brings user visible changes in hwmon sysfs on systems with sparse core id. For example, before commit 7108b80a542b ("hwmon/coretemp: Handle large core ID value"), /sys/class/hwmon/hwmon2/temp2_label:Core 0 /sys/class/hwmon/hwmon2/temp3_label:Core 1 /sys/class/hwmon/hwmon2/temp4_label:Core 2 /sys/class/hwmon/hwmon2/temp5_label:Core 3 /sys/class/hwmon/hwmon2/temp6_label:Core 4 /sys/class/hwmon/hwmon3/temp10_label:Core 8 /sys/class/hwmon/hwmon3/temp11_label:Core 9 after commit, /sys/class/hwmon/hwmon2/temp2_label:Core 0 /sys/class/hwmon/hwmon2/temp3_label:Core 1 /sys/class/hwmon/hwmon2/temp4_label:Core 2 /sys/class/hwmon/hwmon2/temp5_label:Core 3 /sys/class/hwmon/hwmon2/temp6_label:Core 4 /sys/class/hwmon/hwmon2/temp7_label:Core 8 /sys/class/hwmon/hwmon2/temp8_label:Core 9 Restore the previous behavior and rework the code, comments and variable names to avoid future confusions. Fixes: 7108b80a542b ("hwmon/coretemp: Handle large core ID value") Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index e78c76919111..95f4c0b00b2d 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -419,7 +419,7 @@ static ssize_t show_temp(struct device *dev, } static int create_core_attrs(struct temp_data *tdata, struct device *dev, - int attr_no) + int index) { int i; static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev, @@ -431,13 +431,20 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev, }; for (i = 0; i < tdata->attr_size; i++) { + /* + * We map the attr number to core id of the CPU + * The attr number is always core id + 2 + * The Pkgtemp will always show up as temp1_*, if available + */ + int attr_no = tdata->is_pkg_data ? 1 : tdata->cpu_core_id + 2; + snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, "temp%d_%s", attr_no, suffixes[i]); sysfs_attr_init(&tdata->sd_attrs[i].dev_attr.attr); tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i]; tdata->sd_attrs[i].dev_attr.attr.mode = 0444; tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; - tdata->sd_attrs[i].index = attr_no; + tdata->sd_attrs[i].index = index; tdata->attrs[i] = &tdata->sd_attrs[i].dev_attr.attr; } tdata->attr_group.attrs = tdata->attrs; @@ -495,26 +502,25 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, struct platform_data *pdata = platform_get_drvdata(pdev); struct cpuinfo_x86 *c = &cpu_data(cpu); u32 eax, edx; - int err, index, attr_no; + int err, index; if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) return 0; /* - * Find attr number for sysfs: - * We map the attr number to core id of the CPU - * The attr number is always core id + 2 - * The Pkgtemp will always show up as temp1_*, if available + * Get the index of tdata in pdata->core_data[] + * tdata for package: pdata->core_data[1] + * tdata for core: pdata->core_data[2] .. pdata->core_data[NUM_REAL_CORES + 1] */ if (pkg_flag) { - attr_no = PKG_SYSFS_ATTR_NO; + index = PKG_SYSFS_ATTR_NO; } else { index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); if (index < 0) return index; pdata->cpu_map[index] = topology_core_id(cpu); - attr_no = index + BASE_SYSFS_ATTR_NO; + index += BASE_SYSFS_ATTR_NO; } tdata = init_temp_data(cpu, pkg_flag); @@ -540,20 +546,20 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, if (get_ttarget(tdata, &pdev->dev) >= 0) tdata->attr_size++; - pdata->core_data[attr_no] = tdata; + pdata->core_data[index] = tdata; /* Create sysfs interfaces */ - err = create_core_attrs(tdata, pdata->hwmon_dev, attr_no); + err = create_core_attrs(tdata, pdata->hwmon_dev, index); if (err) goto exit_free; return 0; exit_free: - pdata->core_data[attr_no] = NULL; + pdata->core_data[index] = NULL; kfree(tdata); ida_free: if (!pkg_flag) - ida_free(&pdata->ida, index); + ida_free(&pdata->ida, index - BASE_SYSFS_ATTR_NO); return err; } From patchwork Fri Feb 2 09:21:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp306663dyc; Fri, 2 Feb 2024 01:23:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEk3lx0Hj6N9JdUPJBPSIDj1MeUm2kb9d4hPrY60nsAZfqj43LMBG3lFz8WurzRKYB4bRkD X-Received: by 2002:a05:6830:1e4a:b0:6e1:d8c:8f8b with SMTP id e10-20020a0568301e4a00b006e10d8c8f8bmr7699202otj.37.1706865816963; Fri, 02 Feb 2024 01:23:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706865816; cv=pass; d=google.com; s=arc-20160816; b=OX2JlLoP3N0vAF1CXaFStXLF9bJa54liFL5mNPjGod0mdNDKVMQS7Ptn2L1HpHBNa4 ubOLBI0m6u5uYTk+XHnB5/OolEopDBL0dX6sF8UZDQXL5uu3+z81x2/E9fNfg5bx1D/6 YIZ4THoBvVSvCjO1fBdqBTugaDQkGBjV+uA+ZkZEiVuMZTEO/JfWgZqVQq/JSejQKLb5 mkJF26Hl4s8xQw30d2+FyEYTEo5vRmK8t8bWAwduoAXRCZX59uIIvIV08g2KRuZiPoOR DqQH66eySYsPfenZMHAOHmjPQoANldgtvW3x9rwYSppJhtzLn045lHOPobw2cSKNlbtj TUsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xzz1D6aycc3/F5lhIVELQCna2gpoqM2hz8dC2nkYuQs=; fh=HrabqhZWpM0QFR7xeXyQZNhhuE94wUSJC7TVKFx+Aew=; b=VtHq6iRrvzdVMAsuAqvcDKx5e8WPbvD89MKljMsh6nkDTV9m/VSBzazKpkMBnIeEFa lhP5FLKQ+In+XbqadkW1kg/BnvMmouDfKwZr118JsClb8WtTPAYGol9Dg4GAXvY6donF aOUYpGDZmCvJJXZR0+120BbQi2VRCv6AarhYqUynjkyD3YRdtI7HP3S8OMh/hJhUeuCP XpiMapVDtR4/sqVdzQY/97SxQdtI6up0Rzm0s3w0/jbzBndEVl9FNQzT8MWNj9J7vn6M UGyF5HYq3Buo+xXWGvJjOPo7gu4W0QRR4ZIYCKfceOjcSskE6aW2Z1j/zCyAx5T/tbgr +CAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lm4tYbmZ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49556-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49556-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVYjrIR/TGjwFRWkgQkKroSsQD+J4VB8pZ9ol3qH6JOKBB6Ywpit5qnKGQSNt5RA+lKGAIEnbz9SHUpL9dVuhuptV12gA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o18-20020a05622a139200b0042a8c127309si1614040qtk.187.2024.02.02.01.23.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:23:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49556-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lm4tYbmZ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49556-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49556-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 BA3761C27089 for ; Fri, 2 Feb 2024 09:23:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03FAF7C086; Fri, 2 Feb 2024 09:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lm4tYbmZ" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 BF2187A70C; Fri, 2 Feb 2024 09:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865725; cv=none; b=jrl7xo1BscrLBuSK97PYlLfFS7fvAmfrxnIGGjNNAdEOguo3of0yykUHyVyGMtlpoCaP9iLwDxF39w6/OyGGB/dB4WaJPL6bND27I0SzVWGjhi8hyR0++J7LSzI5+zYN/TdD0Ne27o/IoeWnD0s2JMUa6wdfHfRN5GEBAGC3Q6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865725; c=relaxed/simple; bh=M30zJ8jiKBRt9vcEZBXNCa9ddRJLNILlVAiBhO8gJps=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hZD9a+dIgIRfwoBOXNxTslZHRH66YZtR5PViGq9k2M3QlXy6jC8rOBfef5ad7+FlfTWFnHLq1yqjDLVCmQ9ORMW2VL5buR6yCyTJVRyVEKpoT1LQC82s1OIOC8vvY5N7Hft9jh2J4uJT9KSXSYULC8RdMYvTBBtBtqFkJngYrzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lm4tYbmZ; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865724; x=1738401724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M30zJ8jiKBRt9vcEZBXNCa9ddRJLNILlVAiBhO8gJps=; b=lm4tYbmZn+CmQ+z5JJ55txXOqZl070JcoR6tHWGKpiluY8NuUEv9GmCC DTZZ/snkFlD/iN7mUchJhdw5DF/D+SMNg0q5r1E2b4S1E85hXTnEjVYiu B/HZNb07Sxvm01dtcTo/w4dsJume52T0ml9iJz7WHOJHcVFaQ458EpKDz br54ADKq5dBywiY9VcDVfrlhIFQdAYqHbiGDaW3P/IL6uSY3zs0lwykma SSBF0cn62Nn+xcba6Va9egf1dX04uJlM042mGTAnHBANKgOvtSjwg65qA GdySmDdA643DQaGJqhucjafbVaFjyvXJ7LgHjjVpjHHSWM/NlTpfIraJ3 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483053" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483053" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639703" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:01 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 03/11] hwmon: (coretemp) Enlarge per package core count limit Date: Fri, 2 Feb 2024 17:21:36 +0800 Message-Id: <20240202092144.71180-4-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789778530820567510 X-GMAIL-MSGID: 1789778530820567510 Currently, coretemp driver supports only 128 cores per package. This loses some core temperature information on systems that have more than 128 cores per package. [ 58.685033] coretemp coretemp.0: Adding Core 128 failed [ 58.692009] coretemp coretemp.0: Adding Core 129 failed ... Enlarge the limitation to 512 because there are platforms with more than 256 cores per package. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 95f4c0b00b2d..b8fc8d1ef20d 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -41,7 +41,7 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); #define PKG_SYSFS_ATTR_NO 1 /* Sysfs attribute for package temp */ #define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ -#define NUM_REAL_CORES 128 /* Number of Real cores per cpu */ +#define NUM_REAL_CORES 512 /* Number of Real cores per cpu */ #define CORETEMP_NAME_LENGTH 28 /* String Length of attrs */ #define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */ #define TOTAL_ATTRS (MAX_CORE_ATTRS + 1) From patchwork Fri Feb 2 09:21:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp306736dyc; Fri, 2 Feb 2024 01:23:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfYd/4mpXCYGUXb8UzfcdJwkEBovLK6E9AtjrnRGmEKDZJ4XYFyjTb29g7tl1GunQAZKbn X-Received: by 2002:a50:c05b:0:b0:55e:eb81:2db0 with SMTP id u27-20020a50c05b000000b0055eeb812db0mr5281476edd.38.1706865830580; Fri, 02 Feb 2024 01:23:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706865830; cv=pass; d=google.com; s=arc-20160816; b=Xt1ieP2oTIbINz0K7MWu+1iwL87JeHlWSewOfKakWzcPGXV3FKwinh8CuLi75MTLm2 6XKNKJYcGWSp8M73Ldo3PTiHlM9zH740yzZ5wcMiT59zNrk3sPHdcYzn1Bd5GEu6y3h+ QNPlM3oFHRdmqNWdAjpz4TsI8q5kCqmkpF6+mDyAk5yinYA27Zb3G48putqg7akXbj5C cw2A+mip6VhNlmKp3dm5HuGrsefy1hujR4ftDgh+STAwBWwxC6hEiqjTV7xYftNzZIMY 0m+7ZPxmCJ0g93vagWYsibC6k7UwwpaUmafGHfFKFFlWmC+hnXQD9V8ZvYjJg7Hl9S80 Dfkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GMEenTGpD64OsWtlAWpN6VGOtAvUqEfJGaeDX3OQ7oE=; fh=giELeV3ljm8w6g0Y6W7+GrXcstG9g9mpL2SPNujO3c0=; b=JltnjzKv1wILz9Vdlf6QfXQatpO462i+Ce1fBlhPJHy28xg7s7i/RTZgJTSIgjH6be 0VxCk+cRBMWOZOdzAmdHnwPQfJ3VoeGyp799GmUpYWxdw9rApa8rk5wapRWUrPdgGvmb AszcxsEWivlsTVAxHmbCQP8AbLazKPNYd9vwRc0GRga2ahgK5+LrHlD3003i/N1THTrq /8Xf90/TuAewqpWr/6vyMAu1NEpQRHNvmcNttJ5Q7wMCMKF2fnEbW29CAKw3wZl7NjcU 8EIBHrtNnjmcBUQGlR3ndtHl2cv4gIaTFZwXwGlfdHD9Dj7jzXKNO6Tmt94GhXwIZz0C 5mFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eqXzvyTy; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49557-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49557-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCX/8wgN9ElAXlED7WxhCxeWrl0vjH8zNSWvtolrUiwQkfq3E5vluWDtmzEf9CGISNYoizQTyhp70s+BwLFBX00mXn3wFQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n19-20020aa7d053000000b0055fe2ee6bafsi652565edo.36.2024.02.02.01.23.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:23:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49557-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=@intel.com header.s=Intel header.b=eqXzvyTy; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49557-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49557-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 322241F26BDA for ; Fri, 2 Feb 2024 09:23:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 541F47A73E; Fri, 2 Feb 2024 09:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eqXzvyTy" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 302637A729; Fri, 2 Feb 2024 09:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865727; cv=none; b=RGcU1HNKEt1sNeCJ5uyGzGIfxsKajdbEtWC1zysIH8VyWNedYaX2yCp8iENXlZmdDheiR752lJ2F32uAH0sVfJdvTF+TzQyt3Cq/RyUG29zRV+Aa6z7UUVzxS59V4ytv/TPJy/QlJyVl73fzIDnaWkZ7PQ8f9vmNeoZcbjiHjtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865727; c=relaxed/simple; bh=cOvTivQwCKSNAmVU6sv7hOu2Ay14QYpymwDJPYGTOZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KgHpIw5CPI+sgw3GToGa7V8MtiwLvopV06CkmZKWKpN01MkpDKlFprvOXOvRCfYRYL1Cg3nnZ+Z7M3YegBeG+UCsPsh0OkcUzebTQyRv9ndBmTJN3VjOowuMwBd/i9iL5EFXfZ8E6dZJhxUeUOvOGkk7aMB0Sm0lx/dVXJQgFbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=eqXzvyTy; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865727; x=1738401727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cOvTivQwCKSNAmVU6sv7hOu2Ay14QYpymwDJPYGTOZY=; b=eqXzvyTyzhJgRAgMZsRBTzjzsWgxKEiNNKUkux3HPMQ72b7XC6kCpuiS NSfiOWKl7MWSAobrChTsB3PVgm4kd/D6AxnT6zUqxEDKZ5iM4ToR8AODg S5sM2YIZwyouDv79q/51Qbd+dsDFILABMqTU/aDrS3PIoIsb/LKr6qnTM 4RrpjmL07spWmj3Awck22gQgJgzYpddSKHy5TLp1q2JMNpNPCmg3Z6n8a 3vkiDiKT67yvgF1zs6/zHG2foAFNwEMYyGjtdWrsbCm0z435/93efsXo9 nxbePgu1lg7+ckTBdkwlfn6KRLUzbWukr3COsRF/2TUlSedrb7GHSIKwR Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483056" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483056" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639710" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:03 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 04/11] hwmon: (coretemp) Introduce enum for attr index Date: Fri, 2 Feb 2024 17:21:37 +0800 Message-Id: <20240202092144.71180-5-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789778545131450372 X-GMAIL-MSGID: 1789778545131450372 Introduce enum coretemp_attr_index to better describe the index of each sensor attribute. No functional change. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index b8fc8d1ef20d..32f99cf6308b 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -43,10 +43,18 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); #define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ #define NUM_REAL_CORES 512 /* Number of Real cores per cpu */ #define CORETEMP_NAME_LENGTH 28 /* String Length of attrs */ -#define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */ -#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1) #define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) +enum coretemp_attr_index { + ATTR_LABEL, + ATTR_CRIT_ALARM, + ATTR_TEMP, + ATTR_TJMAX, + ATTR_TTARGET, + MAX_CORE_ATTRS = ATTR_TJMAX + 1, /* Maximum no of basic attrs */ + TOTAL_ATTRS = ATTR_TTARGET + 1 /* Maximum no of possible attrs */ +}; + #ifdef CONFIG_SMP #define for_each_sibling(i, cpu) \ for_each_cpu(i, topology_sibling_cpumask(cpu)) From patchwork Fri Feb 2 09:21:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp306822dyc; Fri, 2 Feb 2024 01:24:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhSG/dxLTJ3mQMZU0xOKUq/9hLvMXrFS7zAsCg5DwCSuPfxPvaJ/PS6PAwOtCOckSqgz+I X-Received: by 2002:a05:6214:29eb:b0:68c:5583:a86f with SMTP id jv11-20020a05621429eb00b0068c5583a86fmr9966496qvb.6.1706865845929; Fri, 02 Feb 2024 01:24:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706865845; cv=pass; d=google.com; s=arc-20160816; b=CfiPEDOtIHZu2z+CvL0DzqeHdNJSWeu1cv2lKw1eEWc1O0QqD5qUHTsYLe7Y/paGDb zST0FGmk9tdd0Zzethde9/fF7uBrRdissaIigo4iuVRgWELk/KYj/JNHEJSScP5HuJhz QpajnX/+FWAdIbk+fVUR4EWhxVnCizv7Mo5wRpnrdqbeTEezcq4/JiCxASPgCPpCxJEI aL/RDIEdePGDt9aJeMiUUrjS3oYtXTlyETqXjy115HV43Lz830HOIVL4971/Rb8PnQKv ELn6i9+TIw9L4m1ekdbKwcZr1+VashWqvvuq4iCZXNJHotskXDWqab1Yl11M6TOb3Ijo PAnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=V5Mpb33atoiUHYK1kKD7cpn9KS3IPPA9uYq83EMpct4=; fh=pq0mvt/v9BIHX7Pi4a41wPHOpFfWBUlh65SUNr0KfxY=; b=MSTjQ6MTkyCIZ4zXe2ONfPZnnqBioNuGtKIGbRD2bnwYb6zC+1tqQPsdt//wy2PWuC H0O+mnUP4bNKWDMl2INnDN19zqHygc2QRwjHMtoqsdYzAWchfz4crAGoNEPe0IMCm8kr 2RziKHHZASNTE6HO34goS1AzC73sBwLTy6LOsXY0GBIY10j9LxHUsQyb189vhq9Zd8Qm NffTza9CIbU/Abz6PRIyAUJUazxVgjzVk6vNGhpUmI7IeT/DFIrVM/JNfsocRcHM3vMZ qfSt6zMiW/69hd15WAd89NJ+Jj/Y7xJVvZSGrQ2C8TuSAWRb5XMkn58lvqYWao4xyXEM jOFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HgRJHwQm; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49558-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49558-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCW9JrrPV60kVEeahW+b+niAFG9IwuVY4ZAde6Dm70J2HxPbctC1o1IKMd5JSS0TBWDjFZM2a9zBvnaW/hoBT8jf4RPgsQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e22-20020a05620a12d600b007840856f4b7si1542015qkl.5.2024.02.02.01.24.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:24:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49558-ouuuleilei=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=@intel.com header.s=Intel header.b=HgRJHwQm; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49558-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49558-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 B12C41C269D4 for ; Fri, 2 Feb 2024 09:24:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C6D47C6C1; Fri, 2 Feb 2024 09:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HgRJHwQm" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 E1DD87C096; Fri, 2 Feb 2024 09:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865730; cv=none; b=RajmWtHPOub5XOxi2PxTAeKM5J84Y6Zc3FeMwXNr1pafN/1qf/QXjp2BI5sCMJsCAmVIM5FMer4Q7O4yXu/L+dwpq+YwDjxU7Q8PQM53zE2DNAYd/kK1gemZzX1ffiEJjdtjLV/ezezafGCtf4ZoOD0gdvvAP2hpfQ6m9Nq/6iM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865730; c=relaxed/simple; bh=RleCYu67aFEcNUbHUt0P9qINaHPy/r38vowQxOiPOe0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=re01RmuSCd8Q3e2//osAU0J4S1eV61PXoa1STJ0u5G2CwEPM3kvQT5vctFjk8gboj/Ma3Ode+HAR0spO8OFUmqtWGJFHmRxBpgvK8jc1e//9mxYXzCqCHNYiuZWTXSGf1Ksm0l9DNZ9CsHKsGPXjjf5qfIjOeAuyhxGt3fkODgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HgRJHwQm; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865729; x=1738401729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RleCYu67aFEcNUbHUt0P9qINaHPy/r38vowQxOiPOe0=; b=HgRJHwQm0PPZh9FENVP8E9mo8D9azNns9TwDlVdf961BsO+ep8FlH1Gb MT8n8//l/oJkMAL3HQ2u4QtysEahJ1DZjkZsZlRQf/GcbUPQxAs3TXmyl mTYqOq2t7rcT1xg7dtD8A8YMpk/Xg8vHi1in3xeL6d7PzxebHMwJY4muC 6Q/OHuH0lzBDuyjRXmsyJyomA8GZugnRPnnnTCfQjYDlbc9AjKXrwlhg8 QRW9dWK4JD0unXpS72+ClCEbCUj4u7/ANLtVSnAEhgntFTdYv6cTB0dk/ YsiYVijSpYs8H/nZtrrETo+JrsHs8Hh8OpoDRNlI1YuVsqwqBEGAk8tJJ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483063" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483063" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639718" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:06 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 05/11] hwmon: (coretemp) Remove unnecessary dependency of array index Date: Fri, 2 Feb 2024 17:21:38 +0800 Message-Id: <20240202092144.71180-6-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789778561303569239 X-GMAIL-MSGID: 1789778561303569239 When sensor_device_attribute pointer is available, use container_of() to get the temp_data address. This removes the unnecessary dependency of cached index in pdata->core_data[]. No functional change. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 32f99cf6308b..9a7bfc046c72 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -342,7 +342,7 @@ static ssize_t show_label(struct device *dev, { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_LABEL]); if (tdata->is_pkg_data) return sprintf(buf, "Package id %u\n", pdata->pkg_id); @@ -355,8 +355,7 @@ static ssize_t show_crit_alarm(struct device *dev, { u32 eax, edx; struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_CRIT_ALARM]); mutex_lock(&tdata->update_lock); rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); @@ -369,8 +368,7 @@ static ssize_t show_tjmax(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TJMAX]); int tjmax; mutex_lock(&tdata->update_lock); @@ -384,8 +382,7 @@ static ssize_t show_ttarget(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TTARGET]); int ttarget; mutex_lock(&tdata->update_lock); @@ -402,8 +399,7 @@ static ssize_t show_temp(struct device *dev, { u32 eax, edx; struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TEMP]); int tjmax; mutex_lock(&tdata->update_lock); @@ -426,8 +422,7 @@ static ssize_t show_temp(struct device *dev, return sprintf(buf, "%d\n", tdata->temp); } -static int create_core_attrs(struct temp_data *tdata, struct device *dev, - int index) +static int create_core_attrs(struct temp_data *tdata, struct device *dev) { int i; static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev, @@ -452,7 +447,6 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev, tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i]; tdata->sd_attrs[i].dev_attr.attr.mode = 0444; tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; - tdata->sd_attrs[i].index = index; tdata->attrs[i] = &tdata->sd_attrs[i].dev_attr.attr; } tdata->attr_group.attrs = tdata->attrs; @@ -557,7 +551,7 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, pdata->core_data[index] = tdata; /* Create sysfs interfaces */ - err = create_core_attrs(tdata, pdata->hwmon_dev, index); + err = create_core_attrs(tdata, pdata->hwmon_dev); if (err) goto exit_free; From patchwork Fri Feb 2 09:21:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp320073dyc; Fri, 2 Feb 2024 02:00:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFt7q+lK6Ysweov3/Ol/ic3bEgVJuXoWIcnjeCxis1UTPvs+OC3j/j8IrjZX323QT/nsrxn X-Received: by 2002:aa7:8884:0:b0:6dd:a107:f862 with SMTP id z4-20020aa78884000000b006dda107f862mr8522274pfe.31.1706868042018; Fri, 02 Feb 2024 02:00:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706868042; cv=pass; d=google.com; s=arc-20160816; b=ebCIP5Ptx8/Spx16qLqoOA59qUpYUvZtBmJSsu+ilYB+hXeNc/zUuWJoREg1plivln DHLIkQNsslYh9flRzIQxWji0cNQ3UeRE3W0q6cGYQDTLE3Neii+7S0UiSdep7buplOsY Y3PXmkHanRNwMKGmON400C6oAJ7VLzzNWfXm9WBt9iPwETWr4HEa2QJh10PjZ7EH8nOf ozZtAv+1g2QBo27aCt+/jF7e0tzuAGP39U4QcURZoebr0G+HSgz1zDJGDSSHSI5TgQFD Sw5xwBgrBImlKhdyH9t58SM4sTrRrmzyF4HLmB1WztP7jp+ZoGAeOP5sjmmVyzvGXALZ 9DIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+krwLZG5BPJdekHNhN7zycPpRE49BFiR7rFnpLBV+3U=; fh=5nTYlaqCZ0RxAdZhkuRw9F0iFpRWvZt2GSVrpdwZkmg=; b=y1mxYqQntwl6rlDDm7Gw7sxjyT2YI94UH6xFp7oX8dHk6QclKqUVfKAAAHlt4MPcaH CeQCRhNoJsVG0tq0MbjYOL3Hu1El1nShbgHgS8wzB+hAbjdpI4JutKPD14jgTU8PPnX0 81zYinJb4etTZeJ/hXFoZSIh1YRVvCWQsslq6wVmZ07sKCvtXDska8h3zKwJ/2Wguf/B otakpkcl6iTjT5K9OhBtTgQgVxTyRIQmJXWevgHrNxu57mDuUYmkCHFb3TtLj0srrSzY z1P6lw2DupCM+Phluk4cedDDh4SeXgHSA8goKRKQ9P/f/HFB7NLb5wtAIY3XwdhRe4Jn +gcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dzgEi2K7; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49559-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49559-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWIvE1HuOq1TsRPZH0lZT5Yuqd6ebbBPiiiydI4d7UhREnqJAb2Kq5Jn+xFAYN9JsAApK4ASFfSqEjSzlgWNcbQE/UWuw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id lo4-20020a056a003d0400b006ddced9e9dfsi1327503pfb.51.2024.02.02.02.00.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 02:00:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49559-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dzgEi2K7; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49559-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49559-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A9D7AB2E17E for ; Fri, 2 Feb 2024 09:24:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07D5A7CF23; Fri, 2 Feb 2024 09:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dzgEi2K7" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 7432D7C095; Fri, 2 Feb 2024 09:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865733; cv=none; b=LA4E6+vuoPTtQbYaOZD5z647BUEzlL/4ykwh65N8ln5Q5qMytQtBL994P4Pij+DBTv/mwCBnWRHy+tXxo1eRZLgWf7iYIKKXJXT2ffcoMvwQKGQ2oMoexuXAgOsN+IJEdyU5vfMq/iNXLDsyt9+/WXriCQ2amwQkw6hLCsW473g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865733; c=relaxed/simple; bh=4lJwtT7W+z56piJEq1ajtdOi8X1weo4iQkqGFadRV9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dkuff1g/kreI1oBsZJeEmvbKt177xmU2hd5ipmYw5UgKn1gpKRcO6Nhg23AYVt4rz129/OPCK9okWmA0uoh7fg9Lr+JF2C0zq3M4L7ZOctjddvuCoHZbe0sMdukFkgEOzYreCCu7n2A66oGA3GxlXtD3M2BQRRFXtjRwTIqen1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dzgEi2K7; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865732; x=1738401732; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4lJwtT7W+z56piJEq1ajtdOi8X1weo4iQkqGFadRV9Y=; b=dzgEi2K7+w8cvhDM8O4XH79L9vy2yxr6dSRIgYjqE9rwD7XTPHcz47Lx eQiYC96gOteeWrTWoC/TqjZ9qebTvx4JE/qrDkCqzimeDox8dDjNIszGN N6qnNcTnYlL/emmxcnFtqr59KqC2o8pKmJ2sgnQISuCyt1SdpN0b313pZ V4EvLrTo6mIvmmlE/+MIeZhdSd0TdIQ6Z4CeJF5OGHjSe+4+ouv2LHcRk PTJo8IQRjs+3XgjKFTw2aevkDAty/4yBjgmVjw5Bk16e2ftt+90S/yFmr oSgxPM4YXvzRoDXDKLUTRhJHwMc9GGSEjQBzmb7ylLiqF/vGhvs+8LeEY Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483068" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483068" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639731" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:09 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 06/11] hwmon: (coretemp) Replace sensor_device_attribute with device_attribute Date: Fri, 2 Feb 2024 17:21:39 +0800 Message-Id: <20240202092144.71180-7-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789780863968285619 X-GMAIL-MSGID: 1789780863968285619 Replace sensor_device_attribute with device_attribute because sensor_device_attribute->index is no longer used. No functional change. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 9a7bfc046c72..cdd1e069d5c1 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -85,7 +85,7 @@ struct temp_data { u32 status_reg; int attr_size; bool is_pkg_data; - struct sensor_device_attribute sd_attrs[TOTAL_ATTRS]; + struct device_attribute sd_attrs[TOTAL_ATTRS]; char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH]; struct attribute *attrs[TOTAL_ATTRS + 1]; struct attribute_group attr_group; @@ -340,9 +340,8 @@ static struct platform_device **zone_devices; static ssize_t show_label(struct device *dev, struct device_attribute *devattr, char *buf) { - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_LABEL]); + struct temp_data *tdata = container_of(devattr, struct temp_data, sd_attrs[ATTR_LABEL]); if (tdata->is_pkg_data) return sprintf(buf, "Package id %u\n", pdata->pkg_id); @@ -354,8 +353,8 @@ static ssize_t show_crit_alarm(struct device *dev, struct device_attribute *devattr, char *buf) { u32 eax, edx; - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_CRIT_ALARM]); + struct temp_data *tdata = container_of(devattr, struct temp_data, + sd_attrs[ATTR_CRIT_ALARM]); mutex_lock(&tdata->update_lock); rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); @@ -367,8 +366,7 @@ static ssize_t show_crit_alarm(struct device *dev, static ssize_t show_tjmax(struct device *dev, struct device_attribute *devattr, char *buf) { - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TJMAX]); + struct temp_data *tdata = container_of(devattr, struct temp_data, sd_attrs[ATTR_TJMAX]); int tjmax; mutex_lock(&tdata->update_lock); @@ -381,8 +379,7 @@ static ssize_t show_tjmax(struct device *dev, static ssize_t show_ttarget(struct device *dev, struct device_attribute *devattr, char *buf) { - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TTARGET]); + struct temp_data *tdata = container_of(devattr, struct temp_data, sd_attrs[ATTR_TTARGET]); int ttarget; mutex_lock(&tdata->update_lock); @@ -398,8 +395,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, char *buf) { u32 eax, edx; - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TEMP]); + struct temp_data *tdata = container_of(devattr, struct temp_data, sd_attrs[ATTR_TEMP]); int tjmax; mutex_lock(&tdata->update_lock); @@ -443,11 +439,11 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev) snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, "temp%d_%s", attr_no, suffixes[i]); - sysfs_attr_init(&tdata->sd_attrs[i].dev_attr.attr); - tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i]; - tdata->sd_attrs[i].dev_attr.attr.mode = 0444; - tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; - tdata->attrs[i] = &tdata->sd_attrs[i].dev_attr.attr; + sysfs_attr_init(&tdata->sd_attrs[i].attr); + tdata->sd_attrs[i].attr.name = tdata->attr_name[i]; + tdata->sd_attrs[i].attr.mode = 0444; + tdata->sd_attrs[i].show = rd_ptr[i]; + tdata->attrs[i] = &tdata->sd_attrs[i].attr; } tdata->attr_group.attrs = tdata->attrs; return sysfs_create_group(&dev->kobj, &tdata->attr_group); From patchwork Fri Feb 2 09:21:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp307023dyc; Fri, 2 Feb 2024 01:24:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmqi1yBzuxpXRdjSyTFgRb2bigdxW6ApjK6Bn/T9PxbxTPSbaG7VWVo5ukeVbhvwuCGN6l X-Received: by 2002:a25:8305:0:b0:dbe:ace1:acf6 with SMTP id s5-20020a258305000000b00dbeace1acf6mr1866614ybk.13.1706865874184; Fri, 02 Feb 2024 01:24:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706865874; cv=pass; d=google.com; s=arc-20160816; b=sL7CEsgpHlIUFxoSkasfyvFivQa5CVOhcm0lnDS/vtKGHDYYKvzUCYM+eLOaP7ZTNX Rm8Gmpib5hFlAwkikF4py4x7+JbKFmUiuhBuiQnsaEcFkk0rkdRvZwDTSgQkwcri8H/Q GMoA9HeuxEwW2J9un+crKFneuNocoe33C8QRvgJkRpo6bT9kKiYs4G07faIEF9ayZsFH mEgV+AoafzBRXJ0jBcBmOvAsTydh1FMvYj8jD7p9YxWNmb9VP3s2V3XBb4lalid1gT/h cAr3OqdfL5tL8om+Yg2nVQTcM4KxzLyAe7c+6WAz7vmeGtBTh6UDtt/VlHPX3xSn4yMT 1jwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=aZ7zP6Fr2JAnWpJxrSUV/0aruv+DRJvbZnflmjYS0Uk=; fh=/KhRsH0otIWnn0T2c9kgTKc6QIFyw0Xp3bobsehR5rk=; b=yNPmHvwEAtyjC6SkYOCrputnZVwXXIjMX++O6TItzMBEeuiNlNhFFhdXsdyzHOpc0s 60ajgmV9YiA0eQIkaFtqdcoWn0Z9wz1mBrwn45E8wmu608AMYQ2muYVuW7GT+cXUHszc 7a5VpW7G+hKbL/vPArNu1mo9rjHihHPWvpZZg5NpRamCIvWJtiCcmW54lKc7JH5bvFKI 6NA511xImHp6lSQUc6FvPqSedZ9EG/S9cJL/6aRBCskqGhdu5e9nIrCmhLWfnWazvC4v 8QAtUK2LkOqJghJ9zNglS8UXOC5VjCd7JSrG1t7KFmt2uGUS6F7uElacNdDd8XkMI1L1 W+Tw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YInG+27o; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49560-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49560-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUG8AB5jSPxrQvITaTrHLwicPcu/RIV/Q0uFAl4haxRl9HT6cjgZZjCcMJ8K2HEOya1TgxfLyBAvXtmxd23zYqlmSAihg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a16-20020a05620a02f000b00783da2644b0si1564184qko.696.2024.02.02.01.24.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:24:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49560-ouuuleilei=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=@intel.com header.s=Intel header.b=YInG+27o; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49560-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49560-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 003471C268FA for ; Fri, 2 Feb 2024 09:24:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D0637D400; Fri, 2 Feb 2024 09:22:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YInG+27o" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 EC5957CF07; Fri, 2 Feb 2024 09:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865735; cv=none; b=A2nmTZ9VfsJdOzNOnTh2KBPn8BLovGKeJ1iHJzsTkT1EMFR2HQUuGM0a+r1Z0orzJ7oLXVniIOZUE26vJ8t/790UjruMk4tW7u8/XM4O4wDuqbvVHBrsJ4Ryw8fC3N98igidVKICc1ru5+/aO0H1UBsCXXMRTL8KNRWBt5WR7KU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865735; c=relaxed/simple; bh=ObzYZjjPuoaArfY2LHC47nxAkH4bnA054skyvxsUans=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OBG14hfcMVr5HsWlvVX7TvKo15rjZKjPM4aNUY2wKRrOEjhFqq0wnPrRB2Sd/lyQghg0mUDBLPCcQETbCsn3raxPC14/QvEBFquSw4feFocSi6j7v0j+I3oP8md+q562iMlWCjoNSutvU9p79MfR1uArJeDUD+vOKMl9xvvHgY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YInG+27o; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865734; x=1738401734; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ObzYZjjPuoaArfY2LHC47nxAkH4bnA054skyvxsUans=; b=YInG+27oeZ8h64cMaKvryMKLqYnZ6spbGhrF0Df8YtDFMZM+Bnjua9nS wKfBN8m8wewDdQcgZtPtFPczcWlqqaLDc1Wd2hSPpb0mS9QA6Ie/U6RLE pUn1L71D/S1N1cg1kD6pWGdhUL6hGKZwvBFNJk1VGxgPdluEZyNTKXztm BGKuSWmoG3mYdcfMdCOHF9VuaUIYLCCG428OXXnoVR53JDZSN69FqSme7 DFxkhTfY5QWqJFGQRAunbuW+rXzzm4eA6uyfZhfnd+FTV6Dmw5quSPc4p p5XUSP35W5qDc+MxiNj3saqRromRVoa9SsyovsbBQb7p+ZZJ8Z2FGbtWC w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483077" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483077" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639739" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:11 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 07/11] hwmon: (coretemp) Remove redundant pdata->cpu_map[] Date: Fri, 2 Feb 2024 17:21:40 +0800 Message-Id: <20240202092144.71180-8-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789778590938376597 X-GMAIL-MSGID: 1789778590938376597 pdata->cpu_map[] saves the mapping between cpu core id and the index in pdata->core_data[]. This is used to find the temp_data structure using cpu_core_id, by traversing the pdata->cpu_map[] array. But the same goal can be achieved by traversing the pdata->core_temp[] array directly. Remove redundant pdata->cpu_map[]. No functional change. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index cdd1e069d5c1..29ee8e0c0fe9 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -96,7 +96,6 @@ struct temp_data { struct platform_data { struct device *hwmon_dev; u16 pkg_id; - u16 cpu_map[NUM_REAL_CORES]; struct ida ida; struct cpumask cpumask; struct temp_data *core_data[MAX_CORE_DATA]; @@ -517,7 +516,6 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, if (index < 0) return index; - pdata->cpu_map[index] = topology_core_id(cpu); index += BASE_SYSFS_ATTR_NO; } @@ -696,7 +694,7 @@ static int coretemp_cpu_offline(unsigned int cpu) struct platform_device *pdev = coretemp_get_pdev(cpu); struct platform_data *pd; struct temp_data *tdata; - int i, indx = -1, target; + int i, target; /* No need to tear down any interfaces for suspend */ if (cpuhp_tasks_frozen) @@ -707,18 +705,16 @@ static int coretemp_cpu_offline(unsigned int cpu) if (!pd->hwmon_dev) return 0; - for (i = 0; i < NUM_REAL_CORES; i++) { - if (pd->cpu_map[i] == topology_core_id(cpu)) { - indx = i + BASE_SYSFS_ATTR_NO; + for (i = BASE_SYSFS_ATTR_NO; i < MAX_CORE_DATA; i++) { + if (pd->core_data[i] && pd->core_data[i]->cpu_core_id == topology_core_id(cpu)) break; - } } /* Too many cores and this core is not populated, just return */ - if (indx < 0) + if (i == MAX_CORE_DATA) return 0; - tdata = pd->core_data[indx]; + tdata = pd->core_data[i]; cpumask_clear_cpu(cpu, &pd->cpumask); @@ -729,7 +725,7 @@ static int coretemp_cpu_offline(unsigned int cpu) */ target = cpumask_any_and(&pd->cpumask, topology_sibling_cpumask(cpu)); if (target >= nr_cpu_ids) { - coretemp_remove_core(pd, indx); + coretemp_remove_core(pd, i); } else if (tdata && tdata->cpu == cpu) { mutex_lock(&tdata->update_lock); tdata->cpu = target; From patchwork Fri Feb 2 09:21:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp309419dyc; Fri, 2 Feb 2024 01:31:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFN/3wHnCKse0kbHoA41AdZz8xYqSfr59t+QicIDq2l3L+iw27RrLBhKfGdU6P80tGLUzA8 X-Received: by 2002:a17:902:d4c9:b0:1d7:2455:2e70 with SMTP id o9-20020a170902d4c900b001d724552e70mr1546410plg.21.1706866275410; Fri, 02 Feb 2024 01:31:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706866275; cv=pass; d=google.com; s=arc-20160816; b=PHwXC974VSPZ1PHHZ30JtS+tiioR9VN++aF0fizGIDOnd10ifuNhVvePlwYqQTDff+ EqCW1t7nXhjQ7yijEyGF3MuIqKyFxSWm7+QpdWddT7UjrIXhRCu+lfNwfdYcmEfIo+t4 VeuujsKAUJp/dmyd2jlFuCazaHobU3gRtN1Q4pQ/q/v1ZzslnNHTHSCPcFp496K7/KfC Q+fQZNBZ+nM1cN4RpOYLn5tllfvmXno79RfL1Ice36p/ug+FDioYq7hFL/VBppdo3umR iSuQu8fzOKGT0uzGxMnY9WUu7Cva7xAPJqa9UOdNmzIavwYsd7TMnB8sfg30d4K+r5jy uRdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0uGRfIumuBRGlmKApCMryIrJHfgdyvA7OhXaQEcHxEs=; fh=KPWVYcwzXE9viz8va+6b+dqFxVJXVLNl+TNgwO/fo7o=; b=H0c6XBEnOg82XQvOuhEQis6EIX+UJhdTkwr8ZPAB7TvrcPwAmgPZJrTr5kWs8+xmjw gZh7QdRkiihdI6tbTDT7f3PG+yxupOQR9PVXl0CjZx36abJwxIAAx2duf+9O27j18BFm q3EvtCP1KGV18WGHbeVbYa7dCVO+OiirykHw0JEVrBNYZSw5zp8R5gpX4F1KJrpp9cj+ W2plMTRNRk7/e9SUhsmA1Ce2O8qy1CQQKHOKjd31LvzzBwVuDRDiY4zztbD8C7kQe27S Njbl2jqmXKE+OWFjzBnn1/YLbZuda2vNMwDPiRaIXpJnTE0vi2V+8kukOpeW8tk0mUdX mWfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZjxjGqe3; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49562-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49562-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVdehXn7FvwfXLPQgUtLn+792IaDzppHvGp5DQfRMGWpoGTeQ7NGo2WMHfzp97vgjQYL+DjIdJSsU98FjsIi2c0MxQHBw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u2-20020a170902e80200b001d95551bcd9si1455693plg.308.2024.02.02.01.31.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:31:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49562-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZjxjGqe3; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49562-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49562-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2304F2988A4 for ; Fri, 2 Feb 2024 09:25:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D9D67E58F; Fri, 2 Feb 2024 09:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZjxjGqe3" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 1D1227D3E6; Fri, 2 Feb 2024 09:22:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865741; cv=none; b=iG+g3n8xLCTG7TC0uFYOdKhglmsem9xXD70SrT2E9+oTOZbPwzqhPQ/ynX/hqx8jg+dHXM+zgnTgwUwR022cIy1AIM6VAo/wN4Ky+HWRxMLmfstWTrS2hLc81/ROdL5G6cNCD09kHbiM5UFVd6GejTCPD5VrXPd/W8iLEH1fELA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865741; c=relaxed/simple; bh=ga1g5JzpiWhZ7qkFsQ1GKbvCbtBl/zg26nkpBuYMJvs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iT0oVCQkBgX+fm+horKQ8+97CmeO7SpFeVjxurJz7RdKBFbVGnTeQb+PD9sfJxXcyS8bMCYDj93cFzoo42F50mqlNgFf7lWy47YOt5eIvu2ZFSYXpEE2we4gW91MsLB1sR7uKjw7QA/rFPTKWa3jqX84zQ+dupN+J0WmBrUqJuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZjxjGqe3; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865738; x=1738401738; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ga1g5JzpiWhZ7qkFsQ1GKbvCbtBl/zg26nkpBuYMJvs=; b=ZjxjGqe3BwGc8NgGR2RQc11V0zjisTBfPUr5PjP8TpHUZ1n2Mo0BPOer yEr/oyWlyMa2He8isJowryjo8rLEj7deSIVPHZxk5Z/rK7MypO7TGIv/v 0b5Bq4pVqXNuFN29/PWkbCB79GIzxfNjaVSrgRmVDU/BcK626h/EQwYq2 tEPh+XlNrTqbWfGGMdF5mke/KNDe7KUU5lAWJzCztKpdQPVj005drdwKA +ZaQ5N7E1csvS+9uFfUnJ3aY/vwxEyeu+yPMaxCgQzZt5d0oc3fz8nAkL 9hI8qxuAcXj0EKjb4mVHZmqha3/KP3Zt59/Vhkc+sfzI9e/qB5XGyupoa w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483102" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483102" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639750" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:14 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 08/11] hwmon: (coretemp) Abstract core_temp helpers Date: Fri, 2 Feb 2024 17:21:41 +0800 Message-Id: <20240202092144.71180-9-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789779011879522877 X-GMAIL-MSGID: 1789779011879522877 coretemp driver has an obscure and fragile logic for handling package and core temperature data. Place the logic in newly introduced helpers for further optimizations. No functional change. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 118 +++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 54 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 29ee8e0c0fe9..a19799a302a2 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -81,6 +81,7 @@ struct temp_data { int tjmax; unsigned long last_updated; unsigned int cpu; + unsigned int index; u32 cpu_core_id; u32 status_reg; int attr_size; @@ -474,14 +475,36 @@ static struct platform_device *coretemp_get_pdev(unsigned int cpu) return NULL; } -static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag) +static struct temp_data * +init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) { struct temp_data *tdata; + int index; tdata = kzalloc(sizeof(struct temp_data), GFP_KERNEL); if (!tdata) return NULL; + /* + * Get the index of tdata in pdata->core_data[] + * tdata for package: pdata->core_data[1] + * tdata for core: pdata->core_data[2] .. pdata->core_data[NUM_REAL_CORES + 1] + */ + if (pkg_flag) { + index = PKG_SYSFS_ATTR_NO; + } else { + index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); + if (index < 0) { + kfree(tdata); + return NULL; + } + index += BASE_SYSFS_ATTR_NO; + } + /* Index in pdata->core_data[] */ + tdata->index = index; + + pdata->core_data[index] = tdata; + tdata->status_reg = pkg_flag ? MSR_IA32_PACKAGE_THERM_STATUS : MSR_IA32_THERM_STATUS; tdata->is_pkg_data = pkg_flag; @@ -492,6 +515,30 @@ static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag) return tdata; } +static void destroy_temp_data(struct platform_data *pdata, struct temp_data *tdata) +{ + pdata->core_data[tdata->index] = NULL; + if (!tdata->is_pkg_data) + ida_free(&pdata->ida, tdata->index - BASE_SYSFS_ATTR_NO); + kfree(tdata); +} + +static struct temp_data *get_temp_data(struct platform_data *pdata, int cpu) +{ + int i; + + /* cpu < 0 means get pkg temp_data */ + if (cpu < 0) + return pdata->core_data[PKG_SYSFS_ATTR_NO]; + + for (i = BASE_SYSFS_ATTR_NO; i < MAX_CORE_DATA; i++) { + if (pdata->core_data[i] && + pdata->core_data[i]->cpu_core_id == topology_core_id(cpu)) + return pdata->core_data[i]; + } + return NULL; +} + static int create_core_data(struct platform_device *pdev, unsigned int cpu, int pkg_flag) { @@ -499,36 +546,19 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, struct platform_data *pdata = platform_get_drvdata(pdev); struct cpuinfo_x86 *c = &cpu_data(cpu); u32 eax, edx; - int err, index; + int err; if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) return 0; - /* - * Get the index of tdata in pdata->core_data[] - * tdata for package: pdata->core_data[1] - * tdata for core: pdata->core_data[2] .. pdata->core_data[NUM_REAL_CORES + 1] - */ - if (pkg_flag) { - index = PKG_SYSFS_ATTR_NO; - } else { - index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); - if (index < 0) - return index; - - index += BASE_SYSFS_ATTR_NO; - } - - tdata = init_temp_data(cpu, pkg_flag); - if (!tdata) { - err = -ENOMEM; - goto ida_free; - } + tdata = init_temp_data(pdata, cpu, pkg_flag); + if (!tdata) + return -ENOMEM; /* Test if we can access the status register */ err = rdmsr_safe_on_cpu(cpu, tdata->status_reg, &eax, &edx); if (err) - goto exit_free; + goto err; /* Make sure tdata->tjmax is a valid indicator for dynamic/static tjmax */ get_tjmax(tdata, &pdev->dev); @@ -542,20 +572,15 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, if (get_ttarget(tdata, &pdev->dev) >= 0) tdata->attr_size++; - pdata->core_data[index] = tdata; - /* Create sysfs interfaces */ err = create_core_attrs(tdata, pdata->hwmon_dev); if (err) - goto exit_free; + goto err; return 0; -exit_free: - pdata->core_data[index] = NULL; - kfree(tdata); -ida_free: - if (!pkg_flag) - ida_free(&pdata->ida, index - BASE_SYSFS_ATTR_NO); + +err: + destroy_temp_data(pdata, tdata); return err; } @@ -566,10 +591,8 @@ coretemp_add_core(struct platform_device *pdev, unsigned int cpu, int pkg_flag) dev_err(&pdev->dev, "Adding Core %u failed\n", cpu); } -static void coretemp_remove_core(struct platform_data *pdata, int indx) +static void coretemp_remove_core(struct platform_data *pdata, struct temp_data *tdata) { - struct temp_data *tdata = pdata->core_data[indx]; - /* if we errored on add then this is already gone */ if (!tdata) return; @@ -577,11 +600,7 @@ static void coretemp_remove_core(struct platform_data *pdata, int indx) /* Remove the sysfs attributes */ sysfs_remove_group(&pdata->hwmon_dev->kobj, &tdata->attr_group); - kfree(pdata->core_data[indx]); - pdata->core_data[indx] = NULL; - - if (indx >= BASE_SYSFS_ATTR_NO) - ida_free(&pdata->ida, indx - BASE_SYSFS_ATTR_NO); + destroy_temp_data(pdata, tdata); } static int coretemp_device_add(int zoneid) @@ -694,7 +713,7 @@ static int coretemp_cpu_offline(unsigned int cpu) struct platform_device *pdev = coretemp_get_pdev(cpu); struct platform_data *pd; struct temp_data *tdata; - int i, target; + int target; /* No need to tear down any interfaces for suspend */ if (cpuhp_tasks_frozen) @@ -705,16 +724,7 @@ static int coretemp_cpu_offline(unsigned int cpu) if (!pd->hwmon_dev) return 0; - for (i = BASE_SYSFS_ATTR_NO; i < MAX_CORE_DATA; i++) { - if (pd->core_data[i] && pd->core_data[i]->cpu_core_id == topology_core_id(cpu)) - break; - } - - /* Too many cores and this core is not populated, just return */ - if (i == MAX_CORE_DATA) - return 0; - - tdata = pd->core_data[i]; + tdata = get_temp_data(pd, cpu); cpumask_clear_cpu(cpu, &pd->cpumask); @@ -725,7 +735,7 @@ static int coretemp_cpu_offline(unsigned int cpu) */ target = cpumask_any_and(&pd->cpumask, topology_sibling_cpumask(cpu)); if (target >= nr_cpu_ids) { - coretemp_remove_core(pd, i); + coretemp_remove_core(pd, tdata); } else if (tdata && tdata->cpu == cpu) { mutex_lock(&tdata->update_lock); tdata->cpu = target; @@ -735,10 +745,10 @@ static int coretemp_cpu_offline(unsigned int cpu) /* * If all cores in this pkg are offline, remove the interface. */ - tdata = pd->core_data[PKG_SYSFS_ATTR_NO]; + tdata = get_temp_data(pd, -1); if (cpumask_empty(&pd->cpumask)) { if (tdata) - coretemp_remove_core(pd, PKG_SYSFS_ATTR_NO); + coretemp_remove_core(pd, tdata); hwmon_device_unregister(pd->hwmon_dev); pd->hwmon_dev = NULL; return 0; From patchwork Fri Feb 2 09:21:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp309460dyc; Fri, 2 Feb 2024 01:31:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1hQ6XHGy64SWh3abqKJQHZXDf8Bc2y24h0wQOauXLeZ3qug8v7dnGFiE72IlEiq//xmhB X-Received: by 2002:a17:90a:bf02:b0:296:1147:4354 with SMTP id c2-20020a17090abf0200b0029611474354mr1520047pjs.37.1706866282658; Fri, 02 Feb 2024 01:31:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706866282; cv=pass; d=google.com; s=arc-20160816; b=KNTx/w+vy180e0oAlZMxRL8EiVnFNQvLO3/rNBc3OiYQ9A4eulcVzhva6jv8At27zY V4dpKWs0ZOraPpNcghTQIAutNNQuEg2PRWdyO+Ucp6GZr4akObbGpqdIVmEIQuY5Y0Td u3qwiHO8TBVgUDstc5Mf2UXp6ZEEf1G7HWbpugZfDwNXnqjDBBQABwzbqRFcInskldC5 JHSN/7GUD0K537oeElJs5ZYX7nzwYx0GTFcoNVN+JRXnHi59yKXPODAyfXDs4a9G7EnZ wTx6uNOvT0znSAsnnbFzlSgMofsXGcSvse/dfIYak0pOSt/g0BRH8KyOZ/n1B1tnZbe3 KDnw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HOTTGoAtmt6llRu7COMe6FA3tzZXP2jkSRJ7vDnNIU8=; fh=tRQHYGdbLbcqBnUZFh9Y6eBmJsVGDn0p0c3VDP2W2KI=; b=wYW42LF3/Iy9RvWdex32zheRBaOnqbpgI9W1zehbwcuowZpbbytq9J/eH+ewHC3yUo S5i6TPnQ/T8Jr5JqCs0E54yuvpHSTRmzHxAabpj3VEKSwvEbLYT99Y5Vh52RGuYhI3pR FZ6TdPho4+i3KuGOZrju0KHi9IaMamUnf02Zp/C4fkjjBsAJonwcIq1U25HKzt5Ee8GB mB9JTM1ML/5VLnKT2aSW+1urWVkvXzvbqZbD5QvLcXVP3CkbqAoeJ9IIogBn9KOLA62L dOU+Q30cYC3XNrho+7OfrgVetequImFy5fSHkOiBOyTDf2mkRNsUhLxcISt+J4G81JiG NM1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QBxRwzWb; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49561-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49561-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWhOP1I6fvrgMYKKw3xbbfBJ/cuK0ymrIVRhHpVWH633MQq/ljT2BKS1avqO8g+L3i6OLjOLyW6K/nlVUtro7TH7OEIGw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id gp15-20020a17090adf0f00b00295f31e019fsi4659137pjb.0.2024.02.02.01.31.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:31:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49561-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QBxRwzWb; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49561-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49561-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EFF0729864B for ; Fri, 2 Feb 2024 09:25:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D4B37E57B; Fri, 2 Feb 2024 09:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QBxRwzWb" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 6807460BBD; Fri, 2 Feb 2024 09:22:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865740; cv=none; b=SKvKzmcwy2ao8SH3eRFZ4jykBZ8MFmcYZqE4PRp8NiGeH3Rh+F7W/Ibvn/s+sRC89jX0HUmd2zRBvHfkaghUS3/9FdjFOi5u7NoYZsnaP9/qhLPn88+ZQ9cpRLiuf5uXBfWFSFKc/OzHHjvtU/cv5rE4R7qeYEaVywP8nwl/1NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865740; c=relaxed/simple; bh=+0SD87OA9HiAYQsvVbd0Jkh4AKAqYERvx5zrzAeIyD4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LKegYpozOUMZrLK8rVwkVrmX98eywF7Jzcpe4hE9MOFNcy2cOKOQ/oGxUBle1/if1Tho7Dkpw719h5i/watm+cSVmVYah8ax+IIZRhfn7h3Aivh6agegtEllqTwzcKWb70xiTh64bfNwjMaDV8X2vL4uGfZ5byQKQgmn3Cm3RIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QBxRwzWb; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865740; x=1738401740; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+0SD87OA9HiAYQsvVbd0Jkh4AKAqYERvx5zrzAeIyD4=; b=QBxRwzWbvALcwlW4iTwKIs1GggEwUu3CLYumX9OtxF9mbAz7SW8r9udL SRu9ElfFFmGicVqIsKP7DjEeNV7XU8lWfeyGcGP2nvlwqZclPS9xGxH7K qJ6Q/NF8DGpFmOgJtokd8Ny/8LomVPhdxiZujQMgeiQRmPo0H+Mx1NByr fRYLiwxh1Sj1V+9htYY/rMO1fuyWD5KRZvMSPmsdXhzYwhY8RXdevAQG3 evOWMPC6wmt4nI8o/nTeFII5CWISzieKJt9W0okBbm4aNQnP9QAB+QWWD jSeruAmgHCBo3+kBTvSNfEUFC0EpGAbWUwnK35sl/KrlDX0PP1MzGltEo w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483114" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483114" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639763" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:17 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 09/11] hwmon: (coretemp) Split package temp_data and core temp_data Date: Fri, 2 Feb 2024 17:21:42 +0800 Message-Id: <20240202092144.71180-10-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789779019360463138 X-GMAIL-MSGID: 1789779019360463138 Saving package temp_data and core temp_data in one array with different offsets is fragile. Split them and clean up crabbed maths and macros. This also fixes a problem that pdata->core_data[0] was never used. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index a19799a302a2..1a3b5ae0baca 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -39,11 +39,8 @@ static int force_tjmax; module_param_named(tjmax, force_tjmax, int, 0444); MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); -#define PKG_SYSFS_ATTR_NO 1 /* Sysfs attribute for package temp */ -#define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ #define NUM_REAL_CORES 512 /* Number of Real cores per cpu */ #define CORETEMP_NAME_LENGTH 28 /* String Length of attrs */ -#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) enum coretemp_attr_index { ATTR_LABEL, @@ -99,7 +96,8 @@ struct platform_data { u16 pkg_id; struct ida ida; struct cpumask cpumask; - struct temp_data *core_data[MAX_CORE_DATA]; + struct temp_data *pkg_data; + struct temp_data *core_data[NUM_REAL_CORES]; struct device_attribute name_attr; }; @@ -479,31 +477,21 @@ static struct temp_data * init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) { struct temp_data *tdata; - int index; tdata = kzalloc(sizeof(struct temp_data), GFP_KERNEL); if (!tdata) return NULL; - /* - * Get the index of tdata in pdata->core_data[] - * tdata for package: pdata->core_data[1] - * tdata for core: pdata->core_data[2] .. pdata->core_data[NUM_REAL_CORES + 1] - */ if (pkg_flag) { - index = PKG_SYSFS_ATTR_NO; + pdata->pkg_data = tdata; } else { - index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); - if (index < 0) { + tdata->index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); + if (tdata->index < 0) { kfree(tdata); return NULL; } - index += BASE_SYSFS_ATTR_NO; + pdata->core_data[tdata->index] = tdata; } - /* Index in pdata->core_data[] */ - tdata->index = index; - - pdata->core_data[index] = tdata; tdata->status_reg = pkg_flag ? MSR_IA32_PACKAGE_THERM_STATUS : MSR_IA32_THERM_STATUS; @@ -517,9 +505,12 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) static void destroy_temp_data(struct platform_data *pdata, struct temp_data *tdata) { - pdata->core_data[tdata->index] = NULL; - if (!tdata->is_pkg_data) - ida_free(&pdata->ida, tdata->index - BASE_SYSFS_ATTR_NO); + if (tdata->is_pkg_data) { + pdata->pkg_data = NULL; + } else { + pdata->core_data[tdata->index] = NULL; + ida_free(&pdata->ida, tdata->index); + } kfree(tdata); } @@ -529,9 +520,9 @@ static struct temp_data *get_temp_data(struct platform_data *pdata, int cpu) /* cpu < 0 means get pkg temp_data */ if (cpu < 0) - return pdata->core_data[PKG_SYSFS_ATTR_NO]; + return pdata->pkg_data; - for (i = BASE_SYSFS_ATTR_NO; i < MAX_CORE_DATA; i++) { + for (i = 0; i < NUM_REAL_CORES; i++) { if (pdata->core_data[i] && pdata->core_data[i]->cpu_core_id == topology_core_id(cpu)) return pdata->core_data[i]; From patchwork Fri Feb 2 09:21:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp309478dyc; Fri, 2 Feb 2024 01:31:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJxjTm5Y5crEhK2C2QJctYQCDIaOvgc/nfoybhxH6ioIC+eHIilxKmzgqNcrw2oZPS8d0W X-Received: by 2002:a05:6870:ce97:b0:218:6950:850c with SMTP id xe23-20020a056870ce9700b002186950850cmr1376792oab.21.1706866287063; Fri, 02 Feb 2024 01:31:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706866287; cv=pass; d=google.com; s=arc-20160816; b=BZlLL4dOZH1e8NEGd5S62Kmu5qTltshiIN5ca85A0DKsKahOytWb+jDdFZLRyThGRF A30wwZddIuMzf4mCNDBg/fzTrxo8YEduQ1eHTeI6Rpi6T+QAumdnQLPqPLGrNJ9Y5YH4 wDuFCz3JNDLzY9ef6eNUArL3IFpqwSVmzmnufAmoFY2qOguKoLw0ywGuThTN0o1egSR+ WGKJ3v8I3o2d2VutMxYabh1CafHlrZwvqbS05qBNMBccjfrvmnAVThawUh7k90RG3/cj XPzVKxofHvSIpQNG1YsFPmHnZibt21qLOvqV0aZ8GOkEUlkOP5yoNjTQgxWy8vTUGYmc G0JA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wvDGRYg3m4klzLESl7nM4MXJAOgAKxlhA29oNIGOXns=; fh=vlrW6EDhCcz6j/pZ6nlP+JqeZDzoXG/ppJIosVxYu1A=; b=mAAD0sG7QjW7DPjTP8DXK1I2nVCg+UCswCahjPAIbdGT8k39/Ro1No/OzO32SZbtnc p+78sO1ffz+n/UJB0xtDKlP3nqf/Umujy1xQ6m3CPIqRMpGVPw665OmIgRiIpfqEeKaf +Xg2oI4+j2xE4/vKAjbkG7Eo/rl+pBBx0G6pM8xn7WtiT6B5+xmdHKxp+59zzNCavP6z lRGK/bN1yTVcTaS/9gNUNw6QQOX6mnbyY7Xqbjf9YG8/ICJ0qFRSSaOFSdWtqIjzlfg9 x+7pVkJTXa2CedwCtwYLo5E6uJ3KLncuUvHXhnY5oXXiGHszT+vEhz23bOGfz84VThdT fOJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BNt2R9Kg; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49563-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49563-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVgbShPDskCRKIu4LZ4tDXJIp/2BOiHFlMBodMKxSXlXjU1hYEFICpGOmw3LI2k0b6byXs0JdVBEMvAWRiHW3ULeacm7g== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c16-20020a634e10000000b005cde3cc04c5si1286778pgb.821.2024.02.02.01.31.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:31:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49563-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BNt2R9Kg; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49563-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49563-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F34BF298A51 for ; Fri, 2 Feb 2024 09:25:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61EBD77F0B; Fri, 2 Feb 2024 09:22:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BNt2R9Kg" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 1704677656; Fri, 2 Feb 2024 09:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865742; cv=none; b=k91K90IZrsYSX01tQG16Bt9IhaCc4759AHaWayAbiT6hJLcjUc+g+bHFaK3kl2Qmo7JCvFLQR5BcdXAJM1XhZAo2XEyCI7RuK/blnHayT+5fPQ4cN3uE3ZMuWW18/fiZeK2597HkU7XtXAROZ9kmBB9oQm82tzS5K/7rmxdNzl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865742; c=relaxed/simple; bh=csZ3KHduA/9OB+PJyC6HR1VDQadqpILw6QFQkvTj3wY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pTVNYFVc/T9FIT6CHOlrrHTSnAbsrUIwfLFsWV2XbS41H1cub+1h3+9joKCvE6yOG6Lx5LqEUjGp5l/bo0EoR9SJge3Hx1nmg/dXou+YiiNrx8ywkSeJauhiMcmSRnq6N+5OiErx+nid7cXWBHmKd3UToyBEV7Ztmhcg0qPajZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BNt2R9Kg; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865742; x=1738401742; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=csZ3KHduA/9OB+PJyC6HR1VDQadqpILw6QFQkvTj3wY=; b=BNt2R9Kg+BKEvduWJ5vUAGTnrd7S0ZDw3jBAj9vFy0RUeprsdeRL+oE4 TOgFfLLEhOclT8+fHUMScH/dQ95tQvmbCvCYaYoPkWbNXW7zrHjxT/7lu kM6R7oYtHS2J6XfATRYgYkfXMPr5HgRS7+XDKWXRXFWdWHOOdDKqbhiVt MYibqx7BTHTz9lRXxAyFrZC9eJAcNnSV8wbQId0h73BOv4bMOCT8NPZYK hYNxXLN5Jj5GKro6LKyXpo5nqQbvbwms3UIykihdoMs6a+L8AkXfi7JZm /8LPNhG8DmnftC9W2tTw2SOQad9RRHdNs+cWAXAtE0y3oaWNdfSE4Mj1b Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483126" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483126" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639776" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:19 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 10/11] hwmon: (coretemp) Remove redundant temp_data->is_pkg_data Date: Fri, 2 Feb 2024 17:21:43 +0800 Message-Id: <20240202092144.71180-11-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789779023739622062 X-GMAIL-MSGID: 1789779023739622062 temp_data->index saves the index in pdata->core_data[]. It is not used by package temp_data. Use temp_data->index as the indicator of package temp_data and remove redundant temp_data->is_pkg_data. No functional change. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 1a3b5ae0baca..e548f2145449 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -70,19 +70,16 @@ enum coretemp_attr_index { * @status_reg: One of IA32_THERM_STATUS or IA32_PACKAGE_THERM_STATUS, * from where the temperature values should be read. * @attr_size: Total number of pre-core attrs displayed in the sysfs. - * @is_pkg_data: If this is 1, the temp_data holds pkgtemp data. - * Otherwise, temp_data holds coretemp data. */ struct temp_data { int temp; int tjmax; unsigned long last_updated; unsigned int cpu; - unsigned int index; + int index; u32 cpu_core_id; u32 status_reg; int attr_size; - bool is_pkg_data; struct device_attribute sd_attrs[TOTAL_ATTRS]; char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH]; struct attribute *attrs[TOTAL_ATTRS + 1]; @@ -149,6 +146,11 @@ static const struct tjmax_model tjmax_model_table[] = { */ }; +static bool is_pkg_temp_data(struct temp_data *tdata) +{ + return tdata->index < 0; +} + static int adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev) { /* The 100C is default for both mobile and non mobile CPUs */ @@ -341,7 +343,7 @@ static ssize_t show_label(struct device *dev, struct platform_data *pdata = dev_get_drvdata(dev); struct temp_data *tdata = container_of(devattr, struct temp_data, sd_attrs[ATTR_LABEL]); - if (tdata->is_pkg_data) + if (is_pkg_temp_data(tdata)) return sprintf(buf, "Package id %u\n", pdata->pkg_id); return sprintf(buf, "Core %u\n", tdata->cpu_core_id); @@ -433,7 +435,7 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev) * The attr number is always core id + 2 * The Pkgtemp will always show up as temp1_*, if available */ - int attr_no = tdata->is_pkg_data ? 1 : tdata->cpu_core_id + 2; + int attr_no = is_pkg_temp_data(tdata) ? 1 : tdata->cpu_core_id + 2; snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, "temp%d_%s", attr_no, suffixes[i]); @@ -484,6 +486,8 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) if (pkg_flag) { pdata->pkg_data = tdata; + /* Use tdata->index as indicator of package temp data */ + tdata->index = -1; } else { tdata->index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); if (tdata->index < 0) { @@ -495,7 +499,6 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) tdata->status_reg = pkg_flag ? MSR_IA32_PACKAGE_THERM_STATUS : MSR_IA32_THERM_STATUS; - tdata->is_pkg_data = pkg_flag; tdata->cpu = cpu; tdata->cpu_core_id = topology_core_id(cpu); tdata->attr_size = MAX_CORE_ATTRS; @@ -505,7 +508,7 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) static void destroy_temp_data(struct platform_data *pdata, struct temp_data *tdata) { - if (tdata->is_pkg_data) { + if (is_pkg_temp_data(tdata)) { pdata->pkg_data = NULL; } else { pdata->core_data[tdata->index] = NULL; From patchwork Fri Feb 2 09:21:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 195743 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp309601dyc; Fri, 2 Feb 2024 01:31:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+NCHg7MBSXSWKUNkaeHBnhuirf7YDhTUeV8N2VGGoWsKs+zzzpEg3R2OWletNzl9w5+++ X-Received: by 2002:a05:6402:5213:b0:55f:7fe9:c567 with SMTP id s19-20020a056402521300b0055f7fe9c567mr6190260edd.1.1706866307996; Fri, 02 Feb 2024 01:31:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706866307; cv=pass; d=google.com; s=arc-20160816; b=XzSKrEhfN5dmgn3761M1dVDJ8DZIog0iY0wqNPr9y8VRQHE6hAiesHS9BSbkO0OGYv grhMv1o1Oy9/bH25uWoRdISMcatcuePv5ye1TMP3OP0ZjTZ+Y7I0qqJa+PV3zoq0cc7R YABHKvB+kO0O1AgqmjVyTAcbl0S7R/5fVSjVYVCBeAMSsziH6seE3rFvmNFWZNljY8i6 +ZZrjguGuZ2VgwLcdrVtp9eurRShCEWvld/+ZS7Fe94ggzXAxxwqtbn+Z1USJTCkdtHh qwMIPTaXfCZWABZ6Lx5taI+STTAoazt9vhfc79WriksjmmWMliM6xb8kgtEmMajr2dE1 oAoQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BCqDrn2ucog9lj+XxGwQMk+dee3HgOYYY8ola9sQt3Y=; fh=E30nbM8zIsfRzfFGgcBcGdFC105TrEuvzgTfMtOW+TY=; b=GhhtpPIEul6dixqCraHibXBUlT0Sm0L8Kcpf07oRo2fdxSBUI1foE4+oHaQMq6UrfL brioL+cpa+sWdgVbyU5ZB5qXUvK74S10FDVznbKia4+JuPnE6jNoKiuMprJJEq5R1d/Q DVVNP3ukQscYAWdzHfMAR36s/7EoCsw577Vjt5i2tgnfHwPW8hAXjmmL3BijAdLn9FuR KBh2R9v5Rz+i9vTDSGIO/lISEmEtk4WDtL8tdZ1Mcraosyuuia/fJgT/zz5LH/ejahkW 4YQ7oxHZz3Sawd+K8oznwvUT68rJNE1eK/9HoJWsDmbp40Cq7xHSeU7j2zE5A5HlEPMw pHIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gJHykm0l; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49564-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49564-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCW5yPGhNahiU3mUhSjAZZw0XwwJyMCfyuNvw2bBkwYeyCtZL+40/aO0DUbNVeXOEg6qhPRrA3JNk9vnuIPerA3CGjI2Og== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dn7-20020a05640222e700b0055fa7527f95si652593edb.198.2024.02.02.01.31.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:31:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49564-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=@intel.com header.s=Intel header.b=gJHykm0l; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49564-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49564-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 216AD1F2CA66 for ; Fri, 2 Feb 2024 09:25:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A86377E773; Fri, 2 Feb 2024 09:22:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gJHykm0l" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 825F677F06; Fri, 2 Feb 2024 09:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865745; cv=none; b=BwfV5N+pTkaKH9Q5VrwU7lek2drPLNNnBd3nMwGF9K58jMF4v/XePEWbAzZvInBchNVVxmAJD4F8V+BTvtegnqI1JIt8Quy1cJNnGmKP08nTcePTVr/e6z1x9VBZWnd2zsceT8SLdwlZiLs3+eqM25jLsxB01/bh6MpO9An9H78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865745; c=relaxed/simple; bh=lCx6WOgbhUs1ZUj/emefnBwJYwMVwVQYh3bpqoSEs1U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JMmGhOg5/6adr16aAmlTmBeEZJEqKHAQwEJEXNfyMBk08KaI8Gp8YjrquUb3wA6FMS3ovlDLTN51Ao7K8CfgtBZPZBzFe2D+A5AhauIqAeD1gD8pdMYnPx3W8bYnQO3eiiab4EivpbpcA7+jTIFzq2D0KSMzUCSJNG6ZlvBOBAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gJHykm0l; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865744; x=1738401744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lCx6WOgbhUs1ZUj/emefnBwJYwMVwVQYh3bpqoSEs1U=; b=gJHykm0lC8CgGZUDf6simcWAuH65M5WNuSXJUIwMYr2ftiHD1FFJbju7 pV9QCul7vZZLXh4/0A9f8BnvRGrh1a1yI9+HuREXjNavsvYBZqFhJtbti JBsmb0WCR8rL0qR79idbXEpO/pPAY9wzhqD1wqNpBAQCLCKsUbLhkgy8f dyC6ApTFOc345j4t3wMKhei0Szd8soaEOeCoqHuHBMUhdklSRFa43ANyt 12GTZsPYY6Pk5inQ0nnfl4w7sh8TIk1HA0husWBaRvilT2nMKGihJdA8b 5kQ054sCM5B5hSRk+/XtVucfbREM+mN8Waygqr2kYyohVGDHaX1E+yuTv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483147" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483147" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639785" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:22:21 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 11/11] hwmon: (coretemp) Use dynamic allocated memory for core temp_data Date: Fri, 2 Feb 2024 17:21:44 +0800 Message-Id: <20240202092144.71180-12-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789779045495381198 X-GMAIL-MSGID: 1789779045495381198 The total memory needed for saving per core temperature data depends on the number of cores in a package. Using static allocated memory wastes memories on systems with low per package core count. Improve the code to use dynamic allocated memory so that it can be improved further when per package core count information becomes available. No functional change intended. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index e548f2145449..27c98c7faf32 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -91,10 +91,11 @@ struct temp_data { struct platform_data { struct device *hwmon_dev; u16 pkg_id; + int nr_cores; struct ida ida; struct cpumask cpumask; struct temp_data *pkg_data; - struct temp_data *core_data[NUM_REAL_CORES]; + struct temp_data **core_data; struct device_attribute name_attr; }; @@ -480,6 +481,20 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) { struct temp_data *tdata; + if (!pdata->core_data) { + /* + * TODO: + * The information of actual possible cores in a package is broken for now. + * Will replace hardcoded NUM_REAL_CORES with actual per package core count + * when this information becomes available. + */ + pdata->nr_cores = NUM_REAL_CORES; + pdata->core_data = kcalloc(pdata->nr_cores, sizeof(struct temp_data *), + GFP_KERNEL); + if (!pdata->core_data) + return NULL; + } + tdata = kzalloc(sizeof(struct temp_data), GFP_KERNEL); if (!tdata) return NULL; @@ -489,7 +504,7 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) /* Use tdata->index as indicator of package temp data */ tdata->index = -1; } else { - tdata->index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); + tdata->index = ida_alloc_max(&pdata->ida, pdata->nr_cores - 1, GFP_KERNEL); if (tdata->index < 0) { kfree(tdata); return NULL; @@ -510,6 +525,9 @@ static void destroy_temp_data(struct platform_data *pdata, struct temp_data *tda { if (is_pkg_temp_data(tdata)) { pdata->pkg_data = NULL; + kfree(pdata->core_data); + pdata->core_data = NULL; + pdata->nr_cores = 0; } else { pdata->core_data[tdata->index] = NULL; ida_free(&pdata->ida, tdata->index); @@ -525,7 +543,7 @@ static struct temp_data *get_temp_data(struct platform_data *pdata, int cpu) if (cpu < 0) return pdata->pkg_data; - for (i = 0; i < NUM_REAL_CORES; i++) { + for (i = 0; i < pdata->nr_cores; i++) { if (pdata->core_data[i] && pdata->core_data[i]->cpu_core_id == topology_core_id(cpu)) return pdata->core_data[i];