diff mbox series

[10/13] iio: max9611: Use sysfs_emit()

Message ID 20211216185217.1054495-11-lars@metafoo.de (mailing list archive)
State Accepted
Headers show
Series iio: Use sysfs_emit() | expand

Commit Message

Lars-Peter Clausen Dec. 16, 2021, 6:52 p.m. UTC
sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
`in_current_shunt_resistor` device attributes of the max9611 driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/adc/max9611.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jacopo Mondi Dec. 17, 2021, 9:05 a.m. UTC | #1
Hi Lars-Peter,

On Thu, Dec 16, 2021 at 07:52:14PM +0100, Lars-Peter Clausen wrote:
> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> knows about the sysfs buffer specifics and has some built-in checks for
> size and alignment.
>
> Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
> `in_current_shunt_resistor` device attributes of the max9611 driver.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

Looks good, I just wonder if a dependency on the CONFIG_SYSFS symbol
should now be added...

Thanks
   j

> ---
>  drivers/iio/adc/max9611.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c
> index 01a4275e9c46..f982f00303dc 100644
> --- a/drivers/iio/adc/max9611.c
> +++ b/drivers/iio/adc/max9611.c
> @@ -429,7 +429,7 @@ static ssize_t max9611_shunt_resistor_show(struct device *dev,
>  	i = max9611->shunt_resistor_uohm / 1000000;
>  	r = max9611->shunt_resistor_uohm % 1000000;
>
> -	return sprintf(buf, "%u.%06u\n", i, r);
> +	return sysfs_emit(buf, "%u.%06u\n", i, r);
>  }
>
>  static IIO_DEVICE_ATTR(in_power_shunt_resistor, 0444,
> --
> 2.30.2
>
Lars-Peter Clausen Dec. 17, 2021, 9:17 a.m. UTC | #2
On 12/17/21 10:05 AM, Jacopo Mondi wrote:
> Hi Lars-Peter,
>
> On Thu, Dec 16, 2021 at 07:52:14PM +0100, Lars-Peter Clausen wrote:
>> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
>> knows about the sysfs buffer specifics and has some built-in checks for
>> size and alignment.
>>
>> Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
>> `in_current_shunt_resistor` device attributes of the max9611 driver.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Looks good, I just wonder if a dependency on the CONFIG_SYSFS symbol
> should now be added...
>
I don't think anything has changed in this regard. The function is 
called from a sysfs attribute callback. If SYSFS is disabled the 
callback will not be called. At the same time sysfs_emit() is stubbed 
out when SYSFS is disabled, so no compile error either.
Jacopo Mondi Dec. 17, 2021, 10:09 a.m. UTC | #3
On Fri, Dec 17, 2021 at 10:17:58AM +0100, Lars-Peter Clausen wrote:
> On 12/17/21 10:05 AM, Jacopo Mondi wrote:
> > Hi Lars-Peter,
> >
> > On Thu, Dec 16, 2021 at 07:52:14PM +0100, Lars-Peter Clausen wrote:
> > > sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> > > knows about the sysfs buffer specifics and has some built-in checks for
> > > size and alignment.
> > >
> > > Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
> > > `in_current_shunt_resistor` device attributes of the max9611 driver.
> > >
> > > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> > Looks good, I just wonder if a dependency on the CONFIG_SYSFS symbol
> > should now be added...
> >
> I don't think anything has changed in this regard. The function is called
> from a sysfs attribute callback. If SYSFS is disabled the callback will not
> be called. At the same time sysfs_emit() is stubbed out when SYSFS is
> disabled, so no compile error either.

You're right, nothing changes, we won't have any attribute to call the
function on :)

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks!
   j
diff mbox series

Patch

diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c
index 01a4275e9c46..f982f00303dc 100644
--- a/drivers/iio/adc/max9611.c
+++ b/drivers/iio/adc/max9611.c
@@ -429,7 +429,7 @@  static ssize_t max9611_shunt_resistor_show(struct device *dev,
 	i = max9611->shunt_resistor_uohm / 1000000;
 	r = max9611->shunt_resistor_uohm % 1000000;
 
-	return sprintf(buf, "%u.%06u\n", i, r);
+	return sysfs_emit(buf, "%u.%06u\n", i, r);
 }
 
 static IIO_DEVICE_ATTR(in_power_shunt_resistor, 0444,