From patchwork Fri Feb 17 17:10:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 58728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1012503wrn; Fri, 17 Feb 2023 09:26:14 -0800 (PST) X-Google-Smtp-Source: AK7set+vqZ3lI1hZTNRxqJwBj4S14gdXvcudRYK4UegkUTakkNQ/barwRODGs0E3yxvP+ufPqfSG X-Received: by 2002:a05:6402:1484:b0:4ad:7055:3908 with SMTP id e4-20020a056402148400b004ad70553908mr4757463edv.21.1676654774789; Fri, 17 Feb 2023 09:26:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676654774; cv=none; d=google.com; s=arc-20160816; b=rW0gKgtjMoCBgM1VKISmdksvoquCXnGszFH21N2glr1qiix/CTVZy4WLy5UYJBu9yr 9MEUrtY2ZVS7CXULtmN2HgCHmMHdbFL5ubLDhnHs9aq4/0B0d6sRcqfr5qHaTnV0ahXZ CmWwc9QljhBVn1jGSBO9EXznkX3ylkbPhGNDLtfOYwLQXO7wZnvoDureVDx5Z/KvGL5o J2nO6KP7JPMSHXxGYPA6mXee/XAtAAuM5YBjv+v3vMzvVxcr4sln+ce27Tw/ftiKsipr LjgYE/1WLnYi2eVWLF2GywzgMWNcmxaSwihSoaI8ioBpcrGf7ph6iNHQtCSEzSlJjSEt BDfQ== 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=PMUtA5QEkGEg+5+atiJ9AQ9gqqhsNU4fhlkO2Th87gE=; b=v8X03x0ty/mu9JmcBSgkGr72zZprXSGp/0zppJWLBm2X1TKEgdIRoBNl1i+zYgz0lA QrKQGiJRR/U4NUCRlFbv+OEMHM/gBzc9BtLC85+55yH2n0f1mRu/jsXzZggUed9pblMK IYwc+/IEbLRnxQSR1PSHrR3p7nzAUmGxL6oqGeTD/+G06YPCbXwh/X6PGoZ5ZbrGY+ox AZLO2FTQVvZ3Me8F5ezm0Vjj7TAxeDJnEaTTkm8QHDYv8WbpFR6V1C6MYDiEgKNCZLMq OAmqayl0e0gTH9sIzBB+wnXlJ0PA2qgorFeI/9qaTFgNhN6qcAgnigfL8Qor162AbNi/ tL2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=cZK2uMz8; 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 z22-20020aa7d416000000b004ace603c65csi5619196edq.247.2023.02.17.09.25.31; Fri, 17 Feb 2023 09:26:14 -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=cZK2uMz8; 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 S229647AbjBQRLQ (ORCPT + 99 others); Fri, 17 Feb 2023 12:11:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjBQRLO (ORCPT ); Fri, 17 Feb 2023 12:11:14 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CAF76ABFF for ; Fri, 17 Feb 2023 09:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1676653855; bh=1lHaTXrcGvk9qzJbf3HZv/4v4UAIzF/XJctBCsi93EU=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=cZK2uMz855tfXzoCdGS6KD19K0Iyo5OQUqBIp8rlzR8N+HIyG4+qT5L6pKdqKyQCH L7J83ArjGOWY+xAypD+ikuq9KcziVgfcbHQKqV2NApKLpJ2Yj+AekfJ1T5BJ8uV4g6 lYZ9ZU/QPVe7WV/uBeIwl8vol9SC204+KBOx97/c= Received: by b-5.in.mailobj.net [192.168.90.15] with ESMTP via ip-206.mailobj.net [213.182.55.206] Fri, 17 Feb 2023 18:10:55 +0100 (CET) X-EA-Auth: 95fLD2RuWA+XCYTLFGyfARPmdWcBY3bcSw4kET3KnsvoY7D824dypTu6jXXxHfxxEry6KfPKbpCXSjrXN2fBSelkNN9EVdLg Date: Fri, 17 Feb 2023 22:40:49 +0530 From: Deepak R Varma To: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH] arch/arm/l2x0: Use sysfs_emit() in show() callback function Message-ID: MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758099956953399756?= X-GMAIL-MSGID: =?utf-8?q?1758099956953399756?= 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 --- Please note: 1. Change compile tested using sama7_defconfig 2. The driver name in the patch subject is best derived out of the 5 unique names available for the current committed patches. If this is incorrect, please suggest what it should be set to. arch/arm/mm/cache-l2x0-pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mm/cache-l2x0-pmu.c b/arch/arm/mm/cache-l2x0-pmu.c index 993fefdc167a..a9bd05b82003 100644 --- a/arch/arm/mm/cache-l2x0-pmu.c +++ b/arch/arm/mm/cache-l2x0-pmu.c @@ -343,7 +343,7 @@ static ssize_t l2x0_pmu_event_show(struct device *dev, struct l2x0_event_attribute *lattr; lattr = container_of(attr, typeof(*lattr), attr); - return snprintf(buf, PAGE_SIZE, "config=0x%x\n", lattr->config); + return sysfs_emit(buf, "config=0x%x\n", lattr->config); } static umode_t l2x0_pmu_event_attr_is_visible(struct kobject *kobj,