Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1099926pxx; Fri, 30 Oct 2020 01:54:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmmlZs2njNMlFWkS2cvXnNlDK/sM8gY0Sl3hKvVLyJjRQjquQ3MeADJ3KmIxFQ3GoZNXEF X-Received: by 2002:aa7:d890:: with SMTP id u16mr1138689edq.159.1604048050249; Fri, 30 Oct 2020 01:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604048050; cv=none; d=google.com; s=arc-20160816; b=HW9DX4xSjfd4nGQASuFcsccQUajUry6uO5qIa73f8TiLkHAmig3DfvTB3yRhodrYgE /dX9xRebnMI5LEqAAcx1I94g5yptHAjUNn+iii03f7s4TmiufqRZ1zzEh4ZAoNJWD9O3 W5ZFiYm6TW09owXmiMAkoqDoWWSbVnkx7Th/NH+TQdBgVlONZKrSBbRQqW89pz80+4il dJQsPMF3ykj5YYQSnjgL/2SpXbsL7YAQ8pXiVeY2AqdCgDYkRjm3tYOgHswiXXdD3uWD mgJdYKRHNs2YKRgRmllmgetQwgNuncAOcWDAlLrfCAXNRwuTSaYle68uClEpF5j344OD PPwA== 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=tEuo1WexfA/eO/Y8p2sZkrSw01JdEYOMxlQyw3rvod4=; b=cN79e2TsaE74DJSfRAjV0Oq7VU3zfCPKuPpgpTQlG+fRfUl0rTVB2Zni3qklgln2xq sR7Xer8CRvLGJNLwq8zA0OfZbhRvpiBJ3hYxrM1hdV3NZdi2DyWVIdhQiHiFDhK4lN22 RwT37j+4NaYkgwUJkVF2r1337q4Y6LfSU7lXmUYn/hQbOLYQR/KtxE8pgzSPr+JZQjau ejVmujDKLVksJhDuMCZFHalOlVmXurUhSDOi7bVVi32iaRKJYv+9drVuk2cfB4o0lxaN NVHODRC1kNNuMtzoTkdpFrs1QpavxaHFnayqNfzI+i93tGYgE4GQ0ELmAz7dVx5nQ/3S K0KQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t6si3648478ejf.462.2020.10.30.01.53.47; Fri, 30 Oct 2020 01:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726213AbgJ3Iuo (ORCPT + 99 others); Fri, 30 Oct 2020 04:50:44 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:6943 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbgJ3IuY (ORCPT ); Fri, 30 Oct 2020 04:50:24 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CMwWp0wLDz70S0; Fri, 30 Oct 2020 16:31:34 +0800 (CST) Received: from huawei.com (10.69.192.56) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Fri, 30 Oct 2020 16:31:24 +0800 From: Luo Jiaxing To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 1/5] seq_file: Introduce DEFINE_SHOW_STORE_ATTRIBUTE() helper macro Date: Fri, 30 Oct 2020 16:31:58 +0800 Message-ID: <1604046722-15531-2-git-send-email-luojiaxing@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1604046722-15531-1-git-send-email-luojiaxing@huawei.com> References: <1604046722-15531-1-git-send-email-luojiaxing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected 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 we found many of drivers want a helper marco for read-write file too. So we try to make one to decrease code duplication. Signed-off-by: Luo Jiaxing --- 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 813614d..8a474c8 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -191,6 +191,21 @@ static const struct proc_ops __name ## _proc_ops = { \ .proc_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, \ +} + static inline struct user_namespace *seq_user_ns(struct seq_file *seq) { #ifdef CONFIG_USER_NS -- 2.7.4