svn commit: r322212 - head/sys/compat/linuxkpi/common/include/linux

Mark Johnston markj at FreeBSD.org
Tue Aug 8 04:30:24 UTC 2017


Author: markj
Date: Tue Aug  8 04:30:22 2017
New Revision: 322212
URL: https://svnweb.freebsd.org/changeset/base/322212

Log:
  Add macros for defining attribute groups and for WO and RW attributes.
  
  Reviewed by:	hselasky
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D11872

Modified:
  head/sys/compat/linuxkpi/common/include/linux/device.h
  head/sys/compat/linuxkpi/common/include/linux/sysfs.h

Modified: head/sys/compat/linuxkpi/common/include/linux/device.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/device.h	Tue Aug  8 04:10:46 2017	(r322211)
+++ head/sys/compat/linuxkpi/common/include/linux/device.h	Tue Aug  8 04:30:22 2017	(r322212)
@@ -142,7 +142,13 @@ struct device_attribute {
 
 #define	DEVICE_ATTR(_name, _mode, _show, _store)			\
 	struct device_attribute dev_attr_##_name =			\
-	    { { #_name, NULL, _mode }, _show, _store }
+	    __ATTR(_name, _mode, _show, _store)
+#define	DEVICE_ATTR_RO(_name)						\
+	struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
+#define	DEVICE_ATTR_WO(_name)						\
+	struct device_attribute dev_attr_##_name = __ATTR_WO(_name)
+#define	DEVICE_ATTR_RW(_name)						\
+	struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
 
 /* Simple class attribute that is just a static string */
 struct class_attribute_string {

Modified: head/sys/compat/linuxkpi/common/include/linux/sysfs.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/sysfs.h	Tue Aug  8 04:10:46 2017	(r322211)
+++ head/sys/compat/linuxkpi/common/include/linux/sysfs.h	Tue Aug  8 04:30:22 2017	(r322212)
@@ -54,13 +54,20 @@ struct attribute_group {
 	.attr = { .name = __stringify(_name), .mode = _mode },		\
         .show = _show, .store  = _store,				\
 }
+#define	__ATTR_RO(_name)	__ATTR(_name, 0444, _name##_show, NULL)
+#define	__ATTR_WO(_name)	__ATTR(_name, 0200, NULL, _name##_store)
+#define	__ATTR_RW(_name)	__ATTR(_name, 0644, _name##_show, _name##_store)
 
-#define	__ATTR_RO(_name) {						\
-	.attr = { .name = __stringify(_name), .mode = 0444 },		\
-	.show   = _name##_show,						\
-}
-
 #define	__ATTR_NULL	{ .attr = { .name = NULL } }
+
+#define	ATTRIBUTE_GROUPS(_name)						\
+	static struct attribute_group _name##_group = {			\
+		.attrs = _name##_attrs,					\
+	};								\
+	static struct attribute_group *_name##_groups[] = {		\
+		&_name##_group,						\
+		NULL,							\
+	};
 
 /*
  * Handle our generic '\0' terminated 'C' string.


More information about the svn-src-all mailing list