staging: fbtft: Use sysfs_emit_at() to print to sysfs file
Subsystems (4)
PATCH 1/1 staging: fbtft: Use sysfs_emit_at() to print to sysfs file
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.
--- drivers/staging/fbtft/fbtft-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fbtft/fbtft-sysfs.c +1 -1
@@ -98,7 +98,7 @@ sprintf_gamma(struct fbtft_par *par, u32 *curves, char *buf)mutex_lock (&par->gamma.lock);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]); buf[len -1 ] ='\n' ; }
Signature · 1 line
2.53.0
Quoted 6 lines · Dan Carpenter
This
scnprintf()uses the wrong limit. It should be "PAGE_SIZE- len" instead of justPAGE_SIZE. We're not going to hit the limit in real life since we are printing at mostFBTFT_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,
...
drivers/staging/fbtft/fbtft-sysfs.c sprintf_gamma(struct fbtft_par *par, u32 *curves, char *buf) · line 102
Quoted 5 lines
drivers/staging/fbtft/fbtft-sysfs.c +1
-1for (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?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 13 lines · On Wed, 3 Jun 2026 10:49:11 +0300 Andy Shevchenko…
Quoted 6 lines · Dan Carpenter
This
scnprintf()uses the wrong limit. It should be "PAGE_SIZE- len" instead of justPAGE_SIZE. We're not going to hit the limit in real life since we are printing at mostFBTFT_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 <[email protected]>...
Quoted 8 lines
drivers/staging/fbtft/fbtft-sysfs.c sprintf_gamma(struct fbtft_par *par, u32 *curves, char *buf) · line 102
Quoted 5 lines
drivers/staging/fbtft/fbtft-sysfs.c +1
-1for (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