[PATCH 1/3] media: cxd2880: do not keep the attach state in a static variable
From: Enrico Lorenzoni
Date: Wed Nov 18 2026 - 17:07:53 EST
cxd2880_attach() declares the pointer to the new frontend state as a
function-local static:
static struct cxd2880_priv *priv;
The pointer is only used during the call, between the kzalloc() and the
assignment to fe->demodulator_priv, so there is no reason for it to
outlive the call. Being static, it is shared by every CXD2880 in the
system: when two devices are attached at the same time, for example two
Raspberry Pi TV HATs on SPI0 and SPI1 probed concurrently, one call can
overwrite the pointer set by the other before it is stored, leaving both
frontends on the same state and leaking the other allocation.
Make it an ordinary local variable.
This was found while running two CXD2880 tuners on one Raspberry Pi. I
have not captured a failure that I can attribute to this race; the same
change has been running in an out-of-tree build of this driver on two
Raspberry Pi systems with two tuners each for several weeks without
problems.
The change and this changelog were prepared with the help of an AI coding
assistant (Anthropic Claude). I have reviewed them.
Fixes: 9593810cd42a ("media: cxd2880: Add top level of the driver")
Signed-off-by: Enrico Lorenzoni <enricolorenzoni59@xxxxxxxxx>
---
drivers/media/dvb-frontends/cxd2880/cxd2880_top.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
index 0d058b59a..4daebb7ff 100644
--- a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
@@ -1879,7 +1879,7 @@ struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
int ret;
enum cxd2880_tnrdmd_chip_id chipid =
CXD2880_TNRDMD_CHIP_ID_UNKNOWN;
- static struct cxd2880_priv *priv;
+ struct cxd2880_priv *priv;
u8 data = 0;
if (!fe) {
--
2.47.3