From patchwork Thu Nov 24 16:12:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 25629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3488025wrr; Thu, 24 Nov 2022 08:15:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf7J3SLr/nXUhbXcrOlX2v05gItbFjOu7i/8ROpM4pkykFUJ+GIEVY3wcWnE2FJZX2pvr8AF X-Received: by 2002:a17:906:2650:b0:7b2:c004:55fe with SMTP id i16-20020a170906265000b007b2c00455femr23149727ejc.742.1669306525369; Thu, 24 Nov 2022 08:15:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669306525; cv=pass; d=google.com; s=arc-20160816; b=J2pvkJFHtVI6hSJepUOW8NcKT1TU5V+GPrAa/pkenVEGWFa8FFB/EuSEpd1f+AIEO1 0kq6bXgr5l9BObIA6UaYQm3fAbMBI/5eqEjIrS7GgIvplZzKcgJVISpoJr+TBwDUxvN4 EWYuXuGTNRjPc08zgUXWyvY3cOZz6ApIXhhaz5PQlqoRmgbHqwhv3AGNRM62+8wF70S9 +yUmbzgisO7lSprfSgc8BzL0m0UWvHpNkYqQyCJhcqloDz02A93OxMyCVuVqQmmGD1h0 ufIvUMHmVmQM/PYkA89Vs9YPdwMSSbplutL+ThpRz3ZQfrD5wTem69pyVR3rNGayrzHT yW3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=7oSy9yQZH5R5/p4/8fEIlcDnnh2H6/yjKN583nHGNJs=; b=r27d7bOnhL7eYcUdYw9qITVm23tty8VKYY0QZoQq0fpq7JokDr2njkVz4fDOz5te+5 R+3dTLqSJcSTc6RiHKKrg6ZgtdGsiq+lZQ3ly3nJ1HwIfuMDARIk/IPA1od69SZPpyQg Lxr7uI3mtGoX0ymjVkychRbkPZjaZlUwT2AbWzOg3Jttmm2o8pyDIbfu2bYp3SkSr6mh apfL2nxI8TT2G31kdo6jRbhNntn783ekvWvHn8qHzwawXKGsmt9UvDLx2Ikdkc98g0ee GheDL69SHQqr5X5kY/WU2eivU9xEgAxECSRGLtHJAY5DZTWbmO5GlxUnX18ImsS9fBIo JmkA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=VAMSvUat; arc=pass (i=1); 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa3-20020a170906fd8300b007adb6459e64si894708ejb.862.2022.11.24.08.15.00; Thu, 24 Nov 2022 08:15:25 -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=pass header.i=@outlook.com header.s=selector1 header.b=VAMSvUat; arc=pass (i=1); 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229687AbiKXQMl (ORCPT + 99 others); Thu, 24 Nov 2022 11:12:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbiKXQMh (ORCPT ); Thu, 24 Nov 2022 11:12:37 -0500 Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01olkn2084.outbound.protection.outlook.com [40.92.99.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5446A31DC5 for ; Thu, 24 Nov 2022 08:12:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Asj9lJu6wj8MqB7mcX5RnaZtGAKfCnNSf+IENN8Arrk79z83OOg0km4IkmF6LP0TXZ0FBRzmYeBJB1RroWcVkNpoM4OWtqoK6vXvm3bjXwwfmfzGYEgbJhG6cSYo49VL2nIIUVdE5HQduCUGMCfyk+YmXMbzi4LZs2XlOmWYxAyUs5VJLSsPqqNJIEYVw9hTIfdXstm7/vKpVF567BshQ76Nxw/ktmT+xjR6Cr6cbfHHP7sO0+U8/hWYf1WEKkU0i60/sU4Luz7YKzsOYvr3/vXfmSi6mxPyPEipjufYXTQr48MY7kits8MLYfAAYdKJSJ32zYIGBgul5hwPDTipZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7oSy9yQZH5R5/p4/8fEIlcDnnh2H6/yjKN583nHGNJs=; b=IJJUaWjKC3DxrnGvCvR40XgUj4AMRk8p0vp3Qqffm3/Y0/RoD4/62PkWSXvWX2hiGqsBu0ycLyhagsJNZNq0PiZsgEpbR/Iz9P2MMvOLTPfmuWLZzW0j9oBuf2L3CVUjgdF2Mvrb1TupYNMbdrTSOjjhgwkWwuq3h5UCSUMZbKNVeCTYc9ZATVWD7zOcThPZqEyKKkUDJVIu5KFR9qsz0tdvPPxoL5LdtREY/lQgIgQqnGsSKWTfBVplDeX0tdq9A7rLVydVSeV1DfxwnFrszGPA6bMT5pK/9WCMG32vB/2ZW6YrPih6eGgj4SLVgnLFTIkGoyNGUbC0t8d54XTwgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7oSy9yQZH5R5/p4/8fEIlcDnnh2H6/yjKN583nHGNJs=; b=VAMSvUatEb/TGKnSZ52p0ptF1gq7vTVb/UCO6bl5fdezfYNEeHAaeEoMcKKTv6kVk9RT0ZwxeaEujjLsvIKxisU6tJC9jm2FatlCazPepocUuGf1BM10TEoP5y35N7kd3kJeG3/+wnja5lpTAYRu17nWVxl2pMRZTzXy3lUygKWexbAmq6S0p5ZHLcy1a5oICW0QAbQcqhNq6NPXA18UuwxL3lSSaMM8osOq5EoT/56lC30bv+1YWE/K/UjSgWDv4ivSRnXBGBgj0pBofsJUJFk4z4McMcLLoHxVcSbKOSsQg/n9am4pNlTlial0cd7uAyqH/mfQT/yKT7mRRnRYkA== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by TY3P286MB2500.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:22d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.19; Thu, 24 Nov 2022 16:12:30 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605%4]) with mapi id 15.20.5834.015; Thu, 24 Nov 2022 16:12:30 +0000 From: Dawei Li To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH v2] virtio: Implementing attribute show with sysfs_emit Date: Fri, 25 Nov 2022 00:12:14 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [f5yVnEJd0MoYagV/6DprvozslHZppvEUe5x30n5CTeY=] X-ClientProxiedBy: TY2PR04CA0009.apcprd04.prod.outlook.com (2603:1096:404:f6::21) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20221124161214.6852-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|TY3P286MB2500:EE_ X-MS-Office365-Filtering-Correlation-Id: 4caaca33-57af-42ec-f96f-08dace36afc9 X-MS-Exchange-SLBlob-MailProps: a+H6FLLcF3pgf3IU6ogmyh93lLTDqxb2nEJRI+uM4TUnxu1qVOs6TNMz0OE4UBF7oStf0KWX4qCzJ7nC//dw/Egi0ePVUQtpnnRslIkB+7tB86WfVQXQUudN9BeohT/Q9IDs80Jm6qhfYEFMkBaFZ5hMIl8IkvUuYAIVGCB6onA69Db5pngi/OU6XQAfk7t9icdjVP27B0sCd45/70Ty1QAdQlg6bfOHAqnfsrJpy2hrQhrsSwowww7fgr+fH/0rykkHk3mhzl+jh6iyzr1g+NVrajtHTxVMOEcN9pwuQfsr0FSi1BMBfwyZ/9obzhQf06cnMR+kGTA4PBO97av/7/K0d69OK1M4AP5kf/m1dFJ3KyMCVMIO7sa+oCfrHxlNMvmnxBwFW8Hm0cMhAVtFAURGimI2eQgDkdOJT/WWyB30Nr/4rntYXhuOSTbot72sQrly35S1243u2gYIE2Dj9Rf6Sh9gsQ51q1fJLXMJm1mQZ9km3bI7SdA1xRYcvB2fLrCDDzYjpnUGbDd5EGiPUzQPQ5cL3hKfZ255i2wCdMzq3mS2i/nwRoshSAwtw432nkOIl7QtNvzhn8RzjEBy7M4/QZ83LUNmeM2C8/AAm3BW3upevBPEe35s3Q+h/TxY242SaWIil0xvENdd/fI6eejrUT8igvgcvUADsKgOQw1k0BE+USLoUM0mAZq1/OiR1dsL6kqkGIki9PU/n5aQKGkVap8wf7kTdQ+h1h2F19uBS1bwehIUf9YGBYmcCtgawyWQyBn0HYhrEDtAJTsBQxmBggeKhi+zIk1pystyZZVN5eXJ20rKM0NVvM198lia X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OuiwWyH4Dx2NnIa4Uw9thKLs9y2dEJrwQPrH3/Z7iAyNs4t1EttRrfLnmcLilHT+QyHQ8foOZPA6SDbf+5r+4xp+6GtENfqt5MJj2w1UAMjatlfni62yzm03y/df7UDhmUu6E23jjpVBFi1haGrxP/U405KAsQXhc8ja5/hnNeWIFSoBIEAO4VM46wORFr1/tUtAGrS76uWhC0Pp5j/kHAYuZq62LZRAheq6yfpRARTp0vtm2kj79FIEKOk0WqwO+wDaPLh/Y1TKC3Pr4ZGy7uwVEo+qMvhEbILKlR0jHGkXSmzqySkHkKbnt1vo0YTtH9hO6zKfUqlwfv5mc8k2vjt2bOpjtjVxg+lhZK2U5ynPRg4R6K517MILfjJQxu4HS7SKJ7eJQA+sEyw/lNlUXyz8igRZ8cs4toE4JI71EGrFrrcyMbLv82Azvu2GX/+M3ifY9Y7l/qyVP7E97GZEdlKdj1qoPrWFILGCYBm6qb3HYvgnAi2vcdp6dOzXPXasdxmNZGVHZl3Xol6zewSqjVQBO4zfFtv261aKLuxb+m0z33J/80igE9lnerwk4wF+f4xy/gKXx/nDdB7tcUlUO2h+QWIZosjvSDoR+dCi7r2zW9CchBm/8E4PfoyuO2J8hTQljnw6A6QKk+/O/T+N+g== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tAimtW9hkAtkO5XW8nnoPts9gksx+SVEhtKN/2cTE0ctbmKl3mRj2GizS15Vxd7hSx/nU3mGyCqxMrj8/o5MlWXB/y349u1kvgSNwVjMN0CulITWw9O0XFUgy76KnGSxj1zTP2QG3LQiUlo+JVbnOE+L3O7FIjWgwpjrMOBjfe77SFxOGZ5P6zlpfKHWk/HASDLLVw1oiMrI6kc65cwXcJ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G2SRoD5HIRkqc1ynuCPjbOwq4sTFtjj6UC3g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4caaca33-57af-42ec-f96f-08dace36afc9 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2022 16:12:30.1807 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB2500 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,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?1750394759389684199?= X-GMAIL-MSGID: =?utf-8?q?1750394759389684199?= Replace sprintf with sysfs_emit or its variants for their built-in PAGE_SIZE awareness. Signed-off-by: Dawei Li --- v1->v2: - Remove callback sanity check. v1: - https://lore.kernel.org/all/TYCP286MB23234D3251765359630AD72ECA0C9@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM/ drivers/virtio/virtio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 828ced060742..b9a80aedee1b 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -15,7 +15,7 @@ static ssize_t device_show(struct device *_d, struct device_attribute *attr, char *buf) { struct virtio_device *dev = dev_to_virtio(_d); - return sprintf(buf, "0x%04x\n", dev->id.device); + return sysfs_emit(buf, "0x%04x\n", dev->id.device); } static DEVICE_ATTR_RO(device); @@ -23,7 +23,7 @@ static ssize_t vendor_show(struct device *_d, struct device_attribute *attr, char *buf) { struct virtio_device *dev = dev_to_virtio(_d); - return sprintf(buf, "0x%04x\n", dev->id.vendor); + return sysfs_emit(buf, "0x%04x\n", dev->id.vendor); } static DEVICE_ATTR_RO(vendor); @@ -31,7 +31,7 @@ static ssize_t status_show(struct device *_d, struct device_attribute *attr, char *buf) { struct virtio_device *dev = dev_to_virtio(_d); - return sprintf(buf, "0x%08x\n", dev->config->get_status(dev)); + return sysfs_emit(buf, "0x%08x\n", dev->config->get_status(dev)); } static DEVICE_ATTR_RO(status); @@ -39,7 +39,7 @@ static ssize_t modalias_show(struct device *_d, struct device_attribute *attr, char *buf) { struct virtio_device *dev = dev_to_virtio(_d); - return sprintf(buf, "virtio:d%08Xv%08X\n", + return sysfs_emit(buf, "virtio:d%08Xv%08X\n", dev->id.device, dev->id.vendor); } static DEVICE_ATTR_RO(modalias); @@ -54,9 +54,9 @@ static ssize_t features_show(struct device *_d, /* We actually represent this as a bitstring, as it could be * arbitrary length in future. */ for (i = 0; i < sizeof(dev->features)*8; i++) - len += sprintf(buf+len, "%c", + len += sysfs_emit_at(buf, len, "%c", __virtio_test_bit(dev, i) ? '1' : '0'); - len += sprintf(buf+len, "\n"); + len += sysfs_emit_at(buf, len, "\n"); return len; } static DEVICE_ATTR_RO(features);