From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zijun Hu <zijun_hu@icloud.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org, Zijun Hu <quic_zijuhu@quicinc.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] driver core: Fix an uninitialized variable is used by __device_attach()
Date: Fri, 23 Aug 2024 09:14:12 +0800 [thread overview]
Message-ID: <2024082318-labored-blunderer-a897@gregkh> (raw)
In-Reply-To: <04c58410-13c8-4e50-a009-5715af0cded3@icloud.com>
On Fri, Aug 23, 2024 at 08:46:12AM +0800, Zijun Hu wrote:
> On 2024/8/23 08:02, Dmitry Torokhov wrote:
> > Hi,
> >
> > On Fri, Aug 23, 2024 at 07:46:09AM +0800, Zijun Hu wrote:
> >> From: Zijun Hu <quic_zijuhu@quicinc.com>
> >>
> >> An uninitialized variable @data.have_async may be used as analyzed
> >> by the following inline comments:
> >>
> >> static int __device_attach(struct device *dev, bool allow_async)
> >> {
> >> // if @allow_async is true.
> >>
> >> ...
> >> struct device_attach_data data = {
> >> .dev = dev,
> >> .check_async = allow_async,
> >> .want_async = false,
> >> };
> >> // @data.have_async is not initialized.
> >
> > No, in the presence of a structure initializer fields not explicitly
> > initialized will be set to 0 by the compiler.
> >
> really?
> do all C compilers have such behavior ?
Oh wait, if this were static, then yes, it would all be set to 0, sorry,
I misread this.
This is on the stack so it needs to be zeroed out explicitly. We should
set the whole thing to 0 and then set only the fields we want to
override to ensure it's all correct.
thanks,
greg k-h
next prev parent reply other threads:[~2024-08-23 1:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 23:46 [PATCH] driver core: Fix an uninitialized variable is used by __device_attach() Zijun Hu
2024-08-23 0:02 ` Dmitry Torokhov
2024-08-23 0:46 ` Zijun Hu
2024-08-23 1:14 ` Greg Kroah-Hartman [this message]
2024-08-23 1:25 ` Dmitry Torokhov
2024-08-23 6:11 ` Greg Kroah-Hartman
2024-08-23 6:25 ` Dmitry Torokhov
2024-08-23 10:52 ` Zijun Hu
2024-08-23 1:30 ` Dmitry Torokhov
2024-08-23 11:03 ` Zijun Hu
2024-08-23 0:14 ` Greg Kroah-Hartman
2024-08-23 0:38 ` Zijun Hu
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=2024082318-labored-blunderer-a897@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_zijuhu@quicinc.com \
--cc=rafael@kernel.org \
--cc=stable@vger.kernel.org \
--cc=zijun_hu@icloud.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