[PATCH 05/12] iio: dac: rohm-bd79703: Do not allow writing SCALE

Matti Vaittinen <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <bf75f4bb0d3d620e5c613c04cfc874767a51ff38.1786347811.git.mazziesaccount@gmail.com>
From: Matti Vaittinen <[email protected]>

The BD79703 has adds IIO_CHAN_INFO_SCALE in the info_mask_shared_by_type
so users can read the scale, which depends on the used reference
voltage. This, however, enables users to try writing the scale as well.
This isn't really supported but the bd79703_write_raw() does not check
the mask, and if written scale values pass the validation, the driver
will proceed writing the DAC value when users writes the scale.

Prevent the unsupported scale setting and return an error.

Signed-off-by: Matti Vaittinen <[email protected]>
Fixes: af6aca656a85 ("iio: dac: Support ROHM BD79703 DAC")
---
 drivers/iio/dac/rohm-bd79703.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/dac/rohm-bd79703.c b/drivers/iio/dac/rohm-bd79703.c
index e91090e4a66d..68e66e7286d8 100644
--- a/drivers/iio/dac/rohm-bd79703.c
+++ b/drivers/iio/dac/rohm-bd79703.c
@@ -73,6 +73,9 @@ static int bd79703_write_raw(struct iio_dev *idev,
 {
 	struct bd79703_data *data = iio_priv(idev);
 
+	if (mask != IIO_CHAN_INFO_RAW)
+		return -EINVAL;
+
 	if (val < 0 || val >= 1 << BD79703_DAC_BITS)
 		return -EINVAL;
 
-- 
2.55.0
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmp5gwoACgkQeFA3/03a
ocWYgwgAmdeguctzgeUh4DXpbnRsx4/scOnBDEh9zAV38f4dcSUk5OWLocamRAO/
BLzXtJ48H1Ng+/+CM3xtQGyIqOWCN5vmUzasJhYGwuQBhzNea2BHw0OjZGbi+0Hr
toNqBgBbwSKLHOm8TgiuVYRfdPbOfHHbhwqsbQlPg6u7lsVFF2LE0qSRXCGbC2Bg
73GOVypBsOWnQ7YpkuZtDL5kTDk12ybGdeG5VA+PvUTe7ichK80I3nSUfUoadQdD
xLyRAFb1wI2EJVIdPK3/rxKhR1Tj3tjG07rG2+blaclsipnHO6pOvfNiPGtvozoH
py1K+MlQcKgtiCI4nAJ1Sn6nxn/jVQ==
=4IUX
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.