diff mbox series

sandbox: p2sb: Silence compiler warning

Message ID 20200208145310.123544-1-sjg@chromium.org
State Accepted
Commit 8a770f9eb7be58439361e0ad30a0c122cd46dc7b
Headers show
Series sandbox: p2sb: Silence compiler warning | expand

Commit Message

Simon Glass Feb. 8, 2020, 2:53 p.m. UTC
Some compilers produce a warning about 'child' being used before init.
Silence this by setting to NULL at the start.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/misc/p2sb_emul.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bin Meng Feb. 8, 2020, 3:21 p.m. UTC | #1
On Sat, Feb 8, 2020 at 10:53 PM Simon Glass <sjg at chromium.org> wrote:
>
> Some compilers produce a warning about 'child' being used before init.
> Silence this by setting to NULL at the start.

Should be a compiler bug I think. Which compiler has such issue?

>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>  drivers/misc/p2sb_emul.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
Stephen Warren Feb. 10, 2020, 6:27 p.m. UTC | #2
On 2/8/20 8:21 AM, Bin Meng wrote:
> On Sat, Feb 8, 2020 at 10:53 PM Simon Glass <sjg at chromium.org> wrote:
>>
>> Some compilers produce a warning about 'child' being used before init.
>> Silence this by setting to NULL at the start.
> 
> Should be a compiler bug I think. Which compiler has such issue?

gcc 7.2.1 (Linaro build x86 -> ARM cross-compiler)

I don't believe this is a compiler bug.

For the compiler *not* to emit this warning, it would have to apply 
cross-function data flow analysis, which isn't something guaranteed by 
the C standard IIRC, since it's a very hard problem in general. So, not 
a compiler *bug* even if we'd like to see the compiler be smart about 
these things.
Tom Rini Feb. 10, 2020, 7:02 p.m. UTC | #3
On Mon, Feb 10, 2020 at 11:27:58AM -0700, Stephen Warren wrote:
> On 2/8/20 8:21 AM, Bin Meng wrote:
> > On Sat, Feb 8, 2020 at 10:53 PM Simon Glass <sjg at chromium.org> wrote:
> > > 
> > > Some compilers produce a warning about 'child' being used before init.
> > > Silence this by setting to NULL at the start.
> > 
> > Should be a compiler bug I think. Which compiler has such issue?
> 
> gcc 7.2.1 (Linaro build x86 -> ARM cross-compiler)
> 
> I don't believe this is a compiler bug.
> 
> For the compiler *not* to emit this warning, it would have to apply
> cross-function data flow analysis, which isn't something guaranteed by the C
> standard IIRC, since it's a very hard problem in general. So, not a compiler
> *bug* even if we'd like to see the compiler be smart about these things.

Is that a supported by them still compiler tho?  We don't see that
warning with the gcc-7.3.0 from the kernel.org toolchains we use (or
travis wouldn't have been clean for Simon).

I'm assuming you're using that compiler to test as it's something that
otherwise fits in your test workflow.
Simon Glass Feb. 10, 2020, 7:03 p.m. UTC | #4
Hi Stephen.

On Mon, 10 Feb 2020 at 11:28, Stephen Warren <swarren at wwwdotorg.org> wrote:
>
> On 2/8/20 8:21 AM, Bin Meng wrote:
> > On Sat, Feb 8, 2020 at 10:53 PM Simon Glass <sjg at chromium.org> wrote:
> >>
> >> Some compilers produce a warning about 'child' being used before init.
> >> Silence this by setting to NULL at the start.
> >
> > Should be a compiler bug I think. Which compiler has such issue?
>
> gcc 7.2.1 (Linaro build x86 -> ARM cross-compiler)
>
> I don't believe this is a compiler bug.

Well it is 'fixed' in 7.3.

>
> For the compiler *not* to emit this warning, it would have to apply
> cross-function data flow analysis, which isn't something guaranteed by
> the C standard IIRC, since it's a very hard problem in general. So, not
> a compiler *bug* even if we'd like to see the compiler be smart about
> these things.

Yes it is hard. I do think it is worth avoiding these problems where
we can. But in general I build with the latest kernel toolchain. I
think, sadly, if we really want to solve this problem we may need a
way to make buildman automatically build with multiple toolchains.

Regards,
Simon
Tom Rini Feb. 10, 2020, 7:08 p.m. UTC | #5
On Mon, Feb 10, 2020 at 12:03:26PM -0700, Simon Glass wrote:
> Hi Stephen.
> 
> On Mon, 10 Feb 2020 at 11:28, Stephen Warren <swarren at wwwdotorg.org> wrote:
> >
> > On 2/8/20 8:21 AM, Bin Meng wrote:
> > > On Sat, Feb 8, 2020 at 10:53 PM Simon Glass <sjg at chromium.org> wrote:
> > >>
> > >> Some compilers produce a warning about 'child' being used before init.
> > >> Silence this by setting to NULL at the start.
> > >
> > > Should be a compiler bug I think. Which compiler has such issue?
> >
> > gcc 7.2.1 (Linaro build x86 -> ARM cross-compiler)
> >
> > I don't believe this is a compiler bug.
> 
> Well it is 'fixed' in 7.3.
> 
> >
> > For the compiler *not* to emit this warning, it would have to apply
> > cross-function data flow analysis, which isn't something guaranteed by
> > the C standard IIRC, since it's a very hard problem in general. So, not
> > a compiler *bug* even if we'd like to see the compiler be smart about
> > these things.
> 
> Yes it is hard. I do think it is worth avoiding these problems where
> we can. But in general I build with the latest kernel toolchain. I
> think, sadly, if we really want to solve this problem we may need a
> way to make buildman automatically build with multiple toolchains.

Well, lets see what's going on here a bit more.  We're at the point
right now where it's painful that we're on gcc-7.3 for the most part and
can't easily / universally move up to a 9.something.
Simon Glass March 3, 2020, 2:46 a.m. UTC | #6
On Mon, Feb 10, 2020 at 12:03:26PM -0700, Simon Glass wrote:
> Hi Stephen.
>
> On Mon, 10 Feb 2020 at 11:28, Stephen Warren <swarren at wwwdotorg.org> wrote:
> >
> > On 2/8/20 8:21 AM, Bin Meng wrote:
> > > On Sat, Feb 8, 2020 at 10:53 PM Simon Glass <sjg at chromium.org> wrote:
> > >>
> > >> Some compilers produce a warning about 'child' being used before init.
> > >> Silence this by setting to NULL at the start.
> > >
> > > Should be a compiler bug I think. Which compiler has such issue?
> >
> > gcc 7.2.1 (Linaro build x86 -> ARM cross-compiler)
> >
> > I don't believe this is a compiler bug.
>
> Well it is 'fixed' in 7.3.
>
> >
> > For the compiler *not* to emit this warning, it would have to apply
> > cross-function data flow analysis, which isn't something guaranteed by
> > the C standard IIRC, since it's a very hard problem in general. So, not
> > a compiler *bug* even if we'd like to see the compiler be smart about
> > these things.
>
> Yes it is hard. I do think it is worth avoiding these problems where
> we can. But in general I build with the latest kernel toolchain. I
> think, sadly, if we really want to solve this problem we may need a
> way to make buildman automatically build with multiple toolchains.

Well, lets see what's going on here a bit more.  We're at the point
right now where it's painful that we're on gcc-7.3 for the most part and
can't easily / universally move up to a 9.something.
diff mbox series

Patch

diff --git a/drivers/misc/p2sb_emul.c b/drivers/misc/p2sb_emul.c
index c3795c59c0..6c71092f18 100644
--- a/drivers/misc/p2sb_emul.c
+++ b/drivers/misc/p2sb_emul.c
@@ -214,7 +214,7 @@  static int sandbox_p2sb_emul_map_physmem(struct udevice *dev,
 					 void **ptrp)
 {
 	struct p2sb_emul_priv *priv = dev_get_priv(dev);
-	struct udevice *child;
+	struct udevice *child = NULL;  /* Silence compiler warning */
 	unsigned int offset;
 	int barnum;
 	int ret;