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: 13145051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D7DAFC05027 for ; Fri, 17 Feb 2023 17:12:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=rNSUEoxahvv+JV89GjypWGeWHF2QET1KNtT/X4hjyeQ=; b=2wbzpCj+zhhvBX ZwiPgHhfhmhomBd2iwvwCUhxGAtQ5cI/HGrayg5urkTH49RbLm04REdWKvTmCvzhjt39rdoS42YiN gYS1H0MH67moxRriy/Dz72pTNFX/2crFeRAQkIK4+OZpbMRJXIx2jE4Vv4juY5nrTgS/SUzQHBHVz VQx1doIQfnhZnLz1lqcAJyK8kNl5N2FqWE1J26KWoiS8MXShklud7X+kYbmrpUcC0SMUPbeF8pdg8 7PY3p0Q8sz+yc74kdIMDGFEMvgeV10ZT/OAvSLxJ3DozCiJTvLeh5fKSKyl1xOnSmjfuomCr205/R luhF1zbYoQ/WFd9/Y3Ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pT4GP-00FBkH-6B; Fri, 17 Feb 2023 17:11:13 +0000 Received: from msg-2.mailo.com ([213.182.54.12]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pT4GI-00FBjH-Dq for linux-arm-kernel@lists.infradead.org; Fri, 17 Feb 2023 17:11:10 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230217_091106_909538_CF8AD6A4 X-CRM114-Status: GOOD ( 11.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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,