Message ID | Y++ukV1djYTd01vy@ubun2204.myguest.virtualbox.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp992805wrn; Fri, 17 Feb 2023 08:50:31 -0800 (PST) X-Google-Smtp-Source: AK7set9N6wxwfz5f4nAEJEAQ4IOXcx+UoteCwjbUIv0sV+Cbzz5Otek3BZl5qI02rt37cwtCTMZF X-Received: by 2002:a17:902:b610:b0:19a:b302:5176 with SMTP id b16-20020a170902b61000b0019ab3025176mr1491411pls.46.1676652631218; Fri, 17 Feb 2023 08:50:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676652631; cv=none; d=google.com; s=arc-20160816; b=B9tGi3Ju643MFU2cMaNJ3sdzF/Qhr9KWFtG/yquVyapnSWB5N+KDk4iZ9gcRtGpe6w 4/g7V0zg4Sl2mUlg3iBaEN8rujUOc8iF6icJHANv+TYxv+8LHopHO8Xnd7NyeIqiaG1Z IdNpKksASaok6iUsxBkWDhFGYAvfBmZKZhXgbamLBIWKJR0aarjdx46/I8ujVBAtvB0c XJPFuLuwYaNDMOplxPP2P9ucjnaGPZHrONJnwL2oFBV5YL5hS1yZJgGSm3ubYOpiFM2y JQmHAH/mLU/3GNBamIBCla8Dz4iXMU2WgqXxseeD9y/qlXouh+WY5+QeG5IFDl4qiOxW Qogg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=mhxwIafYBAkWRwUQXnopvsazox+e+UnmAiLL2GU6Nx0=; b=dQ0L9l30J1bMR2BsV8GW7AejWhRSyAsTh49h6Iuh/emAxgN3R8PbFNZvkoM4T3/eOO bbszAzkV4+a0R5Pnz3hh5K2ob/KU4x4dyELb7JliVSyRbneDYBCooHF6FI+v6KKUqf53 dpeRF4uh2ABMFZiziPZnh3mQpsv4Bzo0LFRa2sLC1MlcV7r6l6OtpNoZFh5Q65AN379e 2Os7/nrscMQa3N/uruMN0Q7ojnspN4uFeQzfkEuFQOTcnUhmpz88GMb6u8iaqMnCrpQy 7k63QfIjd6t6n0DlVkJQOzOVFD5orETgb5zVmO/4+OHo5ZpncX2TXHvx+MNn/0nUqL17 17og== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=Bkg38ebM; 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=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a17090301c400b0019abec982d2si294010plh.22.2023.02.17.08.50.18; Fri, 17 Feb 2023 08:50:31 -0800 (PST) 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; dkim=fail header.i=@mailo.com header.s=mailo header.b=Bkg38ebM; 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=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbjBQQnz (ORCPT <rfc822;aimixsaka@gmail.com> + 99 others); Fri, 17 Feb 2023 11:43:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjBQQny (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Feb 2023 11:43:54 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58A832680; Fri, 17 Feb 2023 08:43:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1676652183; bh=8n0Ms1VnNTk56gud+VEJPT9CfkFf8kiqgsa6gw0+rtE=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=Bkg38ebMftcm82eR9eZeBe6BhxhLijv/1ZIr7t4Pqsoiv8MNV8sodCN0hOVeV2H7J uwGd76HIv49bv5OqeaeaWVxz9TwcPoq1pD1y0pE8HRQcbaE6BgBec7fbBibJhy2mJc onZPbecOW2EmpEyamP6yINnS3LvfT+axKdr8HMuo= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via ip-206.mailobj.net [213.182.55.206] Fri, 17 Feb 2023 17:43:03 +0100 (CET) X-EA-Auth: ZhcQgAhY3MDn0FswqxGe2X004sgsQugLQCWPlfZj4bf0PNQk7V3TyrkGBQyeqIBHOFoV8JxZOC9Qj49IoQuHdB+af3aU/MUX Date: Fri, 17 Feb 2023 22:12:57 +0530 From: Deepak R Varma <drv@mailo.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar <ssengar@microsoft.com>, Praveen Kumar <kumarpraveen@linux.microsoft.com>, Deepak R Varma <drv@mailo.com> Subject: [PATCH] perf/x86/amd/core: Use sysfs_emit() in show() callback function Message-ID: <Y++ukV1djYTd01vy@ubun2204.myguest.virtualbox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758097709476986032?= X-GMAIL-MSGID: =?utf-8?q?1758097709476986032?= |
Series |
perf/x86/amd/core: Use sysfs_emit() in show() callback function
|
|
Commit Message
Deepak R Varma
Feb. 17, 2023, 4:42 p.m. UTC
Using sprintf/snprintf functions are error prone and suggested to be
replaced by scnprintf/vscnrptintf as outlined in this [1] LWN article.
A more recent recommendation is to use sysfs_emit() or sysfs_emit_at()
as per Documentation/filesystems/sysfs.rst in show() callback function
when formatting values to be returned to user-space. These helper
functions are PAGE_SIZE aware and wrap a safer call to vscnprintf().
[1] https://lwn.net/Articles/69419/
Issue identified using the coccinelle device_attr_show.cocci script.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
arch/x86/events/amd/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Feb 17, 2023 at 10:12:57PM +0530, Deepak R Varma wrote: > Using sprintf/snprintf functions are error prone and suggested to be > replaced by scnprintf/vscnrptintf as outlined in this [1] LWN article. > > A more recent recommendation is to use sysfs_emit() or sysfs_emit_at() > as per Documentation/filesystems/sysfs.rst in show() callback function > when formatting values to be returned to user-space. These helper > functions are PAGE_SIZE aware and wrap a safer call to vscnprintf(). > > [1] https://lwn.net/Articles/69419/ > > Issue identified using the coccinelle device_attr_show.cocci script. This Changelog fails to inform me of what the actual problem is and why the proposed solution is better. As such I cannot form an opinion on the patch and must decline. (Also, I'm not going to chase down random links on the interweb, Changelogs should be self contained)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index 4386b10682ce..47a3a841332a 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -1272,7 +1272,7 @@ static ssize_t branches_show(struct device *cdev, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", x86_pmu.lbr_nr); + return sysfs_emit(buf, "%d\n", x86_pmu.lbr_nr); } static DEVICE_ATTR_RO(branches);