From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: "Cosmin Tanislav" <cosmin.tanislav@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Eugen Hristev" <eugen.hristev@microchip.com>,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Claudiu Beznea" <claudiu.beznea@microchip.com>,
"Alexandru Ardelean" <alexandru.ardelean@analog.com>,
"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
"Miaoqian Lin" <linmq006@gmail.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Matti Vaittinen" <mazziesaccount@gmail.com>,
"Mihail Chindris" <mihail.chindris@analog.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] iio: Add IIO_STATIC_CONST_DEVICE_ATTR
Date: Fri, 30 Sep 2022 13:54:08 +0300 [thread overview]
Message-ID: <57fa292756e187d104249f39a655ae736cbcaa76.1664534676.git.mazziesaccount@gmail.com> (raw)
[-- Attachment #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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next reply other threads:[~2022-09-30 11:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-30 10:54 Matti Vaittinen [this message]
2022-09-30 10:54 ` [PATCH 2/2] iio: Fix unsafe buffer attributes Matti Vaittinen
2022-09-30 14:17 ` kernel test robot
2022-09-30 17:30 ` Matti Vaittinen
2022-10-01 19:47 ` kernel test robot
2022-10-01 19:47 ` kernel test robot
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=57fa292756e187d104249f39a655ae736cbcaa76.1664534676.git.mazziesaccount@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandru.ardelean@analog.com \
--cc=claudiu.beznea@microchip.com \
--cc=cosmin.tanislav@analog.com \
--cc=eugen.hristev@microchip.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linmq006@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=mihail.chindris@analog.com \
--cc=miquel.raynal@bootlin.com \
--cc=nicolas.ferre@microchip.com \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=u.kleine-koenig@pengutronix.de \
/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
all inboxes | Powered by JetHome®