Message ID | 20231025122316.836400-1-rui.zhang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp2559277vqx; Wed, 25 Oct 2023 05:23:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLPJ7b+0xr34JkwrFZR8nGguexsSZ3djk6KBljiQP026/KcgktAdDnWtkYHCrVBKmRsWhT X-Received: by 2002:a05:6830:11d7:b0:6bd:c7c3:aac2 with SMTP id v23-20020a05683011d700b006bdc7c3aac2mr15944896otq.18.1698236630428; Wed, 25 Oct 2023 05:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698236630; cv=none; d=google.com; s=arc-20160816; b=keh82v4lCK5LYfUzt7fbeqb5X00pdmduF/eYy1MriYVPNrwpnyFxSoqDwknFvvySr3 ahms/bc13668xGz0XUI3p9KZCqXIlNFpPzdl70Gjk1yzoD1DJDA74vMwg2IdCFfoXl3H 2tZzcXgj/qvArErr0BJZvHi41RJ/h0NX1gYRdezEbWIGcki23yY5ojFuw0Agv3V3Sl1P VcEUjvqikES6tH+V4fRIXfusuO47Df1R/YL8LGtIHhmtBLy/SNJlkohUDmC505lXrY63 dkfHqfrBXAA9TETjySIWq9nRP0qN9NbIIFaImkb2nRyAMuZSRospQ45lZGM46ItQW13P S0mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UfkwZdzzxCun3psHkySwxDpGkDw202M/hAz/k4FYiOc=; fh=iJio9q7TjeoiK9drov23FiG8HhfwRBiRLVTo4239oHg=; b=Q8BPweS6SAavq9T6Va5STllaWI1/P0aVoGoxHvmEW6fr/QWmigHWGcZ6hJxgTkxCxP 3azlk4had1kvWop25M72EfqjeCOchigwSb7bSGmrIaMKcbFgwF9IWYRbRa0sP9oYRfbC RPlQV8/8bkRtGdPrPFt/euoPAKki/JOHa5+jZfVw4id1YzcPUZGgR51aIH0UyGEiGVkr u0aUKHl5usqJiASYE1ahhJZ0+Gab8Vq9fk3RPF70XV6hjBUhcuqBNnnWCGylzxLA+KXT itHE7JRKcxJoRoOnQ33/ueOFF35jFyLdexV4HsE+3JRn29PlOU/WHmtQTQlGKudwhoIe HSng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C45IpDwd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id z185-20020a8165c2000000b005a81844125bsi10297520ywb.333.2023.10.25.05.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 05:23:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C45IpDwd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BB5BA80F5F20; Wed, 25 Oct 2023 05:23:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343829AbjJYMXa (ORCPT <rfc822;aposhian.dev@gmail.com> + 26 others); Wed, 25 Oct 2023 08:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343767AbjJYMX3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 25 Oct 2023 08:23:29 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4FCD9C; Wed, 25 Oct 2023 05:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698236607; x=1729772607; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=CioEJ/ktqThFVcUxv05JHlMHKJHPP+QEuG95YNoPBAQ=; b=C45IpDwdsG2VKWyze+hohhtDEIzG9XqL0gQw4z4kUxGcYS5yD6GHkkxq RYJ5ZB0CRKTaggJ8LQDA5rHL+24cn+J6xjVYu55hurFyNgFcFVM9NGm4X 8yPiHawwbKUtqZYryWYxAlQaTWwlsoJYcdmpzbnaCsGdb240RX6nWwEEC xo+M3xoN+KdaWsdAKNELLY6EXrl6IH0bff3tOk22bK3+B5Sp0Zu4xWEQL UIrGUD4f9SrCsnK+sR4ZCOPelEM/BAkHp2RkGhNBSZlAWbXUK7fCNcKHQ cnFN4QXatdth8rELorV6gdjz+yuTjFp1EqFL2Sb6bMMdxyCCai43L//9F w==; X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="473530578" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="473530578" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 05:23:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="1005993196" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="1005993196" Received: from liyingmi-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.249.172.75]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 05:23:24 -0700 From: Zhang Rui <rui.zhang@intel.com> To: linux@roeck-us.net, jdelvare@suse.com, fenghua.yu@intel.com Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, lkp@intel.com, dave.hansen@linux.intel.com, len.brown@intel.com Subject: [PATCH] hwmon: (coretemp) Fix potentially truncated sysfs attribute name Date: Wed, 25 Oct 2023 20:23:16 +0800 Message-Id: <20231025122316.836400-1-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 25 Oct 2023 05:23:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780730172736277193 X-GMAIL-MSGID: 1780730172736277193 |
Series |
hwmon: (coretemp) Fix potentially truncated sysfs attribute name
|
|
Commit Message
Zhang, Rui
Oct. 25, 2023, 12:23 p.m. UTC
When build with W=1 and "-Werror=format-truncation", below error is observed in coretemp driver, drivers/hwmon/coretemp.c: In function 'create_core_data': >> drivers/hwmon/coretemp.c:393:34: error: '%s' directive output may be truncated writing likely 5 or more bytes into a region of size between 3 and 13 [-Werror=format-truncation=] 393 | "temp%d_%s", attr_no, suffixes[i]); | ^~ drivers/hwmon/coretemp.c:393:26: note: assuming directive output of 5 bytes 393 | "temp%d_%s", attr_no, suffixes[i]); | ^~~~~~~~~~~ drivers/hwmon/coretemp.c:392:17: note: 'snprintf' output 7 or more bytes (assuming 22) into a destination of size 19 392 | snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 393 | "temp%d_%s", attr_no, suffixes[i]); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Given that 1. '%d' could take 10 charactors, 2. '%s' could take 10 charactors ("crit_alarm"), 3. "temp", "_" and the NULL terminator take 6 charactors, fix the problem by increasing CORETEMP_NAME_LENGTH to 28. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Fixes: 7108b80a542b ("hwmon/coretemp: Handle large core ID value") Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202310200443.iD3tUbbK-lkp@intel.com/ --- Note that, in practice, I found that the problem is gone if I increase the size to 22. But I cannot explain this. --- drivers/hwmon/coretemp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Wed, Oct 25, 2023 at 08:23:16PM +0800, Zhang Rui wrote: > When build with W=1 and "-Werror=format-truncation", below error is > observed in coretemp driver, > > drivers/hwmon/coretemp.c: In function 'create_core_data': > >> drivers/hwmon/coretemp.c:393:34: error: '%s' directive output may be truncated writing likely 5 or more bytes into a region of size between 3 and 13 [-Werror=format-truncation=] > 393 | "temp%d_%s", attr_no, suffixes[i]); > | ^~ > drivers/hwmon/coretemp.c:393:26: note: assuming directive output of 5 bytes > 393 | "temp%d_%s", attr_no, suffixes[i]); > | ^~~~~~~~~~~ > drivers/hwmon/coretemp.c:392:17: note: 'snprintf' output 7 or more bytes (assuming 22) into a destination of size 19 > 392 | snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 393 | "temp%d_%s", attr_no, suffixes[i]); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > cc1: all warnings being treated as errors > > Given that > 1. '%d' could take 10 charactors, > 2. '%s' could take 10 charactors ("crit_alarm"), > 3. "temp", "_" and the NULL terminator take 6 charactors, > fix the problem by increasing CORETEMP_NAME_LENGTH to 28. > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > Fixes: 7108b80a542b ("hwmon/coretemp: Handle large core ID value") > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/oe-kbuild-all/202310200443.iD3tUbbK-lkp@intel.com/ Applied. Thanks, Guenter
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index eba94f68585a..ba82d1e79c13 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -42,7 +42,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 CORETEMP_NAME_LENGTH 19 /* String Length of attrs */ +#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)