diff mbox series

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

Message ID 20230926083229.2073890-1-u.kleine-koenig@pengutronix.de (mailing list archive)
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(+)

Comments

Uwe Kleine-König Sept. 26, 2023, 9:02 a.m. UTC | #1
Hello,

On Tue, Sep 26, 2023 at 10:32:29AM +0200, Uwe Kleine-König wrote:
> 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.

if you consider this a fix, the corresponding tag line is:

Fixes: a3134fb09e0b ("drivers: soc: Add LLCC driver")

Best regards
Uwe
Bjorn Andersson Sept. 28, 2023, 12:34 a.m. UTC | #2
On Tue, 26 Sep 2023 10:32:29 +0200, Uwe Kleine-König wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] soc: qcom: llcc: Handle a second device without data corruption
      commit: f1a1bc8775b26345aba2be278118999e7f661d3d

Best regards,
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;