From patchwork Tue Nov 15 12:04:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 20344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2680470wru; Tue, 15 Nov 2022 04:07:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf66lBP3DXwPFU6PcOia+4fSlBKDPcFoQ+3RUfy9gGRJwlz68zMPhHXNhTN7lFBCNsGWUNK3 X-Received: by 2002:a17:907:9142:b0:78d:9c18:7307 with SMTP id l2-20020a170907914200b0078d9c187307mr14915080ejs.23.1668514056375; Tue, 15 Nov 2022 04:07:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668514056; cv=none; d=google.com; s=arc-20160816; b=Ep4LlqYtMfY3oP+8O+GxaoRrRIh6wOn04meeNAuMXwHQUuxc+Jwf1WE39I6ZVwymz9 8IRxl6ny1bhTBnNSQ0g4RASnUCo4iauA6D/BBsD6+9TTZpqEBdyJAyxt8nMHEreNe9NH w+hqDug/aaHGv2Yzz7QHKSEV5/xjv8eLzM12gMHaRtJHqGsGLwD6wf/AMRU/McAhrSV0 UQoznW2XLGGn0JEhK4yMMvsPIwS+zWIk3AQoDVHysMec3Q2ScKwNbu95+sJgmQ10BIQQ d80s8x13s4RiC0eN9HYnFVOOQjItbu7ZbiKtzBde7GV5sr/E5OyWdGG6FNHBGWEwjatc aD7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=3IH0nQ6Xmt/MZMBCqvEjZB5CmZI6NT8vEOuzfRDoeOg=; b=Rfj4vY4wHlqtfSjJkLclN0lfBypo1SIEjmYpZ674syhiOG84F3ov882rUiW/y7qhI5 Tfzfu1lQYDvPqcaMubghQe6KuaIJBDqzOo74E5yFRMDygbIPf8aED4S8wNvBnaN3DOZF flZdfOM3kBuu8PelSgVzfN3LaSS+Vl9nPL+qRUcWE9QmWZBJrqzPgqC5iOHoo7PDnwxD yw/Gjb4iKwE1q973aLvbSwEifoGWM2IbyfvcL1Qk2dTwWDjzxNQbul9okmqJ2ZlyPjLl vybFgLRIaKEtzszOCN2ETSDRoOg6rMhRCQy7V0Ezc7dsqoVUzuexqn4KiKtYBePlY+lH Zihw== 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=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r16-20020a05640251d000b004677a9c4b39si9480574edd.91.2022.11.15.04.07.11; Tue, 15 Nov 2022 04:07:36 -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; 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=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238308AbiKOMGI (ORCPT + 99 others); Tue, 15 Nov 2022 07:06:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238029AbiKOMFv (ORCPT ); Tue, 15 Nov 2022 07:05:51 -0500 X-Greylist: delayed 116593 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 15 Nov 2022 04:04:55 PST Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88AE17645; Tue, 15 Nov 2022 04:04:55 -0800 (PST) Received: from mxct.zte.com.cn (unknown [192.168.251.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NBPxd6zL4z5BNRf; Tue, 15 Nov 2022 20:04:53 +0800 (CST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4NBPxc2PY2z501Qf; Tue, 15 Nov 2022 20:04:52 +0800 (CST) Received: from szxlzmapp03.zte.com.cn ([10.5.231.207]) by mse-fl2.zte.com.cn with SMTP id 2AFC4igd026858; Tue, 15 Nov 2022 20:04:44 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp04[null]) by mapi (Zmail) with MAPI id mid14; Tue, 15 Nov 2022 20:04:47 +0800 (CST) Date: Tue, 15 Nov 2022 20:04:47 +0800 (CST) X-Zmail-TransId: 2b066373805f52ffd351 X-Mailer: Zmail v1.0 Message-ID: <202211152004478289568@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , Subject: =?utf-8?q?=5BPATCH_linux-next_v2=5D_zram=3A_use_sysfs=5Femit=28=29_?= =?utf-8?q?to_instead_of_scnprintf=28=29?= X-MAIL: mse-fl2.zte.com.cn 2AFC4igd026858 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 63738065.000 by FangMail milter! X-FangMail-Envelope: 1668513893/4NBPxd6zL4z5BNRf/63738065.000/192.168.251.13/[192.168.251.13]/mxct.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63738065.000/4NBPxd6zL4z5BNRf X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY 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?1749563795095365595?= X-GMAIL-MSGID: =?utf-8?q?1749563795095365595?= From: Xu Panda Replace the open-code with sysfs_emit() to simplify the code. --- change for v2 - realign params of sysfs_emit(). --- Signed-off-by: Xu Panda Signed-off-by: Yang Yang --- drivers/block/zram/zram_drv.c | 61 ++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 9d33801e8ba8..251a142a1f0e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -255,7 +255,7 @@ static ssize_t initstate_show(struct device *dev, val = init_done(zram); up_read(&zram->init_lock); - return scnprintf(buf, PAGE_SIZE, "%u\n", val); + return sysfs_emit(buf, "%u\n", val); } static ssize_t disksize_show(struct device *dev, @@ -263,7 +263,7 @@ static ssize_t disksize_show(struct device *dev, { struct zram *zram = dev_to_zram(dev); - return scnprintf(buf, PAGE_SIZE, "%llu\n", zram->disksize); + return sysfs_emit(buf, "%llu\n", zram->disksize); } static ssize_t mem_limit_store(struct device *dev, @@ -404,7 +404,7 @@ static ssize_t writeback_limit_enable_show(struct device *dev, spin_unlock(&zram->wb_limit_lock); up_read(&zram->init_lock); - return scnprintf(buf, PAGE_SIZE, "%d\n", val); + return sysfs_emit(buf, "%d\n", val); } static ssize_t writeback_limit_store(struct device *dev, @@ -439,7 +439,7 @@ static ssize_t writeback_limit_show(struct device *dev, spin_unlock(&zram->wb_limit_lock); up_read(&zram->init_lock); - return scnprintf(buf, PAGE_SIZE, "%llu\n", val); + return sysfs_emit(buf, "%llu\n", val); } static void reset_bdev(struct zram *zram) @@ -1020,7 +1020,7 @@ static void zram_debugfs_unregister(struct zram *zram) {}; static ssize_t max_comp_streams_show(struct device *dev, struct device_attribute *attr, char *buf) { - return scnprintf(buf, PAGE_SIZE, "%d\n", num_online_cpus()); + return sysfs_emit(buf, "%d\n", num_online_cpus()); } static ssize_t max_comp_streams_store(struct device *dev, @@ -1191,12 +1191,11 @@ static ssize_t io_stat_show(struct device *dev, ssize_t ret; down_read(&zram->init_lock); - ret = scnprintf(buf, PAGE_SIZE, - "%8llu %8llu %8llu %8llu\n", - (u64)atomic64_read(&zram->stats.failed_reads), - (u64)atomic64_read(&zram->stats.failed_writes), - (u64)atomic64_read(&zram->stats.invalid_io), - (u64)atomic64_read(&zram->stats.notify_free)); + ret = sysfs_emit(buf, "%8llu %8llu %8llu %8llu\n", + (u64)atomic64_read(&zram->stats.failed_reads), + (u64)atomic64_read(&zram->stats.failed_writes), + (u64)atomic64_read(&zram->stats.invalid_io), + (u64)atomic64_read(&zram->stats.notify_free)); up_read(&zram->init_lock); return ret; @@ -1222,17 +1221,16 @@ static ssize_t mm_stat_show(struct device *dev, orig_size = atomic64_read(&zram->stats.pages_stored); max_used = atomic_long_read(&zram->stats.max_used_pages); - ret = scnprintf(buf, PAGE_SIZE, - "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n", - orig_size << PAGE_SHIFT, - (u64)atomic64_read(&zram->stats.compr_data_size), - mem_used << PAGE_SHIFT, - zram->limit_pages << PAGE_SHIFT, - max_used << PAGE_SHIFT, - (u64)atomic64_read(&zram->stats.same_pages), - atomic_long_read(&pool_stats.pages_compacted), - (u64)atomic64_read(&zram->stats.huge_pages), - (u64)atomic64_read(&zram->stats.huge_pages_since)); + ret = sysfs_emit(buf, "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n", + orig_size << PAGE_SHIFT, + (u64)atomic64_read(&zram->stats.compr_data_size), + mem_used << PAGE_SHIFT, + zram->limit_pages << PAGE_SHIFT, + max_used << PAGE_SHIFT, + (u64)atomic64_read(&zram->stats.same_pages), + atomic_long_read(&pool_stats.pages_compacted), + (u64)atomic64_read(&zram->stats.huge_pages), + (u64)atomic64_read(&zram->stats.huge_pages_since)); up_read(&zram->init_lock); return ret; @@ -1247,11 +1245,10 @@ static ssize_t bd_stat_show(struct device *dev, ssize_t ret; down_read(&zram->init_lock); - ret = scnprintf(buf, PAGE_SIZE, - "%8llu %8llu %8llu\n", - FOUR_K((u64)atomic64_read(&zram->stats.bd_count)), - FOUR_K((u64)atomic64_read(&zram->stats.bd_reads)), - FOUR_K((u64)atomic64_read(&zram->stats.bd_writes))); + ret = sysfs_emit(buf, "%8llu %8llu %8llu\n", + FOUR_K((u64)atomic64_read(&zram->stats.bd_count)), + FOUR_K((u64)atomic64_read(&zram->stats.bd_reads)), + FOUR_K((u64)atomic64_read(&zram->stats.bd_writes))); up_read(&zram->init_lock); return ret; @@ -1266,11 +1263,9 @@ static ssize_t debug_stat_show(struct device *dev, ssize_t ret; down_read(&zram->init_lock); - ret = scnprintf(buf, PAGE_SIZE, - "version: %d\n%8llu %8llu\n", - version, - (u64)atomic64_read(&zram->stats.writestall), - (u64)atomic64_read(&zram->stats.miss_free)); + ret = sysfs_emit(buf, "version: %d\n%8llu %8llu\n", version, + (u64)atomic64_read(&zram->stats.writestall), + (u64)atomic64_read(&zram->stats.miss_free)); up_read(&zram->init_lock); return ret; @@ -2504,7 +2499,7 @@ static ssize_t hot_add_show(struct class *class, if (ret < 0) return ret; - return scnprintf(buf, PAGE_SIZE, "%d\n", ret); + return sysfs_emit(buf, "%d\n", ret); } static struct class_attribute class_attr_hot_add = __ATTR(hot_add, 0400, hot_add_show, NULL);