From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de ([195.135.220.15]:42376 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751881AbcDZVoQ (ORCPT ); Tue, 26 Apr 2016 17:44:16 -0400 Date: Tue, 26 Apr 2016 23:44:03 +0200 From: David Sterba To: Filipe Manana Cc: "linux-btrfs@vger.kernel.org" Subject: Re: [PATCH 3/3] btrfs: sysfs: protect reading label by lock Message-ID: <20160426214403.GG29353@suse.cz> Reply-To: dsterba@suse.cz References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: Sender: linux-btrfs-owner@vger.kernel.org List-ID: On Tue, Apr 26, 2016 at 04:52:09PM +0100, Filipe Manana wrote: > On Tue, Apr 26, 2016 at 3:32 PM, David Sterba 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 > > --- > > 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.