mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: Tony Luck <tony.luck@intel.com>
Cc: Greg Kroah-Hartman <greg@kroah.com>,
	"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Borislav Petkov <bp@alien8.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 1/5] drivers/base: Add a DEVICE_BOOL_ATTR macro
Date: Thu, 25 Oct 2012 16:17:43 +0200	[thread overview]
Message-ID: <1351174667-5098-2-git-send-email-bp@amd64.org> (raw)
In-Reply-To: <1351174667-5098-1-git-send-email-bp@amd64.org>

From: Borislav Petkov <bp@alien8.de>

... which, analogous to DEVICE_INT_ATTR provides functionality to
set/clear bools. Its purpose is to be used where values need to be used
as booleans in configuration context.

Next patch uses this.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Borislav Petkov <bp@alien8.de>
---
 drivers/base/core.c    | 21 +++++++++++++++++++++
 include/linux/device.h |  7 +++++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index abea76c36a4b..c8ae1f6b01b9 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -171,6 +171,27 @@ ssize_t device_show_int(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(device_show_int);
 
+ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
+			  const char *buf, size_t size)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+
+	if (strtobool(buf, ea->var) < 0)
+		return -EINVAL;
+
+	return size;
+}
+EXPORT_SYMBOL_GPL(device_store_bool);
+
+ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+
+	return snprintf(buf, PAGE_SIZE, "%d\n", *(bool *)(ea->var));
+}
+EXPORT_SYMBOL_GPL(device_show_bool);
+
 /**
  *	device_release - free device structure.
  *	@kobj:	device's kobject.
diff --git a/include/linux/device.h b/include/linux/device.h
index 86ef6ab553b1..50c85a26b003 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -496,6 +496,10 @@ ssize_t device_show_int(struct device *dev, struct device_attribute *attr,
 			char *buf);
 ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
 			 const char *buf, size_t count);
+ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
+			char *buf);
+ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
+			 const char *buf, size_t count);
 
 #define DEVICE_ATTR(_name, _mode, _show, _store) \
 	struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
@@ -505,6 +509,9 @@ ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
 #define DEVICE_INT_ATTR(_name, _mode, _var) \
 	struct dev_ext_attribute dev_attr_##_name = \
 		{ __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
+#define DEVICE_BOOL_ATTR(_name, _mode, _var) \
+	struct dev_ext_attribute dev_attr_##_name = \
+		{ __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) }
 #define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
 	struct device_attribute dev_attr_##_name =		\
 		__ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
-- 
1.8.0


  reply	other threads:[~2012-10-25 14:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-25 14:17 [PATCH 0/5] Rework MCA configuration handling code, v2 Borislav Petkov
2012-10-25 14:17 ` Borislav Petkov [this message]
2012-10-25 16:07   ` [PATCH 1/5] drivers/base: Add a DEVICE_BOOL_ATTR macro Greg Kroah-Hartman
2012-10-25 16:33     ` Borislav Petkov
2012-10-25 16:43       ` Greg Kroah-Hartman
2012-10-25 14:17 ` [PATCH 2/5] x86, MCA: Convert dont_log_ce, banks and tolerant Borislav Petkov
2012-10-25 14:17 ` [PATCH 3/5] x86, MCA: Convert rip_msr, mce_bootlog, monarch_timeout Borislav Petkov
2012-10-25 14:17 ` [PATCH 4/5] x86, MCA: Convert the next three variables batch Borislav Petkov
2012-10-25 14:17 ` [PATCH 5/5] x86, MCA: Finish mca_config conversion Borislav Petkov
2012-10-25 16:50 ` [PATCH 0/5] Rework MCA configuration handling code, v2 Luck, Tony
2012-10-25 16:52   ` Borislav Petkov
  -- strict thread matches above, loose matches on Subject: below --
2012-10-17 11:13 [PATCH 0/5] Rework MCA configuration handling code Borislav Petkov
2012-10-17 11:13 ` [PATCH 1/5] drivers/base: Add a DEVICE_BOOL_ATTR macro Borislav Petkov
2012-10-17 19:03   ` Greg Kroah-Hartman
2012-10-17 20:10     ` Borislav Petkov
2012-10-17 20:29       ` Greg Kroah-Hartman
2012-10-17 20:36         ` Borislav Petkov
2012-10-17 20:44           ` Greg Kroah-Hartman

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=1351174667-5098-2-git-send-email-bp@amd64.org \
    --to=bp@amd64.org \
    --cc=bp@alien8.de \
    --cc=greg@kroah.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=tony.luck@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome