From patchwork Tue Oct 17 08:44:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shuwang@redhat.com X-Patchwork-Id: 10011209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B52A0601E7 for ; Tue, 17 Oct 2017 08:45:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A46F228800 for ; Tue, 17 Oct 2017 08:45:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 996BB28803; Tue, 17 Oct 2017 08:45:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DEC7287C5 for ; Tue, 17 Oct 2017 08:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756429AbdJQIpM (ORCPT ); Tue, 17 Oct 2017 04:45:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40214 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756389AbdJQIpJ (ORCPT ); Tue, 17 Oct 2017 04:45:09 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F34646217; Tue, 17 Oct 2017 08:45:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5F34646217 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=shuwang@redhat.com Received: from d760b8.nay.redhat.com (dhcp-12-134.nay.redhat.com [10.66.12.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56E3E5C1A1; Tue, 17 Oct 2017 08:45:05 +0000 (UTC) From: shuwang@redhat.com To: fenghua.yu@intel.com, jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, chuhu@redhat.com, yizhan@redhat.com, Shu Wang Subject: [PATCH] hwmon: (coretemp) remove duplicated coretemp for same core id Date: Tue, 17 Oct 2017 16:44:50 +0800 Message-Id: <20171017084450.4365-1-shuwang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 17 Oct 2017 08:45:09 +0000 (UTC) Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shu Wang Fix kernel warning on my 4cpus 2core_id system. The cpu0 and cpu1 have same core_id 0, so both cpu0 and cpu1 will try to create file temp2_label when it's online. - coretemp_cpu_online(cpu=0) - create_core_data(cpu=0, attr_no=2) - create_core_attrs(attr_no=2) - coretemp_cpu_online(cpu=1) - create_core_data(cpu=1, attr_no=2) - create_core_attrs(attr_no=2) $ grep -e processor -e 'core id' /proc/cpuinfo processor : 0 core id : 0 processor : 1 core id : 0 processor : 2 core id : 1 processor : 3 core id : 1 dmesg: sysfs: cannot create duplicate filename '/devices/platform/coretemp.0/hwmon/hwmon3/temp2_label' sysfs: cannot create duplicate filename '/devices/platform/coretemp.0/hwmon/hwmon3/temp3_label' WARNING: CPU: 3 PID: 27 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x58/0x70 Call Trace: sysfs_add_file_mode_ns+0x170/0x180 internal_create_group+0xe3/0x2c0 sysfs_create_group+0x13/0x20 create_core_data+0x3ab/0x5e0 [coretemp] coretemp_cpu_online+0x14b/0x1f7 [coretemp] ? create_core_data+0x5e0/0x5e0 [coretemp] cpuhp_invoke_callback+0xae/0x5c0 ? __schedule+0x295/0x880 cpuhp_thread_fun+0xcb/0x170 smpboot_thread_fn+0x110/0x160 Signed-off-by: Shu Wang --- drivers/hwmon/coretemp.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index c13a4fd86b3c..2fb29ab1080b 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -459,6 +459,17 @@ static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag) return tdata; } +static void coretemp_remove_core(struct platform_data *pdata, int indx) +{ + struct temp_data *tdata = pdata->core_data[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; +} + static int create_core_data(struct platform_device *pdev, unsigned int cpu, int pkg_flag) { @@ -479,6 +490,10 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, if (attr_no > MAX_CORE_DATA - 1) return -ERANGE; + tdata = pdata->core_data[attr_no]; + if (tdata != NULL) + coretemp_remove_core(pdata, attr_no); + tdata = init_temp_data(cpu, pkg_flag); if (!tdata) return -ENOMEM; @@ -527,17 +542,6 @@ 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) -{ - struct temp_data *tdata = pdata->core_data[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; -} - static int coretemp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev;