Re: [PATCH v9 5/7] ACPI: APEI: EINJ: Create debugfs files to enter device id and syndrome

From: Luck, Tony
Date: Wed Jun 18 2025 - 11:30:27 EST


On Wed, Jun 18, 2025 at 06:21:39PM +0300, Dan Carpenter wrote:
> On Thu, Jun 12, 2025 at 04:13:25PM -0700, Zaid Alali wrote:
> > +static ssize_t u128_read(struct file *f, char __user *buf, size_t count, loff_t *off)
> > +{
> > + char output[2 * COMPONENT_LEN + 1];
> > + u8 *data = f->f_inode->i_private;
> > + int i;
> > +
> > + if (*off >= sizeof(output))
> > + return 0;
>
> No need for this check. simple_read_from_buffer() will do the
> right thing.

True. But why waste cycles populating the output buffer
when it will be ignored? The normal flow here is that
a user will likely try to read a <stdio.h> sized buffer
and get back 33 bytes. Then read again to find EOF. That
second read doesn't need to do all the "sprintf()"s.

> regards,
> dan carpenter
>
> > +
> > + for (i = 0; i < COMPONENT_LEN; i++)
> > + sprintf(output + 2 * i, "%.02x", data[COMPONENT_LEN - i - 1]);
> > + output[2 * COMPONENT_LEN] = '\n';
> > +
> > + return simple_read_from_buffer(buf, count, off, output, sizeof(output));
> > +}

-Tony