Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp294283rwb; Wed, 28 Sep 2022 02:50:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Z8ULmOs151TpYzS8PeuiTLRaaLrI5jm3Z2TFH8qvKzdT7FO+eOFcebVzMPqfTgQrQdPIu X-Received: by 2002:a17:902:cecf:b0:178:3fa3:1583 with SMTP id d15-20020a170902cecf00b001783fa31583mr31606198plg.141.1664358626549; Wed, 28 Sep 2022 02:50:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664358626; cv=none; d=google.com; s=arc-20160816; b=xoau0YrUJMBB9zhIY6afdpe87ZkcjZ0mNl8MSdNr7mUyj92zRE2m777U+9x4jCiHuS LPXNMfjsQd+CXgoBJvE2npw46nmoF2q5ars+isQa84620Lhxdg5DTm5SRQEUdctpmJBp aqXXiCxuGtTzBVbbf6iTiWPJV5wMEEyYjWmP43l3hz/RaRAyiuWx0bBSwFQtUDWcKXcn fo4IPdNbrUn3MBovU6lRlK9V1GVEvLZbjnePMDQ8aU2iBGV/SXjnmSZ0FssdoWHFk2u1 H6njBlM3QTFn5Gb+kzo43W0ZQMKFpTBdT262URyWLigoqv4gWT8kX63eW2Oe5ilm6XTG b/aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Hv6/UMPguvvpXP4vo/yWIwG9OJ7qZ0HTaeN3ivbOMKQ=; b=Fp/97C5AZ3IKKSkv7T5U5uq1er94wyvQm9nsSGZ5Vy4P9F+rn3C+UCY+PDuCJlS/fq pP+g6UvWuJ51LmtHf61d3wV+DxOXW+2ralzSSNgn03pKMok313FBwY+xFAKH3VF/Nmp5 AwsGlnrF7LVvLAKrS8ujNTu3JjwfFUkl3qnPsYKnIGLD7S+1VL+GqrGUN3HNX1zU3GO+ VQBk0+hyM8vRUKGb/utirV01ByZCjjbZgMbXl94V9BMXQlBCogLRjjG5CGEXgqoCqsCK JIw4aKa/XkNH5iDKZiEWACZQA5gsfOmPUEon1/7DUrukxujicBTh++Gm67cJaEL5Ajrr aMSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x186-20020a6331c3000000b004396227b476si5200313pgx.774.2022.09.28.02.50.15; Wed, 28 Sep 2022 02:50:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233243AbiI1JiS (ORCPT + 99 others); Wed, 28 Sep 2022 05:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbiI1Jhp (ORCPT ); Wed, 28 Sep 2022 05:37:45 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7A38ED5FD for ; Wed, 28 Sep 2022 02:36:38 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 29C851063; Wed, 28 Sep 2022 02:35:54 -0700 (PDT) Received: from [10.57.33.30] (unknown [10.57.33.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6DC9C3F792; Wed, 28 Sep 2022 02:35:46 -0700 (PDT) Message-ID: Date: Wed, 28 Sep 2022 10:35:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 5/7] kernel/cpu: Convert snprintf() to scnprintf() Content-Language: en-GB To: Jules Irenge , tglx@linutronix.de Cc: sathyanarayanan.kuppuswamy@linux.intel.com, linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, ak@linux.intel.com, Jason@zx2c4.com References: From: Steven Price In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26/09/2022 19:52, Jules Irenge wrote: > Coccinnelle reports a warning > Warning: Use scnprintf or sprintf > Adding to that, there has been a slow migration from snprintf to scnprintf. > This LWN article explains the rationale for this change > https: //lwn.net/Articles/69419/ > Ie. snprintf() returns what *would* be the resulting length, > while scnprintf() returns the actual length. > > Signed-off-by: Jules Irenge Using sysfs_emit() would be even better in this case, although it's slightly different because it outputs a maximum of PAGE_SIZE rather than PAGE_SIZE - 2 bytes. But I can't see any reason for that "- 2" - it appears to have been added when the sysfs entry was added by Thomas Gleixner in commit 05736e4ac13c ("cpu/hotplug: Provide knobs to control SMT") but I don't see any justification for it. Steve > --- > kernel/cpu.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/cpu.c b/kernel/cpu.c > index bbad5e375d3b..f358d89c9580 100644 > --- a/kernel/cpu.c > +++ b/kernel/cpu.c > @@ -2512,7 +2512,7 @@ static ssize_t control_show(struct device *dev, > { > const char *state = smt_states[cpu_smt_control]; > > - return snprintf(buf, PAGE_SIZE - 2, "%s\n", state); > + return scnprintf(buf, PAGE_SIZE - 2, "%s\n", state); > } > > static ssize_t control_store(struct device *dev, struct device_attribute *attr, > @@ -2525,7 +2525,7 @@ static DEVICE_ATTR_RW(control); > static ssize_t active_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > - return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active()); > + return scnprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active()); > } > static DEVICE_ATTR_RO(active); >