From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jeremy Sowden <jeremy@azazel.net>
Cc: devel@driverdev.osuosl.org, linux-media@vger.kernel.org
Subject: Re: [PATCH v2 1/3] media: staging: atomisp: fix for sparse "using plain integer as NULL pointer" warnings.
Date: Wed, 29 Nov 2017 03:04:53 +0300 [thread overview]
Message-ID: <20171129000452.5mcbijzedww34ojc@mwanda> (raw)
In-Reply-To: <20171128233337.nwelcxvgaqtpgv5o@azazel.net>
On Tue, Nov 28, 2017 at 11:33:37PM +0000, Jeremy Sowden wrote:
> On 2017-11-28, at 17:15:24 +0300, Dan Carpenter wrote:
> > On Mon, Nov 27, 2017 at 12:44:48PM +0000, Jeremy Sowden wrote:
> > > The "address" member of struct ia_css_host_data is a
> > > pointer-to-char, so define default as NULL.
> > >
> > > --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/isp_param/interface/ia_css_isp_param_types.h
> > > +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/isp_param/interface/ia_css_isp_param_types.h
> > > @@ -95,7 +95,7 @@ union ia_css_all_memory_offsets {
> > > };
> > >
> > > #define IA_CSS_DEFAULT_ISP_MEM_PARAMS \
> > > - { { { { 0, 0 } } } }
> > > + { { { { NULL, 0 } } } }
> >
> > This define is way ugly and instead of making superficial changes, you
> > should try to eliminate it.
> >
> > People look at warnings as a bad thing but they are actually a
> > valuable resource which call attention to bad code. By making this
> > change you're kind of wasting the warning. The bad code is still
> > there, it's just swept under the rug but like a dead mouse carcass
> > it's still stinking up the living room. We should leave the warning
> > there until it irritates someone enough to fix it properly.
>
> Tracking down the offending initializer was definitely a pain.
>
> Compound literals with designated initializers would make this macro
> (and a number of others) easier to understand and more type-safe:
>
> #define IA_CSS_DEFAULT_ISP_MEM_PARAMS \
> - { { { { 0, 0 } } } }
> + (struct ia_css_isp_param_host_segments) { \
> + .params = { { \
> + (struct ia_css_host_data) { \
> + .address = NULL, \
> + .size = 0 \
> + } \
> + } } \
> + }
Using designated initializers is good, yes. Can't we just use an
empty initializer since this is all zeroed memory anyway?
(struct ia_css_isp_param_host_segments) { }
I haven't tried it.
>
> Unfortunately this default value is one end of a chain of default values
Yeah. A really long chain...
> used to initialize members of default values of enclosing structs where
> the outermost values are used to initialize some static variables:
>
> static enum ia_css_err
> init_pipe_defaults(enum ia_css_pipe_mode mode,
> struct ia_css_pipe *pipe,
> bool copy_pipe)
> {
> static struct ia_css_pipe default_pipe = IA_CSS_DEFAULT_PIPE;
> static struct ia_css_preview_settings prev = IA_CSS_DEFAULT_PREVIEW_SETTINGS;
> static struct ia_css_capture_settings capt = IA_CSS_DEFAULT_CAPTURE_SETTINGS;
> static struct ia_css_video_settings video = IA_CSS_DEFAULT_VIDEO_SETTINGS;
> static struct ia_css_yuvpp_settings yuvpp = IA_CSS_DEFAULT_YUVPP_SETTINGS;
>
> if (pipe == NULL) {
> IA_CSS_ERROR("NULL pipe parameter");
> return IA_CSS_ERR_INVALID_ARGUMENTS;
> }
>
> /* Initialize pipe to pre-defined defaults */
> *pipe = default_pipe;
>
> /* TODO: JB should not be needed, but temporary backward reference */
> switch (mode) {
> case IA_CSS_PIPE_MODE_PREVIEW:
> pipe->mode = IA_CSS_PIPE_ID_PREVIEW;
> pipe->pipe_settings.preview = prev;
> break;
> case IA_CSS_PIPE_MODE_CAPTURE:
> if (copy_pipe) {
> pipe->mode = IA_CSS_PIPE_ID_COPY;
> } else {
> pipe->mode = IA_CSS_PIPE_ID_CAPTURE;
> }
> pipe->pipe_settings.capture = capt;
> break;
> case IA_CSS_PIPE_MODE_VIDEO:
> pipe->mode = IA_CSS_PIPE_ID_VIDEO;
> pipe->pipe_settings.video = video;
> break;
> case IA_CSS_PIPE_MODE_ACC:
> pipe->mode = IA_CSS_PIPE_ID_ACC;
> break;
> case IA_CSS_PIPE_MODE_COPY:
> pipe->mode = IA_CSS_PIPE_ID_CAPTURE;
> break;
> case IA_CSS_PIPE_MODE_YUVPP:
> pipe->mode = IA_CSS_PIPE_ID_YUVPP;
> pipe->pipe_settings.yuvpp = yuvpp;
> break;
> default:
> return IA_CSS_ERR_INVALID_ARGUMENTS;
> }
>
> return IA_CSS_SUCCESS;
> }
>
> and GCC's limited support for using compound literals to initialize
> static variables doesn't stretch this far.
>
> I'm not convinced, however, that those variables actually achieve very
> much. If I change the code to assign the defaults directly, the problem
> goes away:
>
> diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c
> index f92b6a9f77eb..671b2c732a46 100644
> --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c
> +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c
> @@ -2291,25 +2291,19 @@ init_pipe_defaults(enum ia_css_pipe_mode mode,
> struct ia_css_pipe *pipe,
> bool copy_pipe)
> {
> - static struct ia_css_pipe default_pipe = IA_CSS_DEFAULT_PIPE;
> - static struct ia_css_preview_settings prev = IA_CSS_DEFAULT_PREVIEW_SETTINGS;
> - static struct ia_css_capture_settings capt = IA_CSS_DEFAULT_CAPTURE_SETTINGS;
> - static struct ia_css_video_settings video = IA_CSS_DEFAULT_VIDEO_SETTINGS;
> - static struct ia_css_yuvpp_settings yuvpp = IA_CSS_DEFAULT_YUVPP_SETTINGS;
> -
> if (pipe == NULL) {
> IA_CSS_ERROR("NULL pipe parameter");
> return IA_CSS_ERR_INVALID_ARGUMENTS;
> }
>
> /* Initialize pipe to pre-defined defaults */
> - *pipe = default_pipe;
> + *pipe = IA_CSS_DEFAULT_PIPE;
>
> /* TODO: JB should not be needed, but temporary backward reference */
> switch (mode) {
> case IA_CSS_PIPE_MODE_PREVIEW:
> pipe->mode = IA_CSS_PIPE_ID_PREVIEW;
> - pipe->pipe_settings.preview = prev;
> + pipe->pipe_settings.preview = IA_CSS_DEFAULT_PREVIEW_SETTINGS;
> break;
> case IA_CSS_PIPE_MODE_CAPTURE:
> if (copy_pipe) {
> @@ -2317,11 +2311,11 @@ init_pipe_defaults(enum ia_css_pipe_mode mode,
> } else {
> pipe->mode = IA_CSS_PIPE_ID_CAPTURE;
> }
> - pipe->pipe_settings.capture = capt;
> + pipe->pipe_settings.capture = IA_CSS_DEFAULT_CAPTURE_SETTINGS;
> break;
> case IA_CSS_PIPE_MODE_VIDEO:
> pipe->mode = IA_CSS_PIPE_ID_VIDEO;
> - pipe->pipe_settings.video = video;
> + pipe->pipe_settings.video = IA_CSS_DEFAULT_VIDEO_SETTINGS;
> break;
> case IA_CSS_PIPE_MODE_ACC:
> pipe->mode = IA_CSS_PIPE_ID_ACC;
> @@ -2331,7 +2325,7 @@ init_pipe_defaults(enum ia_css_pipe_mode mode,
> break;
> case IA_CSS_PIPE_MODE_YUVPP:
> pipe->mode = IA_CSS_PIPE_ID_YUVPP;
> - pipe->pipe_settings.yuvpp = yuvpp;
> + pipe->pipe_settings.yuvpp = IA_CSS_DEFAULT_YUVPP_SETTINGS;
> break;
> default:
> return IA_CSS_ERR_INVALID_ARGUMENTS;
>
> Does this seem reasonable or am I barking up the wrong tree?
Yes. Chopping the chain down and deleting as much of this code as
possible seems a good thing.
regards,
dan carpenter
next prev parent reply other threads:[~2017-11-29 0:05 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-27 11:30 [PATCH 0/3] Sparse fixes for the Atom ISP Staging Driver Jeremy Sowden
2017-11-27 11:30 ` [PATCH 1/3] media: staging: atomisp: address member of struct ia_css_host_data is a pointer-to-char, so define default as NULL Jeremy Sowden
2017-11-27 11:30 ` [PATCH 2/3] media: staging: atomisp: defined as static some const arrays which don't need external linkage Jeremy Sowden
2017-11-27 12:21 ` Greg KH
2017-11-27 12:44 ` [PATCH v2 0/3] Sparse fixes for the Atom ISP Staging Driver Jeremy Sowden
2017-11-27 12:44 ` [PATCH v2 1/3] media: staging: atomisp: fix for sparse "using plain integer as NULL pointer" warnings Jeremy Sowden
2017-11-28 14:15 ` Dan Carpenter
2017-11-28 23:33 ` Jeremy Sowden
2017-11-29 0:04 ` Dan Carpenter [this message]
2017-11-29 8:38 ` Jeremy Sowden
2017-11-29 13:58 ` Alan Cox
2017-11-30 21:40 ` [PATCH 0/3] Clean up of data-structure initialization in the CSS API Jeremy Sowden
2017-11-30 21:40 ` [PATCH 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers Jeremy Sowden
2017-12-01 15:07 ` Dan Carpenter
2017-12-01 15:31 ` Jeremy Sowden
2017-12-01 17:19 ` [PATCH v2 0/3] media: atomisp: clean up of data-structure initialization in the CSS API Jeremy Sowden
2017-12-01 17:19 ` [PATCH v2 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers Jeremy Sowden
2017-12-02 10:20 ` Dan Carpenter
2017-12-02 10:35 ` Jeremy Sowden
2017-12-02 20:41 ` Jeremy Sowden
2017-12-02 21:34 ` Jeremy Sowden
2017-12-02 22:11 ` [PATCH v4 0/3] media: atomisp: clean up of data-structure initialization in the CSS API Jeremy Sowden
2017-12-02 22:11 ` [PATCH v4 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers Jeremy Sowden
2017-12-19 12:07 ` Sakari Ailus
2017-12-21 19:31 ` Jeremy Sowden
2017-12-02 22:12 ` [PATCH v4 2/3] media: atomisp: delete zero-valued struct members Jeremy Sowden
2017-12-02 22:12 ` [PATCH v4 3/3] media: atomisp: delete empty default struct values Jeremy Sowden
2017-12-19 12:08 ` Sakari Ailus
2017-12-03 5:39 ` [PATCH v2 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers Dan Carpenter
2017-12-03 10:54 ` Jeremy Sowden
2017-12-01 17:19 ` [PATCH v2 2/3] media: atomisp: delete zero-valued struct members Jeremy Sowden
2017-12-01 17:41 ` Alan Cox
2017-12-02 15:00 ` Jeremy Sowden
2017-12-01 17:19 ` [PATCH v2 3/3] media: atomisp: delete empty default struct values Jeremy Sowden
2017-12-01 21:45 ` [PATCH v3 0/3] media: atomisp: clean up of data-structure initialization in the CSS API Jeremy Sowden
2017-12-01 21:45 ` [PATCH v3 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers Jeremy Sowden
2017-12-01 21:45 ` [PATCH v3 2/3] media: atomisp: delete zero-valued struct members Jeremy Sowden
2017-12-01 21:45 ` [PATCH v3 3/3] media: atomisp: delete empty default struct values Jeremy Sowden
2017-11-30 21:40 ` [PATCH 2/3] media: atomisp: delete zero-valued struct members Jeremy Sowden
2017-11-30 21:40 ` [PATCH 3/3] media: atomisp: delete empty default struct values Jeremy Sowden
2017-11-27 12:44 ` [PATCH v2 2/3] media: staging: atomisp: fixes for "symbol was not declared. Should it be static?" sparse warnings Jeremy Sowden
2017-11-27 12:44 ` [PATCH v2 3/3] media: staging: atomisp: fixed some checkpatch integer type warnings Jeremy Sowden
2017-11-27 19:09 ` Alan Cox
2017-11-27 22:02 ` Jeremy Sowden
2017-11-28 10:27 ` [PATCH v2 0/3] Sparse fixes for the Atom ISP Staging Driver Jeremy Sowden
2017-11-28 10:27 ` [PATCH v3 1/2] media: staging: atomisp: fix for sparse "using plain integer as NULL pointer" warnings Jeremy Sowden
2017-11-28 10:27 ` [PATCH v3 2/2] media: staging: atomisp: fixes for "symbol was not declared. Should it be static?" sparse warnings Jeremy Sowden
2017-11-29 8:48 ` [PATCH v2 0/3] Sparse fixes for the Atom ISP Staging Driver Sakari Ailus
2017-11-29 9:08 ` [PATCH 2/3] media: staging: atomisp: defined as static some const arrays which don't need external linkage Sakari Ailus
2017-11-29 9:15 ` Greg KH
2017-11-29 9:26 ` Sakari Ailus
2017-11-27 11:30 ` [PATCH 3/3] media: staging: atomisp: prefer s16 to int16_t Jeremy Sowden
2017-11-29 8:47 ` Sakari Ailus
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=20171129000452.5mcbijzedww34ojc@mwanda \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=jeremy@azazel.net \
--cc=linux-media@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