[PATCH 06/28] mfd: ti_am335x_tscadc: Retrieve parent driver data via dev_get_drvdata()
From: Lee Jones
Date: Wed Oct 21 2026 - 08:16:15 EST
ti_tscadc_probe() stores the address of the local pointer variable
tscadc (&tscadc) into cell->platform_data so child devices can retrieve
the parent struct ti_tscadc_dev pointer via ti_tscadc_dev_get().
Although mfd_add_device() deep-copies platform_data before
ti_tscadc_probe() returns, both tscadc->cells[].platform_data and the
shallow MFD cell copy attached to the child platform devices retain a
stale pointer to the expired stack frame.
Set the parent platform driver data before registering the MFD child
devices, update ti_tscadc_dev_get() to retrieve the parent driver data
via dev_get_drvdata(p->dev.parent), and drop the redundant cell
platform_data assignment.
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/mfd/ti_am335x_tscadc.c | 7 ++-----
include/linux/mfd/ti_am335x_tscadc.h | 4 +---
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index 068c25401c6c..4afa9928eba5 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -268,8 +268,6 @@ static int ti_tscadc_probe(struct platform_device *pdev)
cell = &tscadc->cells[cell_idx++];
cell->name = tscadc->data->secondary_feature_name;
cell->of_compatible = tscadc->data->secondary_feature_compatible;
- cell->platform_data = &tscadc;
- cell->pdata_size = sizeof(tscadc);
}
/* ADC Cell */
@@ -277,16 +275,15 @@ static int ti_tscadc_probe(struct platform_device *pdev)
cell = &tscadc->cells[cell_idx++];
cell->name = tscadc->data->adc_feature_name;
cell->of_compatible = tscadc->data->adc_feature_compatible;
- cell->platform_data = &tscadc;
- cell->pdata_size = sizeof(tscadc);
}
+ platform_set_drvdata(pdev, tscadc);
+
err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
tscadc->cells, cell_idx, NULL, 0, NULL);
if (err < 0)
goto err_disable_clk;
- platform_set_drvdata(pdev, tscadc);
return 0;
err_disable_clk:
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index 4063b0614d90..4a048a897cf3 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -177,9 +177,7 @@ struct ti_tscadc_dev {
static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
{
- struct ti_tscadc_dev **tscadc_dev = p->dev.platform_data;
-
- return *tscadc_dev;
+ return dev_get_drvdata(p->dev.parent);
}
static inline bool ti_adc_with_touchscreen(struct ti_tscadc_dev *tscadc)
--
2.56.0.218.g1ec904b173-goog