From: Lee Jones <lee.jones@linaro.org>
To: Daniel Thompson <daniel.thompson@linaro.org>
Cc: "linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
"linux-fbdev@vger.kernel.org" <linux-fbdev@vger.kernel.org>,
"b.zolnierkie@samsung.com" <b.zolnierkie@samsung.com>,
Marcel Ziswiler <marcel.ziswiler@toradex.com>,
"jingoohan1@gmail.com" <jingoohan1@gmail.com>,
"patches@linaro.org" <patches@linaro.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"thierry.reding@gmail.com" <thierry.reding@gmail.com>
Subject: Re: [PATCH] backlight: pwm_bl: Fix uninitialized variable
Date: Wed, 18 Jul 2018 15:55:44 +0000 [thread overview]
Message-ID: <20180718155544.GF4641@dell> (raw)
In-Reply-To: <20180718134103.bgwpgk7l6joxtjoa@holly.lan>
On Wed, 18 Jul 2018, Daniel Thompson wrote:
> On Wed, Jul 18, 2018 at 02:08:53PM +0100, Lee Jones wrote:
> > > > > > No, then we are back to the initial issue of num_steps
> > > > > > potentially not
> > > > > > being initialised. We really want both of_property_read_u32() to
> > > > > > succeed AND num_steps to actually be set.
> > > > >
> > > > > I also think num_steps should be pre-initialised.
> > >
> > > Yes, I guess it definitely does not hurt.
> > >
> > > > > Then it will only be set if of_property_read_u32() succeeds.
> > >
> > > Yes, but we still need to check for both, the function not failing and
> > > num_steps to actually be non zero.
> >
> > Why? You don't do anything differently if it fails.
>
> Only if you initialize num_steps...
>
> We should either initialize to zero and not worry about the return
> code[1] or we check the return code and not worry about
> initialization[2]. I don't think both are worthwhile.
>
> Whilst initialization can fix this specific instance we generally avoid
> overusing it since it messes up static analysis and, in this instance,
> distance from declaration to use is >25 lines, hence current patchset.
>
>
> Daniel.
>
>
> [1] https://lkml.org/lkml/2018/7/16/399
> [2] https://lkml.org/lkml/2018/7/16/1042
>
> Or...
>
> We check the return code and leave number
>
> num_steps is uninitialized and stack allocated so it only has a valid
> value if of_property_read_u32() succeeds.
>
> We can (and I originally did) fix the bug by initializing num_steps to 0
> but its quite some distance between declaration and use so I accepted
> Marcel's counter proposal to check the return code instead.
Only checking the return value of of_property_read_u32() is also
suitable.
--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
next prev parent reply other threads:[~2018-07-18 15:55 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-16 21:02 [PATCH] backlight: pwm_bl: Fix uninitialized variable Daniel Thompson
2018-07-18 8:09 ` Lee Jones
2018-07-18 8:12 ` Lee Jones
2018-07-18 8:22 ` Marcel Ziswiler
2018-07-18 9:53 ` Lee Jones
2018-07-18 10:12 ` Daniel Thompson
2018-07-18 12:57 ` Marcel Ziswiler
2018-07-18 13:08 ` Lee Jones
2018-07-18 13:26 ` Marcel Ziswiler
2018-07-18 13:41 ` Daniel Thompson
2018-07-18 15:55 ` Lee Jones [this message]
2018-07-18 16:34 ` Daniel Thompson
2018-07-23 7:25 ` Lee Jones
2018-07-18 8:26 ` Daniel Thompson
2018-07-19 16:19 ` [PATCH v2] " Daniel Thompson
2018-07-23 7:23 ` Lee Jones
2018-07-24 6:48 ` Daniel Thompson
2018-07-24 7:01 ` Daniel Thompson
2018-07-24 7:12 ` [PATCH v3] " Daniel Thompson
2018-07-24 23:56 ` Doug Anderson
2018-07-25 5:22 ` Lee Jones
2018-07-25 7:38 ` [PATCH v4] " Daniel Thompson
2018-07-25 8:03 ` Lee Jones
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=20180718155544.GF4641@dell \
--to=lee.jones@linaro.org \
--cc=b.zolnierkie@samsung.com \
--cc=daniel.thompson@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jingoohan1@gmail.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=marcel.ziswiler@toradex.com \
--cc=patches@linaro.org \
--cc=thierry.reding@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).