From: Thorsten Blum <thorsten.blum@linux.dev>
To: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>,
Christian Gromm <christian.gromm@microchip.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] most: core: Use sysfs_emit in sysfs show functions
Date: Mon, 25 May 2026 11:56:18 +0200 [thread overview]
Message-ID: <ahQcwkujzkpZDRmb@linux.dev> (raw)
In-Reply-To: <20260309223733.83958-3-thorsten.blum@linux.dev>
Gentle ping?
On Mon, Mar 09, 2026 at 11:37:35PM +0100, Thorsten Blum wrote:
> Replace snprintf() with sysfs_emit() in sysfs show functions.
> sysfs_emit() is preferred for formatting sysfs output because it
> provides safer bounds checking. In components_show() and print_links(),
> use sysfs_emit_at() to avoid manual buffer size accounting.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/most/core.c | 87 +++++++++++++++++++++------------------------
> 1 file changed, 40 insertions(+), 47 deletions(-)
>
> diff --git a/drivers/most/core.c b/drivers/most/core.c
> index c2616da8bceb..64766c021677 100644
> --- a/drivers/most/core.c
> +++ b/drivers/most/core.c
> @@ -208,8 +208,8 @@ static ssize_t number_of_packet_buffers_show(struct device *dev,
> struct most_channel *c = to_channel(dev);
> unsigned int i = c->channel_id;
>
> - return snprintf(buf, PAGE_SIZE, "%d\n",
> - c->iface->channel_vector[i].num_buffers_packet);
> + return sysfs_emit(buf, "%d\n",
> + c->iface->channel_vector[i].num_buffers_packet);
> }
>
> static ssize_t number_of_stream_buffers_show(struct device *dev,
> @@ -219,8 +219,8 @@ static ssize_t number_of_stream_buffers_show(struct device *dev,
> struct most_channel *c = to_channel(dev);
> unsigned int i = c->channel_id;
>
> - return snprintf(buf, PAGE_SIZE, "%d\n",
> - c->iface->channel_vector[i].num_buffers_streaming);
> + return sysfs_emit(buf, "%d\n",
> + c->iface->channel_vector[i].num_buffers_streaming);
> }
>
> static ssize_t size_of_packet_buffer_show(struct device *dev,
> @@ -230,8 +230,8 @@ static ssize_t size_of_packet_buffer_show(struct device *dev,
> struct most_channel *c = to_channel(dev);
> unsigned int i = c->channel_id;
>
> - return snprintf(buf, PAGE_SIZE, "%d\n",
> - c->iface->channel_vector[i].buffer_size_packet);
> + return sysfs_emit(buf, "%d\n",
> + c->iface->channel_vector[i].buffer_size_packet);
> }
>
> static ssize_t size_of_stream_buffer_show(struct device *dev,
> @@ -241,8 +241,8 @@ static ssize_t size_of_stream_buffer_show(struct device *dev,
> struct most_channel *c = to_channel(dev);
> unsigned int i = c->channel_id;
>
> - return snprintf(buf, PAGE_SIZE, "%d\n",
> - c->iface->channel_vector[i].buffer_size_streaming);
> + return sysfs_emit(buf, "%d\n",
> + c->iface->channel_vector[i].buffer_size_streaming);
> }
>
> static ssize_t channel_starving_show(struct device *dev,
> @@ -251,7 +251,7 @@ static ssize_t channel_starving_show(struct device *dev,
> {
> struct most_channel *c = to_channel(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving);
> + return sysfs_emit(buf, "%d\n", c->is_starving);
> }
>
> static ssize_t set_number_of_buffers_show(struct device *dev,
> @@ -260,7 +260,7 @@ static ssize_t set_number_of_buffers_show(struct device *dev,
> {
> struct most_channel *c = to_channel(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers);
> + return sysfs_emit(buf, "%d\n", c->cfg.num_buffers);
> }
>
> static ssize_t set_buffer_size_show(struct device *dev,
> @@ -269,7 +269,7 @@ static ssize_t set_buffer_size_show(struct device *dev,
> {
> struct most_channel *c = to_channel(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size);
> + return sysfs_emit(buf, "%d\n", c->cfg.buffer_size);
> }
>
> static ssize_t set_direction_show(struct device *dev,
> @@ -279,10 +279,10 @@ static ssize_t set_direction_show(struct device *dev,
> struct most_channel *c = to_channel(dev);
>
> if (c->cfg.direction & MOST_CH_TX)
> - return snprintf(buf, PAGE_SIZE, "tx\n");
> + return sysfs_emit(buf, "tx\n");
> else if (c->cfg.direction & MOST_CH_RX)
> - return snprintf(buf, PAGE_SIZE, "rx\n");
> - return snprintf(buf, PAGE_SIZE, "unconfigured\n");
> + return sysfs_emit(buf, "rx\n");
> + return sysfs_emit(buf, "unconfigured\n");
> }
>
> static ssize_t set_datatype_show(struct device *dev,
> @@ -294,10 +294,9 @@ static ssize_t set_datatype_show(struct device *dev,
>
> for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
> if (c->cfg.data_type & ch_data_type[i].most_ch_data_type)
> - return snprintf(buf, PAGE_SIZE, "%s",
> - ch_data_type[i].name);
> + return sysfs_emit(buf, "%s", ch_data_type[i].name);
> }
> - return snprintf(buf, PAGE_SIZE, "unconfigured\n");
> + return sysfs_emit(buf, "unconfigured\n");
> }
>
> static ssize_t set_subbuffer_size_show(struct device *dev,
> @@ -306,7 +305,7 @@ static ssize_t set_subbuffer_size_show(struct device *dev,
> {
> struct most_channel *c = to_channel(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size);
> + return sysfs_emit(buf, "%d\n", c->cfg.subbuffer_size);
> }
>
> static ssize_t set_packets_per_xact_show(struct device *dev,
> @@ -315,7 +314,7 @@ static ssize_t set_packets_per_xact_show(struct device *dev,
> {
> struct most_channel *c = to_channel(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact);
> + return sysfs_emit(buf, "%d\n", c->cfg.packets_per_xact);
> }
>
> static ssize_t set_dbr_size_show(struct device *dev,
> @@ -323,7 +322,7 @@ static ssize_t set_dbr_size_show(struct device *dev,
> {
> struct most_channel *c = to_channel(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.dbr_size);
> + return sysfs_emit(buf, "%d\n", c->cfg.dbr_size);
> }
>
> #define to_dev_attr(a) container_of(a, struct device_attribute, attr)
> @@ -395,7 +394,7 @@ static ssize_t description_show(struct device *dev,
> {
> struct most_interface *iface = dev_get_drvdata(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%s\n", iface->description);
> + return sysfs_emit(buf, "%s\n", iface->description);
> }
>
> static ssize_t interface_show(struct device *dev,
> @@ -406,25 +405,25 @@ static ssize_t interface_show(struct device *dev,
>
> switch (iface->interface) {
> case ITYPE_LOOPBACK:
> - return snprintf(buf, PAGE_SIZE, "loopback\n");
> + return sysfs_emit(buf, "loopback\n");
> case ITYPE_I2C:
> - return snprintf(buf, PAGE_SIZE, "i2c\n");
> + return sysfs_emit(buf, "i2c\n");
> case ITYPE_I2S:
> - return snprintf(buf, PAGE_SIZE, "i2s\n");
> + return sysfs_emit(buf, "i2s\n");
> case ITYPE_TSI:
> - return snprintf(buf, PAGE_SIZE, "tsi\n");
> + return sysfs_emit(buf, "tsi\n");
> case ITYPE_HBI:
> - return snprintf(buf, PAGE_SIZE, "hbi\n");
> + return sysfs_emit(buf, "hbi\n");
> case ITYPE_MEDIALB_DIM:
> - return snprintf(buf, PAGE_SIZE, "mlb_dim\n");
> + return sysfs_emit(buf, "mlb_dim\n");
> case ITYPE_MEDIALB_DIM2:
> - return snprintf(buf, PAGE_SIZE, "mlb_dim2\n");
> + return sysfs_emit(buf, "mlb_dim2\n");
> case ITYPE_USB:
> - return snprintf(buf, PAGE_SIZE, "usb\n");
> + return sysfs_emit(buf, "usb\n");
> case ITYPE_PCIE:
> - return snprintf(buf, PAGE_SIZE, "pcie\n");
> + return sysfs_emit(buf, "pcie\n");
> }
> - return snprintf(buf, PAGE_SIZE, "unknown\n");
> + return sysfs_emit(buf, "unknown\n");
> }
>
> static DEVICE_ATTR_RO(description);
> @@ -471,20 +470,16 @@ static int print_links(struct device *dev, void *data)
>
> list_for_each_entry(c, &iface->p->channel_list, list) {
> if (c->pipe0.comp) {
> - offs += scnprintf(buf + offs,
> - PAGE_SIZE - offs,
> - "%s:%s:%s\n",
> - c->pipe0.comp->name,
> - dev_name(iface->dev),
> - dev_name(&c->dev));
> + offs += sysfs_emit_at(buf, offs, "%s:%s:%s\n",
> + c->pipe0.comp->name,
> + dev_name(iface->dev),
> + dev_name(&c->dev));
> }
> if (c->pipe1.comp) {
> - offs += scnprintf(buf + offs,
> - PAGE_SIZE - offs,
> - "%s:%s:%s\n",
> - c->pipe1.comp->name,
> - dev_name(iface->dev),
> - dev_name(&c->dev));
> + offs += sysfs_emit_at(buf, offs, "%s:%s:%s\n",
> + c->pipe1.comp->name,
> + dev_name(iface->dev),
> + dev_name(&c->dev));
> }
> }
> d->offs = offs;
> @@ -517,10 +512,8 @@ static ssize_t components_show(struct device_driver *drv, char *buf)
> struct most_component *comp;
> int offs = 0;
>
> - list_for_each_entry(comp, &comp_list, list) {
> - offs += scnprintf(buf + offs, PAGE_SIZE - offs, "%s\n",
> - comp->name);
> - }
> + list_for_each_entry(comp, &comp_list, list)
> + offs += sysfs_emit_at(buf, offs, "%s\n", comp->name);
> return offs;
> }
>
prev parent reply other threads:[~2026-05-25 9:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 22:37 [PATCH RESEND] most: core: Use sysfs_emit in sysfs show functions Thorsten Blum
2026-05-25 9:56 ` Thorsten Blum [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=ahQcwkujzkpZDRmb@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=christian.gromm@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=parthiban.veerasooran@microchip.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