Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1124752rdb; Mon, 4 Sep 2023 04:02:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFj1/9/YSUxNu5XL4bDP4qsyGpyLiI0WMdVvy645b1YOb5jFh3bQ3+0etmdbW8qmYx6p21E X-Received: by 2002:a05:6a20:e105:b0:151:7d4c:8997 with SMTP id kr5-20020a056a20e10500b001517d4c8997mr4841787pzb.22.1693825354462; Mon, 04 Sep 2023 04:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693825354; cv=none; d=google.com; s=arc-20160816; b=FNRoDTg1H0XM3pLxZvZOw5QEzZ8jAqPNDom3N5c6QNm8jqtamAAS/FS+CshGZYW3qk US6JT+tRNnaJgLfpdzzNQiJD0Ei4/sPFAXQVVaB6u/ZFSJkG1hDHBv90nrlW15s0oB+b lISFyJZVa5M0VjhTFa8xX+akTqz8h8wFeNVgjjRNL9HvMYidaf+cg7ZAAejgxqE6gFqR +JtF1rtTg9IIoU3nsJ5UvjRr0G/KkRQxud9V4vu8kk8VmA4mRjZRDLqm+YY2gHrBER/y gpDUqe+XN4zvXHvwjShHvykO73B1lrZ0Ai8D85f8qF+CtKgS+fDXzywCwYqMvAUHOkeX Py/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=sb0Fu2hgc5gbneaQy2WivsHjuVucaJ8G7K5Rqwboac0=; fh=m7og4B5eYCctrLkxc9cSjvs8cj9BT5n6qf42E8IHCpg=; b=nGL9+S1xK2mlowVXFaub8gbyPIE5l4Wi0DhlgEAYy9k0Ji7uPHK4ZkgKBdNzXi7P00 RGjuPhQC5mX1Bx84OceJW5g4FmKkOr/wsIyyqgsWt2iYLYcum97zi/xIGOjt9yIjxXx0 DgtFSd7yzx1hOPR9mftODbJxlXrYtvhzTIbeHSmDF0fOpGSlRxT4qqwnptz7vDAtInPh KnwrhZR3CHe5/Mt/B6qA6Rv1kPq5jAiKWepTFT8JzkQLu5/iKpIDzKAm2S2K519LQBT2 ApMGQUfqUupdAbsOQkCAcQ+EB8N2U/FJtkx2zEcHroIRcyxpm8j2CLMsGnTsnlkTuoFJ 0aAQ== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a6567d4000000b00564d938589dsi7645892pgs.326.2023.09.04.04.02.16; Mon, 04 Sep 2023 04:02:34 -0700 (PDT) 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238486AbjIDI5E (ORCPT + 99 others); Mon, 4 Sep 2023 04:57:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352604AbjIDI46 (ORCPT ); Mon, 4 Sep 2023 04:56:58 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F9A133; Mon, 4 Sep 2023 01:56:54 -0700 (PDT) Received: from dggpemm500012.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RfMrV1RfSzTm9p; Mon, 4 Sep 2023 16:54:18 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by dggpemm500012.china.huawei.com (7.185.36.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 4 Sep 2023 16:56:51 +0800 From: Xingui Yang To: , , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v5 1/3] seq_file: Add helper macro to define attribute for rw file Date: Mon, 4 Sep 2023 08:48:02 +0000 Message-ID: <20230904084804.39564-2-yangxingui@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230904084804.39564-1-yangxingui@huawei.com> References: <20230904084804.39564-1-yangxingui@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500012.china.huawei.com (7.185.36.89) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, 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 We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute for read-only file, but many of drivers want a helper macro for read-write file too. So we add DEFINE_SHOW_STORE_ATTRIBUTE helper to reduce duplicated code. Signed-off-by: Luo Jiaxing Signed-off-by: Xingui Yang --- include/linux/seq_file.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index bd023dd38ae6..e400007e410c 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -207,6 +207,21 @@ static const struct file_operations __name ## _fops = { \ .release = single_release, \ } +#define DEFINE_SHOW_STORE_ATTRIBUTE(__name) \ +static int __name ## _open(struct inode *inode, struct file *file) \ +{ \ + return single_open(file, __name ## _show, inode->i_private); \ +} \ + \ +static const struct file_operations __name ## _fops = { \ + .owner = THIS_MODULE, \ + .open = __name ## _open, \ + .read = seq_read, \ + .write = __name ## _write, \ + .llseek = seq_lseek, \ + .release = single_release, \ +} + #define DEFINE_PROC_SHOW_ATTRIBUTE(__name) \ static int __name ## _open(struct inode *inode, struct file *file) \ { \ -- 2.17.1