From: David Laight <david.laight.linux@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Dan Carpenter <error27@gmail.com>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Andy Shevchenko <andy@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Helge Deller <deller@gmx.de>,
Thomas Zimmermann <tzimmermann@suse.de>,
Chintan Patel <chintanlike@gmail.com>,
dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] staging: fbtft: Use sysfs_emit_at() to print to sysfs file
Date: Wed, 3 Jun 2026 13:48:06 +0100 [thread overview]
Message-ID: <20260603134806.69df0b01@pumpkin> (raw)
In-Reply-To: <ah_cd9Ax4fzOhBp7@ashevche-desk.local>
On Wed, 3 Jun 2026 10:49:11 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Jun 03, 2026 at 10:34:21AM +0300, Dan Carpenter wrote:
> > This scnprintf() uses the wrong limit. It should be "PAGE_SIZE - len"
> > instead of just PAGE_SIZE. We're not going to hit the limit in real
> > life since we are printing at most FBTFT_GAMMA_MAX_VALUES_TOTAL (128)
> > u32 values, however, it's still worth fixing.
> >
> > Use sysfs_emit_at() to fix this since this is a sysfs file.
>
> OK,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
>
> ...
>
> > for (i = 0; i < par->gamma.num_curves; i++) {
> > for (j = 0; j < par->gamma.num_values; j++)
> > - len += scnprintf(&buf[len], PAGE_SIZE,
> > + len += sysfs_emit_at(buf, len,
> > "%04x ", curves[i * par->gamma.num_values + j]);
>
> Can we switch to use hex_dump_to_buffer() at some point?
>
That gets hard when you really want to aim for something nearer seq_printf().
Oh, the way the loops in the code are written doesn't look like
it gives the compiler much chance of optimising it very well.
This is probably equivalent:
for (i = par->gamma.num_curves; i--;) {
for (j = par->gamma.num_values; j--;)
len += sysfs_emit_at(buf, len, "%04x ", *curves++);
buf[len - 1] = '\n';
}
and will generate much better code.
(Although most of the cost inside the snprintf() function - which is horrid.)
num_values better be non-zero.
-- David
prev parent reply other threads:[~2026-06-03 12:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 7:34 [PATCH] staging: fbtft: Use sysfs_emit_at() to print to sysfs file Dan Carpenter
2026-06-03 7:49 ` Andy Shevchenko
2026-06-03 12:48 ` David Laight [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=20260603134806.69df0b01@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=chintanlike@gmail.com \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=thomas.petazzoni@free-electrons.com \
--cc=tzimmermann@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.