Re: [PATCH] driver core: Fix an uninitialized variable is used by __device_attach()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
> >>
> >> 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




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux