From: David Sterba <dsterba@suse.cz>
To: Filipe Manana <fdmanana@gmail.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 3/3] btrfs: sysfs: protect reading label by lock
Date: Tue, 26 Apr 2016 23:44:03 +0200 [thread overview]
Message-ID: <20160426214403.GG29353@suse.cz> (raw)
In-Reply-To: <CAL3q7H7myUQ6FbkwTcr1Qb0oqyCt2iV=My2k_rf2P606oTWoNQ@mail.gmail.com>
On Tue, Apr 26, 2016 at 04:52:09PM +0100, Filipe Manana wrote:
> On Tue, Apr 26, 2016 at 3:32 PM, David Sterba <dsterba@suse.com> wrote:
> > If the label setting ioctl races with sysfs label handler, we could get
> > mixed result in the output, part old part new. We should either get the
> > old or new label. The chances to hit this race are low.
> >
> > Signed-off-by: David Sterba <dsterba@suse.com>
> > ---
> > fs/btrfs/sysfs.c | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> > index 3d14618ce54b..7b0da1dcb6df 100644
> > --- a/fs/btrfs/sysfs.c
> > +++ b/fs/btrfs/sysfs.c
> > @@ -367,7 +367,12 @@ static ssize_t btrfs_label_show(struct kobject *kobj,
> > {
> > struct btrfs_fs_info *fs_info = to_fs_info(kobj);
> > char *label = fs_info->super_copy->label;
> > - return snprintf(buf, PAGE_SIZE, label[0] ? "%s\n" : "%s", label);
> > +
> > + spin_lock(&fs_info->super_lock);
> > + snprintf(buf, PAGE_SIZE, label[0] ? "%s\n" : "%s", label);
> > + spin_unlock(&fs_info->super_lock);
> > +
> > + return buf;
>
> We should return a ssize_t value, not a char *. I.e. return what
> snprintf returns. This should make gcc emit a warning.
Indeed the warning was there and I overlooked it, last minute patches
before leaving. Thanks for catching it.
prev parent reply other threads:[~2016-04-26 21:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-26 14:32 [PATCH 0/3] Minor updates to sysfs David Sterba
2016-04-26 14:32 ` [PATCH 1/3] btrfs: add read-only check to sysfs handler of features David Sterba
2016-04-26 14:32 ` [PATCH 2/3] btrfs: add check to sysfs handler of label David Sterba
2016-04-26 14:32 ` [PATCH 3/3] btrfs: sysfs: protect reading label by lock David Sterba
2016-04-26 15:52 ` Filipe Manana
2016-04-26 21:44 ` David Sterba [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160426214403.GG29353@suse.cz \
--to=dsterba@suse.cz \
--cc=fdmanana@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).