Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5436919pxu; Thu, 22 Oct 2020 02:11:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysKRLF740WKCC/WqZ3CPFfW4mUxYIwNVHUNHQZfrJ5I0Aevieuw7loXZb0P7jQeWObOgrZ X-Received: by 2002:a17:906:c095:: with SMTP id f21mr1426031ejz.108.1603357891665; Thu, 22 Oct 2020 02:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603357891; cv=none; d=google.com; s=arc-20160816; b=Ba2W4bWNdQEo09DGlvoW6bRNnq3RQMv0mlNouAbCXHjDnwJF/SheGh/3rb26O53qba uTO1rHV4eMOBDZaXSgD0+n5kxa+gQX8+46oHIaW5bJpSE2c5UaGqeFA+ce0vA8kxmHdQ 8Tj+dKQ2YVCjTFP/M2exBCqRolsvqJp2mQOFP7rNZbtV+woX4w31fB/47mo529WPsp6c gv7G1PGzhvF2BWl/AQ+BiEm8F83XuKUE3pXCkAUi+/Kx1ea4YBxzlGZJOtFL3XHfYlH4 XS2oNk8KHfUYOLHkCHCOM043+7i7E1xSb/QED+2rQq+Qp/ixJ6v0lUGWmkBk+HWsdrzB MLmQ== 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=JZ+cGvP+WDpyDM5wSMoH9jyEd+7qeexQU3Y/l5hSLbk=; b=PyfPPdT4/6ipA117qarzA0oGeXuBIJkJz0gCRaibrUnUO9SH5jfYsg2fpMwDoefAPy Ge/pjJ/7wkHWatJCr9X4Yr00rD8lCOIuG5ltNUybfb6ZxDx0P73meHhAhsv7Fb2u8W08 pwLEt2VCdOpa+loVz4/OG/JaLvc5w3a/iNuR93SyCbrPhGxxF5rDKDRs17eJp5XSQ6Q7 QAYRWfr5axNRzR12jdgpKV1bT2FlqUPSwFpYSL0uV0leDKw75hgD02cc+hT6/joau5Bj kZK76UmFt1pi/Q9Xt3Kf9j9dSQJdy1Y8knPvd2+/Js8LEb4+5Efsb5O/47mFlCSCHNC3 VTOQ== 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 k2si472772eje.85.2020.10.22.02.11.09; Thu, 22 Oct 2020 02:11:31 -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 S2509407AbgJVIj2 (ORCPT + 99 others); Thu, 22 Oct 2020 04:39:28 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15762 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2508298AbgJVIj1 (ORCPT ); Thu, 22 Oct 2020 04:39:27 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 659406A8CB4F4D55BBB2; Thu, 22 Oct 2020 16:39:24 +0800 (CST) Received: from huawei.com (10.69.192.56) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Thu, 22 Oct 2020 16:39:15 +0800 From: Luo Jiaxing To: , , CC: , , , , , , , , , , , Subject: [PATCH v1 1/5] seq_file: Introduce DEFINE_STORE_ATTRIBUTE() helper macro Date: Thu, 22 Oct 2020 16:39:53 +0800 Message-ID: <1603355997-32350-2-git-send-email-luojiaxing@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1603355997-32350-1-git-send-email-luojiaxing@huawei.com> References: <1603355997-32350-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..3b3b797 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_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