Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2520742rda; Wed, 25 Oct 2023 05:23:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFE72ac8N0TQjRW2ng2sW5MKTLn4zTxZsjBLQnZzGmf9N47BOr1qXPQ/vLE9ZLhHsS1Xa4Z X-Received: by 2002:a81:4844:0:b0:5a8:d86f:bb3f with SMTP id v65-20020a814844000000b005a8d86fbb3fmr16126049ywa.8.1698236620754; Wed, 25 Oct 2023 05:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698236620; cv=none; d=google.com; s=arc-20160816; b=C2/9e/D5VETYq1dhn8NlOzu8SQOaEQXt+C4p7S2vifPDAQ4ASAwz056AzwgErt0Vb/ 8q1bAhcYHn4XcdF9E9ANVznZ8OCbe2nyvtltqmGw9QOxfhIhj0G+r/W4UNByZDdBOc9R E4vVXZCKcaUnHqjBVqx2h3kjPAVz8n3mNbY4i2Y1wzydimJSueXNvtFSSQH8hK7KahC1 RqwOG0Ic5gorhIlxXbTdkYEvfk+/x40k/i3OWGwnFNeJ8KWTzZsC7zWyBBXW+zTD22Qd N3fSb+5NT8fUa8Ks4lr3RnVbooGX714d1Xf0Spl76TiWEVuFBmCwBezCJr/KJaNn7uZl v4Ag== 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 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m14-20020a819c0e000000b005a7b9248a12si11654696ywa.12.2023.10.25.05.23.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 05:23:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; 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 23.128.96.33 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 0530180F5F1B; Wed, 25 Oct 2023 05:23:38 -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 S1343827AbjJYMXa (ORCPT + 99 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 ); 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 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: 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:38 -0700 (PDT) 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 Fixes: 7108b80a542b ("hwmon/coretemp: Handle large core ID value") Reported-by: kernel test robot 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(-) 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) -- 2.34.1