From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Marcel Holtmann <marcel@holtmann.org>,
Johan Hedberg <johan.hedberg@gmail.com>,
linux-bluetooth@vger.kernel.org,
"David S . Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, Randy Dunlap <rdunlap@infradead.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro
Date: Thu, 23 Nov 2017 22:36:04 +0200 [thread overview]
Message-ID: <20171123203605.44954-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20171123203605.44954-1-andriy.shevchenko@linux.intel.com>
The DEFINE_SHOW_ATTRIBUTE() helper macro would be useful for current
users, which are many of them, and for new comers to decrease code
duplication.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/seq_file.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index c32929802c25..73adc12ab773 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -144,6 +144,19 @@ void *__seq_open_private(struct file *, const struct seq_operations *, int);
int seq_open_private(struct file *, const struct seq_operations *, int);
int seq_release_private(struct inode *, struct file *);
+#define DEFINE_SHOW_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 = { \
+ .open = __name ## _open, \
+ .read = seq_read, \
+ .llseek = seq_lseek, \
+ .release = single_release, \
+} \
+
static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
{
#ifdef CONFIG_USER_NS
--
2.15.0
next prev parent reply other threads:[~2017-11-23 20:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-23 20:36 [PATCH v2 0/2] seq_file, Bluetooth: introduce DEFINE_SHOW_ATTRIBUTE() Andy Shevchenko
2017-11-23 20:36 ` Andy Shevchenko [this message]
2017-11-28 8:43 ` [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro Marcel Holtmann
2017-11-28 12:19 ` Andy Shevchenko
2017-11-28 12:19 ` Andy Shevchenko
2017-12-13 15:38 ` Andy Shevchenko
2017-11-23 20:36 ` [PATCH v2 2/2] Bluetooth: Re-use DEFINE_SHOW_ATTRIBUTE() macro Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171123203605.44954-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=netdev@vger.kernel.org \
--cc=rdunlap@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.