diff mbox series

soc: qcom: llcc: Handle a second device without data corruption

Message ID 20230926083229.2073890-1-u.kleine-koenig@pengutronix.de
State Accepted
Commit f1a1bc8775b26345aba2be278118999e7f661d3d
Headers show
Series soc: qcom: llcc: Handle a second device without data corruption | expand

Commit Message

Uwe Kleine-König Sept. 26, 2023, 8:32 a.m. UTC
Usually there is only one llcc device. But if there were a second, even
a failed probe call would modify the global drv_data pointer. So check
if drv_data is valid before overwriting it.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

the check added here is racy. To fix that race a lock would be needed to
protect drv_data. Alternatively (and cleaner) drv_data could be stored
using platform_set_drvdata(pdev, ...), but that cannot be done trivially
because there is a global function (llcc_slice_getd) that needs drv_data
but has no access to the platform device.

I don't know what is sensible here, so I just added this 90% fix. If you
want a more sophisticated solution, please create one yourself and just
consider my patch a problem report.

Best regards
Uwe

 drivers/soc/qcom/llcc-qcom.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/drivers/soc/qcom/llcc-qcom.c b/drivers/soc/qcom/llcc-qcom.c
index feb21637ac20..e3f262a50e4a 100644
--- a/drivers/soc/qcom/llcc-qcom.c
+++ b/drivers/soc/qcom/llcc-qcom.c
@@ -1120,6 +1120,9 @@  static int qcom_llcc_probe(struct platform_device *pdev)
 	u32 version;
 	struct regmap *regmap;
 
+	if (!IS_ERR(drv_data))
+		return -EBUSY;
+
 	drv_data = devm_kzalloc(dev, sizeof(*drv_data), GFP_KERNEL);
 	if (!drv_data) {
 		ret = -ENOMEM;