Skip to contentSkip to conversation

media: mxl5007t: release tuner state when attach fails

PATCH New Alexandre Becholey 1 participant 1 message Nov 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: mxl5007t: release tuner state when attach fails

mxl5007t_attach() takes a shared tuner instance with hybrid_tuner_request_state() but sets fe->tuner_priv only on success. When a register access fails during attach, mxl5007t_release() finds no tuner_priv and the instance stays on the global list, still pointing to the bridge's i2c adapter. Once the USB device is gone, the next mxl5007t_attach() walks the list and uses the freed adapter.

Set fe->tuner_priv right after hybrid_tuner_request_state(), as the other users of the helper do.

The bug was found, and the reproducer and this fix were written, by AI agents (Claude Mythos and Claude Opus models). The analysis and the patch were reviewed by a human.

Fixes 2a83e4d5e40f ("V4L/DVB (8528): add support for MaxLinear MxL5007T silicon tuner")

---
A device that fails one tuner register access and then re-enumerates triggers it (KASAN, v7.3.1 and master 9d66f26fefac; clean with the fix). Reproducer available on request.

 drivers/media/tuners/mxl5007t.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/tuners/mxl5007t.c +2 -2
index 03c46a62bf26..4a765a7b0ad8 100644
@@ -844,6 +844,8 @@ struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
 	instance = hybrid_tuner_request_state(struct mxl5007t_state, state,
 					      hybrid_tuner_instance_list,
 					      i2c, addr, "mxl5007t");
+	/* let the fail path drop the reference taken above */
+	fe->tuner_priv = state;
 	switch (instance) {
 	case 0:
 		goto fail;
@@ -893,8 +895,6 @@ struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
 	if (mxl_fail(ret))
 		goto fail;
 
-	fe->tuner_priv = state;
-
 	mutex_unlock(&mxl5007t_list_mutex);
 
 	memcpy(&fe->ops.tuner_ops, &mxl5007t_tuner_ops,
Signature · 1 line
2.53.0