On Wed, Oct 09, 2024 at 11:24:06AM GMT, Hongbo Li wrote:
> 
> 
> On 2024/10/9 11:13, Kent Overstreet wrote:
> > On Thu, Sep 26, 2024 at 10:00:00AM GMT, Hongbo Li wrote:
> > > printbuf.buf may be NULL if allocation_failure is true. Check
> > > for this prior to using it as a seq_puts() source.
> > > 
> > > Fixes: fa8e94faeece ("bcachefs: Heap allocate printbufs")
> > > Signed-off-by: David Disseldorp <[email protected]>
> > > Signed-off-by: Hongbo Li <[email protected]>
> > 
> > Let's do this by adding a proper printbuf_err() helper - have it return
> > -ENOMEM on allocation failure, and do a normal
> > if (ret)
> >     goto err;
> > 
> > so it looks more standard.
> > 
> > > ---
> > >   fs/bcachefs/fs.c | 7 +++++--
> > >   1 file changed, 5 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
> > > index e774cb3e6b1a..d6e26b5056f3 100644
> > > --- a/fs/bcachefs/fs.c
> > > +++ b/fs/bcachefs/fs.c
> > > @@ -1923,13 +1923,16 @@ static int bch2_show_options(struct seq_file 
> > > *seq, struct dentry *root)
> > >   {
> > >           struct bch_fs *c = root->d_sb->s_fs_info;
> > >           struct printbuf buf = PRINTBUF;
> > > + int ret = 0;
> > >           bch2_opts_to_text(&buf, c->opts, c, c->disk_sb.sb,
> > >                             OPT_MOUNT, OPT_HIDDEN, OPT_SHOW_MOUNT_STYLE);
> > >           printbuf_nul_terminate(&buf);
> > > - seq_puts(seq, buf.buf);
> 
> like this?:
>         ret = printbuf_err(buf);
>         if (ret)
>             goto err:
>         seq_printf(seq, ",%s", buf.buf);
>         printbuf_exit(&buf);
> 
> err:
>         return ret;

Just so

Reply via email to