mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] iio: proximity: srf08: replace sprintf() with sysfs_emit()
@ 2026-04-20 23:08 Maxwell Doose
  2026-04-21 14:42 ` Jonathan Cameron
  2026-04-22  6:59 ` Andy Shevchenko
  0 siblings, 2 replies; 4+ messages in thread
From: Maxwell Doose @ 2026-04-20 23:08 UTC (permalink / raw)
  To: ak, jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel

This patch replaces sprintf() function calls with sysfs_emit() and
sysfs_emit_at(). While the current code is fine, sysfs_emit() is
preferred over sprintf(), and will help modernize the driver.

Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
 v2:
 - Fixed indenting of sysfs_emit call in function srf08_show_range_mm.
 - Optimized return sequence in function srf08_show_sensitivity by
   directly returning instead of modifying a variable and then
   returning.

 v3:
 - Changed indenting of sysfs_emit() call in function
   srf08_show_range_mm() per Andy Shevchenko's request.
 - Clarified commit message details.

 drivers/iio/proximity/srf08.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c
index d7e4cc48cfbf..e92526459dcf 100644
--- a/drivers/iio/proximity/srf08.c
+++ b/drivers/iio/proximity/srf08.c
@@ -226,7 +226,7 @@ static int srf08_read_raw(struct iio_dev *indio_dev,
 static ssize_t srf08_show_range_mm_available(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "[0.043 0.043 11.008]\n");
+	return sysfs_emit(buf, "[0.043 0.043 11.008]\n");
 }
 
 static IIO_DEVICE_ATTR(sensor_max_range_available, S_IRUGO,
@@ -238,8 +238,8 @@ static ssize_t srf08_show_range_mm(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct srf08_data *data = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d.%03d\n", data->range_mm / 1000,
-						data->range_mm % 1000);
+	return sysfs_emit(buf, "%d.%03d\n",
+			data->range_mm / 1000, data->range_mm % 1000);
 }
 
 /*
@@ -316,10 +316,10 @@ static ssize_t srf08_show_sensitivity_available(struct device *dev,
 
 	for (i = 0; i < data->chip_info->num_sensitivity_avail; i++)
 		if (data->chip_info->sensitivity_avail[i])
-			len += sprintf(buf + len, "%d ",
+			len += sysfs_emit_at(buf, len, "%d ",
 				data->chip_info->sensitivity_avail[i]);
 
-	len += sprintf(buf + len, "\n");
+	len += sysfs_emit_at(buf, len, "\n");
 
 	return len;
 }
@@ -332,11 +332,8 @@ static ssize_t srf08_show_sensitivity(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct srf08_data *data = iio_priv(indio_dev);
-	int len;
 
-	len = sprintf(buf, "%d\n", data->sensitivity);
-
-	return len;
+	return sysfs_emit(buf, "%d\n", data->sensitivity);
 }
 
 static ssize_t srf08_write_sensitivity(struct srf08_data *data,
-- 
2.53.0


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

* Re: [PATCH v3] iio: proximity: srf08: replace sprintf() with sysfs_emit()
  2026-04-20 23:08 [PATCH v3] iio: proximity: srf08: replace sprintf() with sysfs_emit() Maxwell Doose
@ 2026-04-21 14:42 ` Jonathan Cameron
  2026-04-21 16:38   ` Maxwell Doose
  2026-04-22  6:59 ` Andy Shevchenko
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2026-04-21 14:42 UTC (permalink / raw)
  To: Maxwell Doose; +Cc: ak, dlechner, nuno.sa, andy, linux-iio, linux-kernel

On Mon, 20 Apr 2026 18:08:13 -0500
Maxwell Doose <m32285159@gmail.com> wrote:

> This patch replaces sprintf() function calls with sysfs_emit() and
> sysfs_emit_at(). While the current code is fine, sysfs_emit() is
> preferred over sprintf(), and will help modernize the driver.
> 
> Signed-off-by: Maxwell Doose <m32285159@gmail.com>
> ---
>  v2:
>  - Fixed indenting of sysfs_emit call in function srf08_show_range_mm.

Not true unfortunately. Now broken differently.

>  - Optimized return sequence in function srf08_show_sensitivity by
>    directly returning instead of modifying a variable and then
>    returning.
> 
>  v3:
>  - Changed indenting of sysfs_emit() call in function
>    srf08_show_range_mm() per Andy Shevchenko's request.
>  - Clarified commit message details.
> 
>  drivers/iio/proximity/srf08.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c
> index d7e4cc48cfbf..e92526459dcf 100644
> --- a/drivers/iio/proximity/srf08.c
> +++ b/drivers/iio/proximity/srf08.c
> @@ -226,7 +226,7 @@ static int srf08_read_raw(struct iio_dev *indio_dev,
>  static ssize_t srf08_show_range_mm_available(struct device *dev,
>  				struct device_attribute *attr, char *buf)
>  {
> -	return sprintf(buf, "[0.043 0.043 11.008]\n");
> +	return sysfs_emit(buf, "[0.043 0.043 11.008]\n");
>  }
>  
>  static IIO_DEVICE_ATTR(sensor_max_range_available, S_IRUGO,
> @@ -238,8 +238,8 @@ static ssize_t srf08_show_range_mm(struct device *dev,
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct srf08_data *data = iio_priv(indio_dev);
>  
> -	return sprintf(buf, "%d.%03d\n", data->range_mm / 1000,
> -						data->range_mm % 1000);
> +	return sysfs_emit(buf, "%d.%03d\n",
> +			data->range_mm / 1000, data->range_mm % 1000);
Should be:
	return sysfs_emit(buf, "%d.%03d\n",
			  data->range_mm / 1000, data->range_mm % 1000);
Or
	return sysfs_emit(buf, "%d.%03d\n", data->range_mm / 1000,
			  data->range_mm % 1000);


>  }
>  
>  /*
> @@ -316,10 +316,10 @@ static ssize_t srf08_show_sensitivity_available(struct device *dev,
>  
>  	for (i = 0; i < data->chip_info->num_sensitivity_avail; i++)
>  		if (data->chip_info->sensitivity_avail[i])
> -			len += sprintf(buf + len, "%d ",
> +			len += sysfs_emit_at(buf, len, "%d ",
>  				data->chip_info->sensitivity_avail[i]);
>  
> -	len += sprintf(buf + len, "\n");
> +	len += sysfs_emit_at(buf, len, "\n");
>  
>  	return len;
>  }
> @@ -332,11 +332,8 @@ static ssize_t srf08_show_sensitivity(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct srf08_data *data = iio_priv(indio_dev);
> -	int len;
>  
> -	len = sprintf(buf, "%d\n", data->sensitivity);
> -
> -	return len;
> +	return sysfs_emit(buf, "%d\n", data->sensitivity);
>  }
>  
>  static ssize_t srf08_write_sensitivity(struct srf08_data *data,


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

* Re: [PATCH v3] iio: proximity: srf08: replace sprintf() with sysfs_emit()
  2026-04-21 14:42 ` Jonathan Cameron
@ 2026-04-21 16:38   ` Maxwell Doose
  0 siblings, 0 replies; 4+ messages in thread
From: Maxwell Doose @ 2026-04-21 16:38 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: ak, dlechner, nuno.sa, andy, linux-iio, linux-kernel

On Tue, Apr 21, 2026 at 9:42 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> Not true unfortunately. Now broken differently.
>
> Should be:
>         return sysfs_emit(buf, "%d.%03d\n",
>                           data->range_mm / 1000, data->range_mm % 1000);
> Or
>         return sysfs_emit(buf, "%d.%03d\n", data->range_mm / 1000,
>                           data->range_mm % 1000);
>

Sorry, still figuring out the indenting for the multi-line parameter lists.
I'll get that fixed in a v4 once I've got free time.

best regards,
maxwell

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

* Re: [PATCH v3] iio: proximity: srf08: replace sprintf() with sysfs_emit()
  2026-04-20 23:08 [PATCH v3] iio: proximity: srf08: replace sprintf() with sysfs_emit() Maxwell Doose
  2026-04-21 14:42 ` Jonathan Cameron
@ 2026-04-22  6:59 ` Andy Shevchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-04-22  6:59 UTC (permalink / raw)
  To: Maxwell Doose; +Cc: ak, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel

On Mon, Apr 20, 2026 at 06:08:13PM -0500, Maxwell Doose wrote:
> This patch replaces sprintf() function calls with sysfs_emit() and
> sysfs_emit_at(). While the current code is fine, sysfs_emit() is
> preferred over sprintf(), and will help modernize the driver.

...

> static ssize_t srf08_show_range_mm(struct device *dev,

>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct srf08_data *data = iio_priv(indio_dev);
>  
> -	return sprintf(buf, "%d.%03d\n", data->range_mm / 1000,
> -						data->range_mm % 1000);
> +	return sysfs_emit(buf, "%d.%03d\n",
> +			data->range_mm / 1000, data->range_mm % 1000);

Wrong indentation.

>  }

...

>  	for (i = 0; i < data->chip_info->num_sensitivity_avail; i++)
>  		if (data->chip_info->sensitivity_avail[i])
> -			len += sprintf(buf + len, "%d ",
> +			len += sysfs_emit_at(buf, len, "%d ",
>  				data->chip_info->sensitivity_avail[i]);

Ditto.

...

The rest is okay.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-04-22  6:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-20 23:08 [PATCH v3] iio: proximity: srf08: replace sprintf() with sysfs_emit() Maxwell Doose
2026-04-21 14:42 ` Jonathan Cameron
2026-04-21 16:38   ` Maxwell Doose
2026-04-22  6:59 ` Andy Shevchenko

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

all inboxes | Powered by JetHome®