From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86D8BC433DF for ; Thu, 4 Jun 2020 23:51:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 443C620B80 for ; Thu, 4 Jun 2020 23:51:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="iaGv9rsr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 443C620B80 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DFCBB28005F; Thu, 4 Jun 2020 19:51:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D86D3280005; Thu, 4 Jun 2020 19:51:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C77BE28005F; Thu, 4 Jun 2020 19:51:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id A7617280005 for ; Thu, 4 Jun 2020 19:51:07 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6E417180AD802 for ; Thu, 4 Jun 2020 23:51:07 +0000 (UTC) X-FDA: 76893177774.19.frog48_061306226d9b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 532FA1AD1B5 for ; Thu, 4 Jun 2020 23:51:07 +0000 (UTC) X-HE-Tag: frog48_061306226d9b X-Filterd-Recvd-Size: 3888 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Jun 2020 23:51:06 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C9F552067B; Thu, 4 Jun 2020 23:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591314666; bh=bpRZnYvqY6yQRewlLRGsT3+H39OJK8bYylakn/ZV4ck=; h=Date:From:To:Subject:In-Reply-To:From; b=iaGv9rsrbFjn+OQdoZML0Sa7OGw+EckTZabZ5q9A1jAwZiwfwoEMLrtvcF3vkwzWr O2c1wCoY0LNmPLn4HASqPv1ffyBzQ9OQlHosPgKqTPGbbYR3jMEVC6UEQhP2ST3G3S HSU2SpnQlToGORNlutzcilvuZY0h4HROW38dxxqw= Date: Thu, 04 Jun 2020 16:51:05 -0700 From: Andrew Morton To: akpm@linux-foundation.org, anil.s.keshavamurthy@intel.com, davem@davemloft.net, gregkh@linuxfoundation.org, linux-mm@kvack.org, mhiramat@kernel.org, mingo@kernel.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, wangkefeng.wang@huawei.com Subject: [patch 093/127] include/linux/seq_file.h: introduce DEFINE_SEQ_ATTRIBUTE() helper macro Message-ID: <20200604235105.3xun8HesA%akpm@linux-foundation.org> In-Reply-To: <20200604164523.e15f3177f4b69dcb4f2534a1@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 532FA1AD1B5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Kefeng Wang Subject: include/linux/seq_file.h: introduce DEFINE_SEQ_ATTRIBUTE() helper macro Patch series "seq_file: Introduce DEFINE_SEQ_ATTRIBUTE() helper macro". As discussed in https://lore.kernel.org/lkml/20191129222310.GA3712618@kroah.com/, we could introduce a new helper macro to reduce losts of boilerplate code, vmstat and kprobes is the example which covert to use it, if this is accepted, I will send out more cleanups. This patch (of 3): Introduce DEFINE_SEQ_ATTRIBUTE() helper macro to decrease code duplication. [akpm@linux-foundation.org: coding style fixes] Link: http://lkml.kernel.org/r/20200509064031.181091-1-wangkefeng.wang@huawei.com Link: http://lkml.kernel.org/r/20200509064031.181091-2-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang Cc: Greg KH Cc: Ingo Molnar Cc: Kefeng Wang Cc: Anil S Keshavamurthy Cc: "David S. Miller" Cc: Masami Hiramatsu Cc: Al Viro Signed-off-by: Andrew Morton --- include/linux/seq_file.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/include/linux/seq_file.h~seq_file-introduce-define_seq_attribute-helper-macro +++ a/include/linux/seq_file.h @@ -145,6 +145,25 @@ void *__seq_open_private(struct file *, int seq_open_private(struct file *, const struct seq_operations *, int); int seq_release_private(struct inode *, struct file *); +#define DEFINE_SEQ_ATTRIBUTE(__name) \ +static int __name ## _open(struct inode *inode, struct file *file) \ +{ \ + int ret = seq_open(file, &__name ## _sops); \ + if (!ret && inode->i_private) { \ + struct seq_file *seq_f = file->private_data; \ + seq_f->private = inode->i_private; \ + } \ + return ret; \ +} \ + \ +static const struct file_operations __name ## _fops = { \ + .owner = THIS_MODULE, \ + .open = __name ## _open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = seq_release, \ +} + #define DEFINE_SHOW_ATTRIBUTE(__name) \ static int __name ## _open(struct inode *inode, struct file *file) \ { \ _