[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251107181623.2139080-2-Sergey.Nalivayko@kaspersky.com>
Date: Fri, 7 Nov 2025 21:16:22 +0300
From: Nalivayko Sergey <Sergey.Nalivayko@...persky.com>
To: <linux-media@...r.kernel.org>
CC: Nalivayko Sergey <Sergey.Nalivayko@...persky.com>,
<linux-kernel@...r.kernel.org>, <lvc-project@...uxtesting.org>, Mauro
Carvalho Chehab <mchehab@...nel.org>, Michael Krufky <mkrufky@...uxtv.org>
Subject: [PATCH v2 1/2] media: dvb-usb-v2: add device init_ready flag
The current implementation of dvb-usb-v2 initializes device in
dvb_usbv2_probe() while making it immediately available for use in the I2C,
Remote Control, demux and potentially other kernel subsystems before
the driver has fully completed initialization. As a result, the device
becomes accessible through these subsystem interfaces prematurely,
allowing to invoke read/write operations on the device before it is
fully initialized.
Introduce an atomic init_ready flag in struct dvb_usb_device for
the DVB-USB-V2 driver.
Allow driver code to check this flag before performing actions
that access device state (for example I2C reads) which may race
with device initialization.
Signed-off-by: Nalivayko Sergey <Sergey.Nalivayko@...persky.com>
---
drivers/media/usb/dvb-usb-v2/dvb_usb.h | 4 ++++
drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb.h b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
index ecdc20d45132..d4c22f979abd 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -365,6 +365,7 @@ struct dvb_usb_adapter {
* @usb_mutex: mutex for usb control messages
* @i2c_mutex: mutex for i2c-transfers
* @i2c_adap: device's i2c-adapter
+ * @init_ready: set when the device is initialized
* @adapter: adapters
* @rc_dev: rc device for the remote control
* @rc_phys: rc path
@@ -389,6 +390,9 @@ struct dvb_usb_device {
struct mutex i2c_mutex;
struct i2c_adapter i2c_adap;
+ /* Check in drivers to prevent read from uninitialized device */
+ atomic_t init_ready;
+
struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
/* remote control */
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index f1c79f351ec8..d1cd68f242cc 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -988,6 +988,8 @@ int dvb_usbv2_probe(struct usb_interface *intf,
exit:
usb_set_intfdata(intf, d);
+ atomic_set(&d->init_ready, 1);
+
return 0;
err_free_all:
dvb_usbv2_exit(d);
@@ -1012,6 +1014,8 @@ void dvb_usbv2_disconnect(struct usb_interface *intf)
dev_dbg(&d->udev->dev, "%s: bInterfaceNumber=%d\n", __func__,
intf->cur_altsetting->desc.bInterfaceNumber);
+ atomic_set(&d->init_ready, 0);
+
if (d->props->exit)
d->props->exit(d);
--
2.39.5
Powered by blists - more mailing lists