linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] iio: Add IIO_STATIC_CONST_DEVICE_ATTR
@ 2022-09-30 10:54 Matti Vaittinen
  2022-09-30 10:54 ` [PATCH 2/2] iio: Fix unsafe buffer attributes Matti Vaittinen
  0 siblings, 1 reply; 3+ messages in thread
From: Matti Vaittinen @ 2022-09-30 10:54 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Alexandre Belloni, Lars-Peter Clausen, Michael Hennerich,
	Matti Vaittinen, Cosmin Tanislav, Miquel Raynal,
	Uwe Kleine-König, linux-kernel, linux-iio, linux-arm-kernel,
	Miaoqian Lin, Srinivas Pandruvada, Eugen Hristev,
	Alexandru Ardelean, Mihail Chindris, Claudiu Beznea,
	Jonathan Cameron


[-- Attachment #1.1: Type: text/plain, Size: 1898 bytes --]

Add IIO_STATIC_CONST_DEVICE_ATTR macro for creating an read-only
iio_dev_attr which returns constant value. This macro is intended to be
used when replacing the IIO_CONST_ATTR - attributes for triggered
buffers because the triggered buffer attributes must be of type
iio_dev_attr.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
I am not thrilled about how keyword 'static' is handled here but in my
calendar this day seems to be called the day of the developer without
working ideas. Feel free to suggest something if you guys have more
luck with ideas. :) And I still think this macro is better than adding
the summy 'show' callback in each individual driver :/

 include/linux/iio/sysfs.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/iio/sysfs.h b/include/linux/iio/sysfs.h
index e51fba66de4b..de5bb125815c 100644
--- a/include/linux/iio/sysfs.h
+++ b/include/linux/iio/sysfs.h
@@ -97,6 +97,17 @@ struct iio_const_attr {
 	= { .string = _string,						\
 	    .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
 
+#define IIO_STATIC_CONST_DEVICE_ATTR(_name, _string)				\
+	static ssize_t iio_const_dev_attr_show_##_name(			\
+					struct device *dev,		\
+					struct device_attribute *attr,	\
+					char *buf)			\
+	{								\
+		return sysfs_emit(buf, "%s\n", _string);		\
+	}								\
+	static IIO_DEVICE_ATTR(_name, 0444,				\
+			       iio_const_dev_attr_show_##_name, NULL, 0)
+
 /* Generic attributes of onetype or another */
 
 /**
-- 
2.37.3


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-30 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-30 10:54 [PATCH 1/2] iio: Add IIO_STATIC_CONST_DEVICE_ATTR Matti Vaittinen
2022-09-30 10:54 ` [PATCH 2/2] iio: Fix unsafe buffer attributes Matti Vaittinen
     [not found]   ` <202209302235.hHrSjkSb-lkp@intel.com>
2022-09-30 17:30     ` Matti Vaittinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).