diff mbox series

[4/4] iio: dac: Convert powerdown read callbacks to sysfs_emit()

Message ID 20210320071405.9347-5-lars@metafoo.de (mailing list archive)
State New
Headers show
Series iio: Start conversion to sysfs_emit() | expand

Commit Message

Lars-Peter Clausen March 20, 2021, 7:14 a.m. UTC
Update DAC drivers powerdown attribute show callback to use the new
sysfs_emit() function.

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in sanity checks.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/dac/ad5064.c        | 2 +-
 drivers/iio/dac/ad5360.c        | 2 +-
 drivers/iio/dac/ad5380.c        | 2 +-
 drivers/iio/dac/ad5446.c        | 2 +-
 drivers/iio/dac/ad5504.c        | 4 ++--
 drivers/iio/dac/ad5624r_spi.c   | 4 ++--
 drivers/iio/dac/ad5686.c        | 2 +-
 drivers/iio/dac/ad5755.c        | 4 ++--
 drivers/iio/dac/ad5758.c        | 2 +-
 drivers/iio/dac/ad5770r.c       | 2 +-
 drivers/iio/dac/ad5791.c        | 2 +-
 drivers/iio/dac/ad7303.c        | 2 +-
 drivers/iio/dac/ltc2632.c       | 4 ++--
 drivers/iio/dac/max5821.c       | 2 +-
 drivers/iio/dac/mcp4725.c       | 2 +-
 drivers/iio/dac/stm32-dac.c     | 2 +-
 drivers/iio/dac/ti-dac082s085.c | 2 +-
 drivers/iio/dac/ti-dac5571.c    | 2 +-
 drivers/iio/dac/ti-dac7311.c    | 2 +-
 19 files changed, 23 insertions(+), 23 deletions(-)

Comments

Joe Perches March 20, 2021, 11:01 a.m. UTC | #1
On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:
> Update DAC drivers powerdown attribute show callback to use the new
> sysfs_emit() function.
> 
> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> knows about the sysfs buffer specifics and has some built-in sanity checks.

Thanks.

unrelated trivia:

> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
[]
> @@ -255,7 +255,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct ad5360_state *st = iio_priv(indio_dev);
>  
> -	return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> +	return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));

rather than cast to bool, perhaps standardize to use !!(val & test)

> diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c
[]
> @@ -117,8 +117,8 @@ static ssize_t ad5624r_read_dac_powerdown(struct iio_dev *indio_dev,
>  {
>  	struct ad5624r_state *st = iio_priv(indio_dev);
>  
> -	return sprintf(buf, "%d\n",
> -			!!(st->pwr_down_mask & (1 << chan->channel)));
> +	return sysfs_emit(buf, "%d\n",
> +			  !!(st->pwr_down_mask & (1 << chan->channel)));

like this and below...

> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
[]
> @@ -57,7 +57,7 @@ static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
>  {
>  	struct ad5686_state *st = iio_priv(indio_dev);
> 
> -	return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
> +	return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask &
>  				       (0x3 << (chan->channel * 2))));
>  }

etc...

and it might be nicer to rewrap alignments like

	return sysfs_emit(buf, "%d\n",
			  !!(st->pwr_down_mask & (0x3 << (chan->channel * 2))));
Lars-Peter Clausen March 20, 2021, 12:52 p.m. UTC | #2
On 3/20/21 12:01 PM, Joe Perches wrote:
> On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:
>> Update DAC drivers powerdown attribute show callback to use the new
>> sysfs_emit() function.
>>
>> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
>> knows about the sysfs buffer specifics and has some built-in sanity checks.
> Thanks.
>
> unrelated trivia:
>
>> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> []
>> @@ -255,7 +255,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
>>   	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>>   	struct ad5360_state *st = iio_priv(indio_dev);
>>   
>> -	return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
>> +	return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> rather than cast to bool, perhaps standardize to use !!(val & test)
I very much prefer the cast to bool since it semantically stronger. You 
don't have to know that the !! idiom is used to cast an int to bool.
Joe Perches March 20, 2021, 3:13 p.m. UTC | #3
On Sat, 2021-03-20 at 13:52 +0100, Lars-Peter Clausen wrote:
> On 3/20/21 12:01 PM, Joe Perches wrote:
> > On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:
> > > Update DAC drivers powerdown attribute show callback to use the new
> > > sysfs_emit() function.
> > > 
> > > sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> > > knows about the sysfs buffer specifics and has some built-in sanity checks.
> > Thanks.
> > 
> > unrelated trivia:
> > 
> > > diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> > []
> > > @@ -255,7 +255,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
> > >   	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> > >   	struct ad5360_state *st = iio_priv(indio_dev);
> > >   
> > > 
> > > -	return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > > +	return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > rather than cast to bool, perhaps standardize to use !!(val & test)
> I very much prefer the cast to bool since it semantically stronger. You 
> don't have to know that the !! idiom is used to cast an int to bool.

Using !! does not cast to bool, it's an int.

casting to bool and using %d in a printf equivalent ends up with an
integer promotion/implicit type conversion from bool to int.

Anyway, it's not my code so it's author's choice, but similar
code using different styles is, at a minimum, inconsistent.
Jonathan Cameron March 29, 2021, 10:13 a.m. UTC | #4
On Sat, 20 Mar 2021 08:13:55 -0700
Joe Perches <joe@perches.com> wrote:

> On Sat, 2021-03-20 at 13:52 +0100, Lars-Peter Clausen wrote:
> > On 3/20/21 12:01 PM, Joe Perches wrote:  
> > > On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:  
> > > > Update DAC drivers powerdown attribute show callback to use the new
> > > > sysfs_emit() function.
> > > > 
> > > > sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> > > > knows about the sysfs buffer specifics and has some built-in sanity checks.  
> > > Thanks.
> > > 
> > > unrelated trivia:
> > >   
> > > > diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c  
> > > []  
> > > > @@ -255,7 +255,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
> > > >   	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> > > >   	struct ad5360_state *st = iio_priv(indio_dev);
> > > >   
> > > > 
> > > > -	return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > > > +	return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));  
> > > rather than cast to bool, perhaps standardize to use !!(val & test)  
> > I very much prefer the cast to bool since it semantically stronger. You 
> > don't have to know that the !! idiom is used to cast an int to bool.  
> 
> Using !! does not cast to bool, it's an int.
> 
> casting to bool and using %d in a printf equivalent ends up with an
> integer promotion/implicit type conversion from bool to int.
> 
> Anyway, it's not my code so it's author's choice, but similar
> code using different styles is, at a minimum, inconsistent.
> 
I'm certainly not against cleaning this up at somepoint, but it's not strictly
part of what this particular patch set is doing, so I'd rather do
it separately anyway.

Applied to the togreg branch of iio.git and pushed out as testing
for all the normal reasons.

Thanks,

Jonathan
Andy Shevchenko March 29, 2021, 11:21 a.m. UTC | #5
On Sat, Mar 20, 2021 at 2:54 PM Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 3/20/21 12:01 PM, Joe Perches wrote:
> > On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:
> >> Update DAC drivers powerdown attribute show callback to use the new
> >> sysfs_emit() function.
> >>
> >> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> >> knows about the sysfs buffer specifics and has some built-in sanity checks.
> > Thanks.
> >
> > unrelated trivia:
> >
> >> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> > []
> >> @@ -255,7 +255,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
> >>      struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> >>      struct ad5360_state *st = iio_priv(indio_dev);
> >>
> >> -    return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> >> +    return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > rather than cast to bool, perhaps standardize to use !!(val & test)
> I very much prefer the cast to bool since it semantically stronger.

It's a mistake here. You have no special type for bool and you do
transition int -> bool -> int.
Why? !! is a proper way to deal with this.

> You
> don't have to know that the !! idiom is used to cast an int to bool.

As Joe said.
Andy Shevchenko March 29, 2021, 11:22 a.m. UTC | #6
On Mon, Mar 29, 2021 at 2:21 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Sat, Mar 20, 2021 at 2:54 PM Lars-Peter Clausen <lars@metafoo.de> wrote:
> > On 3/20/21 12:01 PM, Joe Perches wrote:
> > > On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:

...

> > >> -    return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > >> +    return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > > rather than cast to bool, perhaps standardize to use !!(val & test)
> > I very much prefer the cast to bool since it semantically stronger.
>
> It's a mistake here. You have no special type for bool and you do
> transition int -> bool -> int.
> Why? !! is a proper way to deal with this.

Just to generalize: casting printf() parameters is a mistake in 99% cases.
Andy Shevchenko March 29, 2021, 11:27 a.m. UTC | #7
On Sat, Mar 20, 2021 at 1:26 PM Lars-Peter Clausen <lars@metafoo.de> wrote:

One side note for the future improvements.

> +       return sysfs_emit(buf, "%d\n",
> +                         !(st->pwr_down_mask & (1 << chan->channel)));

> +       return sysfs_emit(buf, "%d\n",
> +                         !!(st->pwr_down_mask & (1 << chan->channel)));

> -       return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
> +       return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask &
>                                        (0x3 << (chan->channel * 2))));

Converting above to use BIT() / GENMASK() will help to avoid potential
UB when it will try to set the last (31st) bit.

> +       return sysfs_emit(buf, "%d\n",
> +                         (bool)(st->pwr_down & (1 << chan->channel)));

> +       return sysfs_emit(buf, "%d\n",
> +                         !!(st->powerdown_cache_mask & (1 << chan->channel)));

...

> -       return sprintf(buf, "%d\n", ret ? 0 : 1);
> +       return sysfs_emit(buf, "%d\n", ret ? 0 : 1);

Useless ternary, may be ret == 0 or !ret. (Yes, I know that compiler
optimizes this away)
diff mbox series

Patch

diff --git a/drivers/iio/dac/ad5064.c b/drivers/iio/dac/ad5064.c
index 82abd4d6886c..dff623b65e4f 100644
--- a/drivers/iio/dac/ad5064.c
+++ b/drivers/iio/dac/ad5064.c
@@ -277,7 +277,7 @@  static ssize_t ad5064_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5064_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", st->pwr_down[chan->channel]);
+	return sysfs_emit(buf, "%d\n", st->pwr_down[chan->channel]);
 }
 
 static ssize_t ad5064_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
index 602dd2ba61b5..2d3b14c407d8 100644
--- a/drivers/iio/dac/ad5360.c
+++ b/drivers/iio/dac/ad5360.c
@@ -255,7 +255,7 @@  static ssize_t ad5360_read_dac_powerdown(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct ad5360_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
+	return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
 }
 
 static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c
index 37ef653564b0..53db5b4e4c53 100644
--- a/drivers/iio/dac/ad5380.c
+++ b/drivers/iio/dac/ad5380.c
@@ -85,7 +85,7 @@  static ssize_t ad5380_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5380_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", st->pwr_down);
+	return sysfs_emit(buf, "%d\n", st->pwr_down);
 }
 
 static ssize_t ad5380_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c
index d87e21016863..488ec69967d6 100644
--- a/drivers/iio/dac/ad5446.c
+++ b/drivers/iio/dac/ad5446.c
@@ -100,7 +100,7 @@  static ssize_t ad5446_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5446_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", st->pwr_down);
+	return sysfs_emit(buf, "%d\n", st->pwr_down);
 }
 
 static ssize_t ad5446_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index e9297c25d4ef..c12ae91d8843 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -170,8 +170,8 @@  static ssize_t ad5504_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5504_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n",
-			!(st->pwr_down_mask & (1 << chan->channel)));
+	return sysfs_emit(buf, "%d\n",
+			  !(st->pwr_down_mask & (1 << chan->channel)));
 }
 
 static ssize_t ad5504_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c
index 2b2b8edfd258..9bde86982912 100644
--- a/drivers/iio/dac/ad5624r_spi.c
+++ b/drivers/iio/dac/ad5624r_spi.c
@@ -117,8 +117,8 @@  static ssize_t ad5624r_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5624r_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n",
-			!!(st->pwr_down_mask & (1 << chan->channel)));
+	return sysfs_emit(buf, "%d\n",
+			  !!(st->pwr_down_mask & (1 << chan->channel)));
 }
 
 static ssize_t ad5624r_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 99a95282ac57..fcb64f20ff64 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -57,7 +57,7 @@  static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
+	return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask &
 				       (0x3 << (chan->channel * 2))));
 }
 
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
index 0df28acf074a..cabc38d54085 100644
--- a/drivers/iio/dac/ad5755.c
+++ b/drivers/iio/dac/ad5755.c
@@ -399,8 +399,8 @@  static ssize_t ad5755_read_powerdown(struct iio_dev *indio_dev, uintptr_t priv,
 {
 	struct ad5755_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n",
-		       (bool)(st->pwr_down & (1 << chan->channel)));
+	return sysfs_emit(buf, "%d\n",
+			  (bool)(st->pwr_down & (1 << chan->channel)));
 }
 
 static ssize_t ad5755_write_powerdown(struct iio_dev *indio_dev, uintptr_t priv,
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index bd9ac8359d98..0572ef518101 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -574,7 +574,7 @@  static ssize_t ad5758_read_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5758_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", st->pwr_down);
+	return sysfs_emit(buf, "%d\n", st->pwr_down);
 }
 
 static ssize_t ad5758_write_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad5770r.c b/drivers/iio/dac/ad5770r.c
index 84dcf149261f..5e901fe48023 100644
--- a/drivers/iio/dac/ad5770r.c
+++ b/drivers/iio/dac/ad5770r.c
@@ -433,7 +433,7 @@  static ssize_t ad5770r_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5770r_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", st->ch_pwr_down[chan->channel]);
+	return sysfs_emit(buf, "%d\n", st->ch_pwr_down[chan->channel]);
 }
 
 static ssize_t ad5770r_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c
index 615d72cd59bc..a0923b76e8b6 100644
--- a/drivers/iio/dac/ad5791.c
+++ b/drivers/iio/dac/ad5791.c
@@ -177,7 +177,7 @@  static ssize_t ad5791_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad5791_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", st->pwr_down);
+	return sysfs_emit(buf, "%d\n", st->pwr_down);
 }
 
 static ssize_t ad5791_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ad7303.c b/drivers/iio/dac/ad7303.c
index dbb4645ab6b1..e1b6a92df12f 100644
--- a/drivers/iio/dac/ad7303.c
+++ b/drivers/iio/dac/ad7303.c
@@ -65,7 +65,7 @@  static ssize_t ad7303_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ad7303_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", (bool)(st->config &
+	return sysfs_emit(buf, "%d\n", (bool)(st->config &
 		AD7303_CFG_POWER_DOWN(chan->channel)));
 }
 
diff --git a/drivers/iio/dac/ltc2632.c b/drivers/iio/dac/ltc2632.c
index 4002ed0868be..53e4b887d372 100644
--- a/drivers/iio/dac/ltc2632.c
+++ b/drivers/iio/dac/ltc2632.c
@@ -135,8 +135,8 @@  static ssize_t ltc2632_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct ltc2632_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n",
-		       !!(st->powerdown_cache_mask & (1 << chan->channel)));
+	return sysfs_emit(buf, "%d\n",
+			  !!(st->powerdown_cache_mask & (1 << chan->channel)));
 }
 
 static ssize_t ltc2632_write_dac_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
index d6bb24db49c4..bd6e75699a63 100644
--- a/drivers/iio/dac/max5821.c
+++ b/drivers/iio/dac/max5821.c
@@ -84,7 +84,7 @@  static ssize_t max5821_read_dac_powerdown(struct iio_dev *indio_dev,
 {
 	struct max5821_data *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", st->powerdown[chan->channel]);
+	return sysfs_emit(buf, "%d\n", st->powerdown[chan->channel]);
 }
 
 static int max5821_sync_powerdown_mode(struct max5821_data *data,
diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index beb9a15b7c74..34b14aafb630 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -167,7 +167,7 @@  static ssize_t mcp4725_read_powerdown(struct iio_dev *indio_dev,
 {
 	struct mcp4725_data *data = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", data->powerdown);
+	return sysfs_emit(buf, "%d\n", data->powerdown);
 }
 
 static ssize_t mcp4725_write_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 12dec68c16f7..a5b0a52bf86e 100644
--- a/drivers/iio/dac/stm32-dac.c
+++ b/drivers/iio/dac/stm32-dac.c
@@ -210,7 +210,7 @@  static ssize_t stm32_dac_read_powerdown(struct iio_dev *indio_dev,
 	if (ret < 0)
 		return ret;
 
-	return sprintf(buf, "%d\n", ret ? 0 : 1);
+	return sysfs_emit(buf, "%d\n", ret ? 0 : 1);
 }
 
 static ssize_t stm32_dac_write_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ti-dac082s085.c b/drivers/iio/dac/ti-dac082s085.c
index de33c1fc6e0b..5c14bfb16521 100644
--- a/drivers/iio/dac/ti-dac082s085.c
+++ b/drivers/iio/dac/ti-dac082s085.c
@@ -121,7 +121,7 @@  static ssize_t ti_dac_read_powerdown(struct iio_dev *indio_dev,
 {
 	struct ti_dac_chip *ti_dac = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", ti_dac->powerdown);
+	return sysfs_emit(buf, "%d\n", ti_dac->powerdown);
 }
 
 static ssize_t ti_dac_write_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ti-dac5571.c b/drivers/iio/dac/ti-dac5571.c
index d3295767a079..2a5ba1b08a1d 100644
--- a/drivers/iio/dac/ti-dac5571.c
+++ b/drivers/iio/dac/ti-dac5571.c
@@ -166,7 +166,7 @@  static ssize_t dac5571_read_powerdown(struct iio_dev *indio_dev,
 {
 	struct dac5571_data *data = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", data->powerdown[chan->channel]);
+	return sysfs_emit(buf, "%d\n", data->powerdown[chan->channel]);
 }
 
 static ssize_t dac5571_write_powerdown(struct iio_dev *indio_dev,
diff --git a/drivers/iio/dac/ti-dac7311.c b/drivers/iio/dac/ti-dac7311.c
index 63171e42f987..9d0b253be841 100644
--- a/drivers/iio/dac/ti-dac7311.c
+++ b/drivers/iio/dac/ti-dac7311.c
@@ -110,7 +110,7 @@  static ssize_t ti_dac_read_powerdown(struct iio_dev *indio_dev,
 {
 	struct ti_dac_chip *ti_dac = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", ti_dac->powerdown);
+	return sysfs_emit(buf, "%d\n", ti_dac->powerdown);
 }
 
 static ssize_t ti_dac_write_powerdown(struct iio_dev *indio_dev,