[lvc-project] [PATCH 1/2] media: dvb-usb-v2: add device init_ready flag

Nalivayko Sergey Sergey.Nalivayko at kaspersky.com
Fri Nov 7 18:44:25 MSK 2025


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 at kaspersky.com>
---
 drivers/media/usb/dvb-usb-v2/dvb_usb.h      | 3 +++
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 4 ++++
 2 files changed, 7 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..ecb929e006ba 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -389,6 +389,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




More information about the lvc-project mailing list