[PATCH] iio: light: vcnl4000: use sysfs_emit() for near_level

Donggeun Yoo posted 1 patch 3 weeks, 6 days ago
There is a newer version of this series
drivers/iio/light/vcnl4000.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] iio: light: vcnl4000: use sysfs_emit() for near_level
Posted by Donggeun Yoo 3 weeks, 6 days ago
Use sysfs_emit() instead of sprintf() for writing to the sysfs
output buffer. sysfs_emit() is aware of the buffer's PAGE_SIZE
limit and is the preferred helper for sysfs callbacks.

Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
---
 drivers/iio/light/vcnl4000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 336468d59ea7..dac235dd6220 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -1504,7 +1504,7 @@ static ssize_t vcnl4000_read_near_level(struct iio_dev *indio_dev,
 {
 	struct vcnl4000_data *data = iio_priv(indio_dev);
 
-	return sprintf(buf, "%u\n", data->near_level);
+	return sysfs_emit(buf, "%u\n", data->near_level);
 }
 
 static irqreturn_t vcnl4010_irq_thread(int irq, void *p)

base-commit: 350d1fb9204b13c5f95e511e98b8bcb47574d425
-- 
2.53.0
Re: [PATCH] iio: light: vcnl4000: use sysfs_emit() for near_level
Posted by Joshua Crofts 3 weeks, 6 days ago
On Sun, 30 Aug 2026 14:42:36 +0900
Donggeun Yoo <donggeunyoo.kernel@gmail.com> wrote:

> Use sysfs_emit() instead of sprintf() for writing to the sysfs
> output buffer. sysfs_emit() is aware of the buffer's PAGE_SIZE
> limit and is the preferred helper for sysfs callbacks.
> 
> Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
> ---
>  drivers/iio/light/vcnl4000.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index 336468d59ea7..dac235dd6220 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -1504,7 +1504,7 @@ static ssize_t vcnl4000_read_near_level(struct iio_dev *indio_dev,
>  {
>  	struct vcnl4000_data *data = iio_priv(indio_dev);
>  
> -	return sprintf(buf, "%u\n", data->near_level);
> +	return sysfs_emit(buf, "%u\n", data->near_level);

You should also include <linux/sysfs.h>.

-- 
Kind regards,
Joshua Crofts
Re: [PATCH] iio: light: vcnl4000: use sysfs_emit() for near_level
Posted by Donggeun Yoo 3 weeks, 6 days ago
> You should also include <linux/sysfs.h>.

Thanks, added in v2.


On Mon, Aug 31, 2026 at 12:41 AM Joshua Crofts <joshua.crofts1@gmail.com> wrote:
>
> On Sun, 30 Aug 2026 14:42:36 +0900
> Donggeun Yoo <donggeunyoo.kernel@gmail.com> wrote:
>
> > Use sysfs_emit() instead of sprintf() for writing to the sysfs
> > output buffer. sysfs_emit() is aware of the buffer's PAGE_SIZE
> > limit and is the preferred helper for sysfs callbacks.
> >
> > Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
> > ---
> >  drivers/iio/light/vcnl4000.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> > index 336468d59ea7..dac235dd6220 100644
> > --- a/drivers/iio/light/vcnl4000.c
> > +++ b/drivers/iio/light/vcnl4000.c
> > @@ -1504,7 +1504,7 @@ static ssize_t vcnl4000_read_near_level(struct iio_dev *indio_dev,
> >  {
> >       struct vcnl4000_data *data = iio_priv(indio_dev);
> >
> > -     return sprintf(buf, "%u\n", data->near_level);
> > +     return sysfs_emit(buf, "%u\n", data->near_level);
>
> You should also include <linux/sysfs.h>.
>
> --
> Kind regards,
> Joshua Crofts