diff mbox series

iio: adc: ad9467: Fix the "don't allow reading vref if not available" case

Message ID 556f87c8931d7d7cdf56ebc79f974f8bef045b0d.1733431628.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Changes Requested
Headers show
Series iio: adc: ad9467: Fix the "don't allow reading vref if not available" case | expand

Commit Message

Christophe JAILLET Dec. 5, 2024, 8:47 p.m. UTC
The commit in Fixes add a special case when only one possible scale is
available.
If several scales are available, it sets the .read_avail field of the
struct iio_info to ad9467_read_avail().

However, this field already holds this function pointer, so the code is a
no-op.

Update ad9467_info to actually reflect the intent described in the commit
message. Keep .read_avail to NULL, unless it is changed to
ad9467_read_avail() in the probe at runtime.

Fixes: b92f94f74826 ("iio: adc: ad9467: don't allow reading vref if not available")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is compile tested only and is completely speculative.

Another solution would be to keep ad9467_info as a const struct as it was
before and add a new ad9467_info_no_read structure.
This way, instead of writing in the structure itself, we would choose at
runtime which version to use. The main benefit would be keep this structure
with function pointer const.
---
 drivers/iio/adc/ad9467.c | 1 -
 1 file changed, 1 deletion(-)

Comments

David Lechner Dec. 6, 2024, 12:03 a.m. UTC | #1
On 12/5/24 2:47 PM, Christophe JAILLET wrote:
> The commit in Fixes add a special case when only one possible scale is
> available.
> If several scales are available, it sets the .read_avail field of the
> struct iio_info to ad9467_read_avail().
> 
> However, this field already holds this function pointer, so the code is a
> no-op.
> 
> Update ad9467_info to actually reflect the intent described in the commit
> message. Keep .read_avail to NULL, unless it is changed to
> ad9467_read_avail() in the probe at runtime.
> 
> Fixes: b92f94f74826 ("iio: adc: ad9467: don't allow reading vref if not available")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This patch is compile tested only and is completely speculative.
> 
> Another solution would be to keep ad9467_info as a const struct as it was
> before and add a new ad9467_info_no_read structure.

Yes, making it static const again would be best. Modifying static structs
that are shared between all instances like this based on the properties of
a single instance is asking for trouble down the road.

> This way, instead of writing in the structure itself, we would choose at
> runtime which version to use. The main benefit would be keep this structure
> with function pointer const.
> ---
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
index d358958ab310..356637677524 100644
--- a/drivers/iio/adc/ad9467.c
+++ b/drivers/iio/adc/ad9467.c
@@ -900,7 +900,6 @@  static struct iio_info ad9467_info = {
 	.write_raw = ad9467_write_raw,
 	.update_scan_mode = ad9467_update_scan_mode,
 	.debugfs_reg_access = ad9467_reg_access,
-	.read_avail = ad9467_read_avail,
 };
 
 static int ad9467_scale_fill(struct ad9467_state *st)