public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver core: Fix an uninitialized variable is used by __device_attach()
@ 2024-08-22 23:46 Zijun Hu
  2024-08-23  0:02 ` Dmitry Torokhov
  2024-08-23  0:14 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 12+ messages in thread
From: Zijun Hu @ 2024-08-22 23:46 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Dmitry Torokhov
  Cc: Zijun Hu, linux-kernel, Zijun Hu, stable

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.

	...
	ret = bus_for_each_drv(dev->bus, NULL, &data,
			__device_attach_driver);
	// @data.have_async must not be set by __device_attach_driver() if
 	// @dev->bus does not have driver which allows probe asynchronously

	if (!ret && allow_async && data.have_async) {
	// Above @data.have_async is not uninitialized but used.
		...
	}
	...
}

It may be unnecessary to trigger the second pass probing asynchronous
drivers for the device @dev.

Fixed by initializing @data.have_async to false.

Fixes: 765230b5f084 ("driver-core: add asynchronous probing support for drivers")
Cc: stable@vger.kernel.org
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/dd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 9b745ba54de1..b0c44b0846aa 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1021,6 +1021,7 @@ static int __device_attach(struct device *dev, bool allow_async)
 			.dev = dev,
 			.check_async = allow_async,
 			.want_async = false,
+			.have_async = false,
 		};
 
 		if (dev->parent)

---
base-commit: 87ee9981d1f86ee9b1623a46c7f9e4ac24461fe4
change-id: 20240823-fix_have_async-3a135618d91b

Best regards,
-- 
Zijun Hu <quic_zijuhu@quicinc.com>


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-08-23 11:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox