Re: [RESEND PATCH v2] scsi: core: Add 'serial' sysfs attribute for SCSI/SATA

From: Igor Pylypiv

Date: Mon Feb 09 2026 - 14:32:13 EST


On Mon, Feb 09, 2026 at 09:31:39AM -0800, Bart Van Assche wrote:
> On 2/5/26 10:00 AM, Igor Pylypiv wrote:
> > + return sysfs_emit(buf, "%s\n", buf);
>
> Since many snprintf() variants do not allow to specify the output buffer as
> input argument, the above seems risky to me. Has it been considered to
> replace the above statement with the following?
>
> return sysfs_emit_at(buf, strlen(buf), "\n");

Thank you for pointing this out, Bart! I've now realized that you
pointed out this in V1 as well but I misunderstood your comment.

sysfs_emit_at() returns number of characters written starting at &buf[at]
so it would return 1 for the added newline. We can add the number of
characters written by scsi_vpd_lun_serial() to return the correct number
of characters:

return ret + sysfs_emit_at(buf, ret, "\n");

This looks a bit too complicated/ugly to me. Instead, I will put a newline
manually and return the correct number of characters. PAGE_SIZE is passed
to scsi_vpd_lun_serial() so we don't sysfs_emit_at() to check it again.

buf[ret] = '\n';
return ret + 1;

Let me know if this sounds good to you.

Thank you!
Igor

>
> Thanks,
>
> Bart.
>