Message ID | 20200411154915.9408-1-tangbin@cmss.chinamobile.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: Fix backref.c selftest compilation warning | expand |
On 2020/4/11 下午11:49, Tang Bin wrote: > Fix missing braces compilation warning in the ARM > compiler environment: > fs/btrfs/backref.c: In function ‘is_shared_data_backref’: > fs/btrfs/backref.c:394:9: warning: missing braces around initializer [-Wmissing-braces] > struct prelim_ref target = {0}; > fs/btrfs/backref.c:394:9: warning: (near initialization for ‘target.rbnode’) [-Wmissing-braces] GCC version please. It looks like you're using an older GCC, as it's pretty common certain prebuild tool chain is still using outdated GCC. In my environment with GCC 9.2.0 natively (on aarch64) it's completely fine. Thus personally I recommend to build your own tool chain using buildroot, or run it natively, other than rely on prebuilt one. > > Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> > Signed-off-by: Shengju Zhang <zhangshengju@cmss.chinamobile.com> > --- > fs/btrfs/backref.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c > index 9c380e7..0cc0257 100644 > --- a/fs/btrfs/backref.c > +++ b/fs/btrfs/backref.c > @@ -391,7 +391,7 @@ static int is_shared_data_backref(struct preftrees *preftrees, u64 bytenr) > struct rb_node **p = &preftrees->direct.root.rb_root.rb_node; > struct rb_node *parent = NULL; > struct prelim_ref *ref = NULL; > - struct prelim_ref target = {0}; > + struct prelim_ref target = {}; In fact your fix could cause problem, as the original code is initializing all members to 0, but now it's uninitialized. You need to locate the root cause other than blindly follow the warning. Thanks, Qu > int result; > > target.parent = bytenr; >
Hi Qu: On 2020/4/12 8:52, Qu Wenruo wrote: > > On 2020/4/11 下午11:49, Tang Bin wrote: >> Fix missing braces compilation warning in the ARM >> compiler environment: >> fs/btrfs/backref.c: In function ‘is_shared_data_backref’: >> fs/btrfs/backref.c:394:9: warning: missing braces around initializer [-Wmissing-braces] >> struct prelim_ref target = {0}; >> fs/btrfs/backref.c:394:9: warning: (near initialization for ‘target.rbnode’) [-Wmissing-braces] > GCC version please. > > It looks like you're using an older GCC, as it's pretty common certain > prebuild tool chain is still using outdated GCC. > > In my environment with GCC 9.2.0 natively (on aarch64) it's completely fine. > Thus personally I recommend to build your own tool chain using > buildroot, or run it natively, other than rely on prebuilt one. My environment: PC : Ubuntu 16.04 Hardware : I.MX6ULL Tool Chain : arm-linux-gnueabihf-gcc (Linaro GCC 4.9-2017.01) 4.9.4 > > In fact your fix could cause problem, as the original code is > initializing all members to 0, but now it's uninitialized. > > You need to locate the root cause other than blindly follow the warning. In hardware experiment, this approach is feasible. Thanks. Tang Bin > >
On 2020/4/12 上午11:21, Tang Bin wrote: > Hi Qu: > > On 2020/4/12 8:52, Qu Wenruo wrote: >> >> On 2020/4/11 下午11:49, Tang Bin wrote: >>> Fix missing braces compilation warning in the ARM >>> compiler environment: >>> fs/btrfs/backref.c: In function ‘is_shared_data_backref’: >>> fs/btrfs/backref.c:394:9: warning: missing braces around >>> initializer [-Wmissing-braces] >>> struct prelim_ref target = {0}; >>> fs/btrfs/backref.c:394:9: warning: (near initialization for >>> ‘target.rbnode’) [-Wmissing-braces] >> GCC version please. >> >> It looks like you're using an older GCC, as it's pretty common certain >> prebuild tool chain is still using outdated GCC. >> >> In my environment with GCC 9.2.0 natively (on aarch64) it's completely >> fine. >> Thus personally I recommend to build your own tool chain using >> buildroot, or run it natively, other than rely on prebuilt one. > > My environment: > > PC : Ubuntu 16.04 > > Hardware : I.MX6ULL > > Tool Chain : arm-linux-gnueabihf-gcc (Linaro GCC 4.9-2017.01) 4.9.4 That's pretty old. You'd better fetch the newer version, as newer kernel may require higher version gcc. Or even build your own using tools like buildroot. Thanks, Qu > >> >> In fact your fix could cause problem, as the original code is >> initializing all members to 0, but now it's uninitialized. >> >> You need to locate the root cause other than blindly follow the warning. > > In hardware experiment, this approach is feasible. > > Thanks. > > Tang Bin > >> >> > >
On Sat, Apr 11, 2020 at 11:49:15PM +0800, Tang Bin wrote: > Fix missing braces compilation warning in the ARM > compiler environment: > fs/btrfs/backref.c: In function ‘is_shared_data_backref’: > fs/btrfs/backref.c:394:9: warning: missing braces around initializer [-Wmissing-braces] > struct prelim_ref target = {0}; > fs/btrfs/backref.c:394:9: warning: (near initialization for ‘target.rbnode’) [-Wmissing-braces] > > Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> > Signed-off-by: Shengju Zhang <zhangshengju@cmss.chinamobile.com> > --- > fs/btrfs/backref.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c > index 9c380e7..0cc0257 100644 > --- a/fs/btrfs/backref.c > +++ b/fs/btrfs/backref.c > @@ -391,7 +391,7 @@ static int is_shared_data_backref(struct preftrees *preftrees, u64 bytenr) > struct rb_node **p = &preftrees->direct.root.rb_root.rb_node; > struct rb_node *parent = NULL; > struct prelim_ref *ref = NULL; > - struct prelim_ref target = {0}; > + struct prelim_ref target = {}; I wonder why this initialization is a problem while there are about 20 other uses of "{0}". The warning is about the embedded rbnode, but why does a more recent compiler not warn about that? Is this a missing fix from the one you use? I don't mind fixing compiler warnings as long as it bothers enough people, eg. we have fixes reported by gcc 7 but I'm hesitant to fix anything older without a good reason.
On Tue, Apr 14, 2020 at 05:19:31PM +0200, David Sterba wrote: > On Sat, Apr 11, 2020 at 11:49:15PM +0800, Tang Bin wrote: > > Fix missing braces compilation warning in the ARM > > compiler environment: > > fs/btrfs/backref.c: In function ‘is_shared_data_backref’: > > fs/btrfs/backref.c:394:9: warning: missing braces around initializer [-Wmissing-braces] > > struct prelim_ref target = {0}; > > fs/btrfs/backref.c:394:9: warning: (near initialization for ‘target.rbnode’) [-Wmissing-braces] > > > > Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> > > Signed-off-by: Shengju Zhang <zhangshengju@cmss.chinamobile.com> > > --- > > fs/btrfs/backref.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c > > index 9c380e7..0cc0257 100644 > > --- a/fs/btrfs/backref.c > > +++ b/fs/btrfs/backref.c > > @@ -391,7 +391,7 @@ static int is_shared_data_backref(struct preftrees *preftrees, u64 bytenr) > > struct rb_node **p = &preftrees->direct.root.rb_root.rb_node; > > struct rb_node *parent = NULL; > > struct prelim_ref *ref = NULL; > > - struct prelim_ref target = {0}; > > + struct prelim_ref target = {}; > > I wonder why this initialization is a problem while there are about 20 > other uses of "{0}". The warning is about the embedded rbnode, but why > does a more recent compiler not warn about that? Is this a missing fix > from the one you use? > > I don't mind fixing compiler warnings as long as it bothers enough > people, eg. we have fixes reported by gcc 7 but I'm hesitant to fix > anything older without a good reason. This seems to be the bug report https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 "Bug 53119 - -Wmissing-braces wrongly warns about universal zero initializer {0} "
Hi David: On 2020/4/14 23:22, David Sterba wrote: > On Tue, Apr 14, 2020 at 05:19:31PM +0200, David Sterba wrote: >> On Sat, Apr 11, 2020 at 11:49:15PM +0800, Tang Bin wrote: >>> Fix missing braces compilation warning in the ARM >>> compiler environment: >>> fs/btrfs/backref.c: In function ‘is_shared_data_backref’: >>> fs/btrfs/backref.c:394:9: warning: missing braces around initializer [-Wmissing-braces] >>> struct prelim_ref target = {0}; >>> fs/btrfs/backref.c:394:9: warning: (near initialization for ‘target.rbnode’) [-Wmissing-braces] >>> >>> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> >>> Signed-off-by: Shengju Zhang <zhangshengju@cmss.chinamobile.com> >>> --- >>> fs/btrfs/backref.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c >>> index 9c380e7..0cc0257 100644 >>> --- a/fs/btrfs/backref.c >>> +++ b/fs/btrfs/backref.c >>> @@ -391,7 +391,7 @@ static int is_shared_data_backref(struct preftrees *preftrees, u64 bytenr) >>> struct rb_node **p = &preftrees->direct.root.rb_root.rb_node; >>> struct rb_node *parent = NULL; >>> struct prelim_ref *ref = NULL; >>> - struct prelim_ref target = {0}; >>> + struct prelim_ref target = {}; >> I wonder why this initialization is a problem while there are about 20 >> other uses of "{0}". The warning is about the embedded rbnode, but why >> does a more recent compiler not warn about that? Is this a missing fix >> from the one you use? >> >> I don't mind fixing compiler warnings as long as it bothers enough >> people, eg. we have fixes reported by gcc 7 but I'm hesitant to fix >> anything older without a good reason. > This seems to be the bug report > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 > "Bug 53119 - -Wmissing-braces wrongly warns about universal zero > initializer {0} " Thank you for your reply. My tool chain is "arm-linux-gnueabihf-gcc(Linaro GCC 4.9-2017.01) 4.9.4". I was trying to do an experiment on the hardware so I compiled it and there was a warning. Maybe as Qu Wenruo said possible tools are old? Thank you for your patience, Tang Bin
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 9c380e7..0cc0257 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -391,7 +391,7 @@ static int is_shared_data_backref(struct preftrees *preftrees, u64 bytenr) struct rb_node **p = &preftrees->direct.root.rb_root.rb_node; struct rb_node *parent = NULL; struct prelim_ref *ref = NULL; - struct prelim_ref target = {0}; + struct prelim_ref target = {}; int result; target.parent = bytenr;