Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v3] iio: adc: ad7091r-base: Remove duplicate code on volatile reg check
@ 2025-04-21 14:55 Arthur Pilone
  2025-04-22  1:52 ` Marcelo Schmitt
  0 siblings, 1 reply; 3+ messages in thread
From: Arthur Pilone @ 2025-04-21 14:55 UTC (permalink / raw)
  To: jic23; +Cc: marcelo.schmitt, linux-iio, bruno.stephan, aschwarz

From: Arthur Pilone <art.pilone@gmail.com>

Both ad7091r_writeable_reg() and ad7091r_volatile_reg() perform the
same test, checking whether a given 'reg' code is
AD7091R_REG_RESULT or AD7091R_REG_ALERT. As the volatile ad7091r
registers happen to be the only read-only ones, the volatile_reg()
function now returns the negated output of writeable_reg().

Co-developed-by: Bruno Stephan <bruno.stephan@usp.br>
Signed-off-by: Bruno Stephan <bruno.stephan@usp.br>
Co-developed-by: Andre de Lima <aschwarz@usp.br>
Signed-off-by: Andre de Lima <aschwarz@usp.br>
Signed-off-by: Arthur Pilone <art.pilone@gmail.com>
---
V2 -> V3: Ditched macro for simply calling existing function
V1 -> V2: Renamed macro and added clarifying comment

 drivers/iio/adc/ad7091r-base.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/ad7091r-base.c b/drivers/iio/adc/ad7091r-base.c
index 931ff71b2888..647a7852dd8d 100644
--- a/drivers/iio/adc/ad7091r-base.c
+++ b/drivers/iio/adc/ad7091r-base.c
@@ -387,13 +387,8 @@ EXPORT_SYMBOL_NS_GPL(ad7091r_writeable_reg, "IIO_AD7091R");
 
 bool ad7091r_volatile_reg(struct device *dev, unsigned int reg)
 {
-	switch (reg) {
-	case AD7091R_REG_RESULT:
-	case AD7091R_REG_ALERT:
-		return true;
-	default:
-		return false;
-	}
+	/* The volatile ad7091r registers are also the only RO ones. */
+	return !ad7091r_writeable_reg(dev, reg);
 }
 EXPORT_SYMBOL_NS_GPL(ad7091r_volatile_reg, "IIO_AD7091R");
 
-- 
2.25.1


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

end of thread, other threads:[~2025-04-26 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-21 14:55 [PATCH v3] iio: adc: ad7091r-base: Remove duplicate code on volatile reg check Arthur Pilone
2025-04-22  1:52 ` Marcelo Schmitt
2025-04-26 15:33   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox