From patchwork Tue Mar 5 06:44:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1908033 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TpmPX1MLfz23fC for ; Tue, 5 Mar 2024 17:49:04 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rhObd-0001yV-Cd; Tue, 05 Mar 2024 06:48:53 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rhOZo-00010J-R2 for kernel-team@lists.ubuntu.com; Tue, 05 Mar 2024 06:47:02 +0000 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 7D4614118B for ; Tue, 5 Mar 2024 06:47:00 +0000 (UTC) Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5672dba9767so2107951a12.0 for ; Mon, 04 Mar 2024 22:47:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709621220; x=1710226020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o2mrnXlMhB9lxFG7B8uzjZCdiBnaLn7lur9/o/vA+KQ=; b=wuXUw95YDz9oDTHOcFNtiqUWjzvgqBfYVengDZrurvIUDqhMFa233DBNWLwJlwpsHf oSuUhv3e7o9CzpmhZvVl4sVeSMbbdKPYOf8NWXyubb6HzVGAvkEU52dXTKpXNIyxW8oV 7Vo9weD8xqoboEXkf8x7jAZ5JRYwwyqp1h/jXw4RRi4dZPnVtYaO0FHCVwTzi0BwSQ+Z PXAapIMZpUZArMaDbHCOX9ADGZNWz3oBCKi480UaKWiDsrXa0xOTU6hlmIwkb4KIWI/J sLrgte4QgogmHGFMBNu1Q7oVPGrrWpo1DMLSSzwFkZNRqr9ZObTKPMV3mZ1+kLUQPQi/ 1OnA== X-Gm-Message-State: AOJu0Yx1JP4WSu1Gn5AxfcLGlTiIKB9fKXVFIaS5VvsJdvRohdt+jger JFNLn7nSneKYnI5frY89TDdBOeQ9Qx1bFh9qrBAsmAIFuNRDiC+b7YezPsHBSiN/ru6vhpGhq26 dfXtV9XIEJtnwQFZ5VSGodl/HtKQMvricZHtQMWsEuCogQu+0Ok0cpEbU6M3xiUO3qz1DgHjBuC UaLvRB5mnZFQ== X-Received: by 2002:a05:6402:214e:b0:566:59a2:7a10 with SMTP id bq14-20020a056402214e00b0056659a27a10mr1886046edb.1.1709621220027; Mon, 04 Mar 2024 22:47:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKwNk2S2H6pPBTjSj47XUunX4F7zEngePeF8Qg1o2+Rvd14hLgTMS538kGepl6RMOLrfgRpw== X-Received: by 2002:a05:6402:214e:b0:566:59a2:7a10 with SMTP id bq14-20020a056402214e00b0056659a27a10mr1886040edb.1.1709621219807; Mon, 04 Mar 2024 22:46:59 -0800 (PST) Received: from localhost.localdomain (host-95-252-40-65.retail.telecomitalia.it. [95.252.40.65]) by smtp.gmail.com with ESMTPSA id i17-20020aa7c9d1000000b00567566227a5sm1784439edt.18.2024.03.04.22.46.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 22:46:59 -0800 (PST) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [N/U][PATCH 8/8] hwmon: (coretemp) Use dynamic allocated memory for core temp_data Date: Tue, 5 Mar 2024 07:44:12 +0100 Message-ID: <20240305064644.251754-9-andrea.righi@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240305064644.251754-1-andrea.righi@canonical.com> References: <20240305064644.251754-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Zhang Rui BugLink: https://bugs.launchpad.net/bugs/2056126 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 Link: https://lore.kernel.org/r/20240202092144.71180-12-rui.zhang@intel.com [groeck: Fixed continuation line alignment] Signed-off-by: Guenter Roeck (cherry picked from commit 1a793caf6f6991716cb07583ed7c27de84ef0cba linux-next) Signed-off-by: Andrea Righi --- 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..30402de2c889 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];