public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Cc: devel@driverdev.osuosl.org,
	Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Hans Verkuil <hverkuil@xs4all.nl>, Chen-Yu Tsai <wens@csie.org>,
	linux-arm-kernel@lists.infradead.org,
	Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: Re: [PATCH] media: cedrus: don't initialize pointers with zero
Date: Fri, 7 Dec 2018 16:22:58 +0300	[thread overview]
Message-ID: <20181207132258.GJ3095@unbuntlaptop> (raw)
In-Reply-To: <20181207093106.4f112d0b@coco.lan>

On Fri, Dec 07, 2018 at 09:31:06AM -0200, Mauro Carvalho Chehab wrote:
> Em Fri, 7 Dec 2018 12:14:50 +0100
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
> > On 12/07/2018 11:56 AM, Mauro Carvalho Chehab wrote:
> > > A common mistake is to assume that initializing a var with:
> > > 	struct foo f = { 0 };
> > > 
> > > Would initialize a zeroed struct. Actually, what this does is
> > > to initialize the first element of the struct to zero.
> > > 
> > > According to C99 Standard 6.7.8.21:
> > > 
> > >     "If there are fewer initializers in a brace-enclosed
> > >      list than there are elements or members of an aggregate,
> > >      or fewer characters in a string literal used to initialize
> > >      an array of known size than there are elements in the array,
> > >      the remainder of the aggregate shall be initialized implicitly
> > >      the same as objects that have static storage duration."
> > > 
> > > So, in practice, it could zero the entire struct, but, if the
> > > first element is not an integer, it will produce warnings:
> > > 
> > > 	drivers/staging/media/sunxi/cedrus/cedrus.c:drivers/staging/media/sunxi/cedrus/cedrus.c:78:49:  warning: Using plain integer as NULL pointer
> > > 	drivers/staging/media/sunxi/cedrus/cedrus_dec.c:drivers/staging/media/sunxi/cedrus/cedrus_dec.c:29:35:  warning: Using plain integer as NULL pointer
> > > 
> > > A proper way to initialize it with gcc is to use:
> > > 
> > > 	struct foo f = { };
> > > 
> > > But that seems to be a gcc extension. So, I decided to check upstream  
> > 
> > No, this is not a gcc extension. It's part of the latest C standard.
> 
> Sure? Where the C standard spec states that? I've been seeking for
> such info for a while, as '= {}' is also my personal preference.
> 
> I tried to build the Kernel with clang, just to be sure that this
> won't cause issues with the clang support

My test says that clang works with {}.

I support this in Smatch as well.

regards,
dan carpenter


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      parent reply	other threads:[~2018-12-07 13:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07 10:56 [PATCH] media: cedrus: don't initialize pointers with zero Mauro Carvalho Chehab
2018-12-07 11:14 ` Hans Verkuil
2018-12-07 11:31   ` Mauro Carvalho Chehab
2018-12-07 11:37     ` Hans Verkuil
2018-12-07 12:27       ` Ian Arkver
2018-12-07 12:58         ` Mauro Carvalho Chehab
2018-12-07 13:22     ` Dan Carpenter [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=20181207132258.GJ3095@unbuntlaptop \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-media@vger.kernel.org \
    --cc=maxime.ripard@bootlin.com \
    --cc=mchehab+samsung@kernel.org \
    --cc=mchehab@infradead.org \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=wens@csie.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