mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Gabriel Rondon <grondon@gmail.com>
Cc: David Lechner <dlechner@baylibre.com>,
	Nuno Sa <nuno.sa@analog.com>, Andy Shevchenko <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions
Date: Wed, 25 Mar 2026 20:25:05 +0000	[thread overview]
Message-ID: <20260325202505.404cbc17@jic23-huawei> (raw)
In-Reply-To: <20260323215619.6883-1-grondon@gmail.com>

On Mon, 23 Mar 2026 21:56:19 +0000
Gabriel Rondon <grondon@gmail.com> wrote:

> Replace sprintf() with sysfs_emit() in sysfs attribute show
> callbacks. sysfs_emit() is the preferred API as it is aware of the
> sysfs buffer page size limit.
> 
> Signed-off-by: Gabriel Rondon <grondon@gmail.com>
Applied. Note there is more that could be done in these two functions 
(look beyond it if considering doing this). 
> ---
>  drivers/iio/accel/bmc150-accel-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 42ccf0316..2398eb7e1 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -851,7 +851,7 @@ static ssize_t bmc150_accel_get_fifo_watermark(struct device *dev,
>  	wm = data->watermark;
>  	mutex_unlock(&data->mutex);
That mutex is only held for setting local copy of wm.  Should be no problem
in bolding it over the sysfs_emit. So
include cleanup.h if not already and use a guard.

	guard(mutex)(&data->mutex);

	return sysfs_emit(buf, "%d\n", data->watermark);

No need for a local variable.

>  
> -	return sprintf(buf, "%d\n", wm);
> +	return sysfs_emit(buf, "%d\n", wm);
>  }
>  
>  static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
> @@ -866,7 +866,7 @@ static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
>  	state = data->fifo_mode;
>  	mutex_unlock(&data->mutex);
>  
> -	return sprintf(buf, "%d\n", state);
> +	return sysfs_emit(buf, "%d\n", state);
>  }
>  
>  static const struct iio_mount_matrix *


      reply	other threads:[~2026-03-25 20:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 21:56 Gabriel Rondon
2026-03-25 20:25 ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260325202505.404cbc17@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=grondon@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®