On Thu, Apr 17, 2025 at 11:27:42AM -0500, Eric Blake wrote:
> On Mon, Apr 14, 2025 at 04:12:13PM -0400, Stefan Hajnoczi wrote:
> > Populate the pdiscard_alignment block limit so the block layer is able
> > align discard requests correctly.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com>
> > ---
> >  block/file-posix.c | 67 +++++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 66 insertions(+), 1 deletion(-)
> > 
> 
> > +static int get_sysfs_u32_val(struct stat *st, const char *attribute,
> > +                             uint32_t *u32)
> > +{
> > +    g_autofree char *str = NULL;
> > +    const char *end;
> > +    unsigned int val;
> > +    int ret;
> > +
> > +    ret = get_sysfs_str_val(st, attribute, &str);
> > +    if (ret < 0) {
> > +        return ret;
> > +    }
> > +
> > +    /* The file is ended with '\n', pass 'end' to accept that. */
> > +    ret = qemu_strtoui(str, &end, 10, &val);
> > +    if (ret == 0 && end && *end == '\0') {
> 
> This doesn't match the comment.  If we expect the file contents to end
> in \n, then this should be checking *end == '\n', not '\0'.

Then again, get_sysfs_str_val() strips the trailing \n, so the code is
correct, and the comment is fishy.

But now, if we expect there to be no trailing garbage (after we've
stripped the \n when getting the string), we could simplify by passing
NULL instead of &end to qemu_strtoui, and merely rely on "if (ret == 0)".

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to