From: Marek Szyprowski <[email protected]>
device_get_match_data() function should not be used on the device other
than the one matched to the given driver, because it always returns the
match_data of the matched driver. In case of exynos-clkout driver, the
original code matches the OF IDs on the PARENT device, so replacing it
with of_device_get_match_data() broke the driver.
This has been already pointed once in commit 2bc5febd05ab ("clk: samsung:
Revert "clk: samsung: exynos-clkout: Use of_device_get_match_data()"").
To avoid further confusion, add a comment about this special case, which
requires direct of_match_device() call to pass custom IDs array.
This partially reverts commit 409c39ec92a35e3708f5b5798c78eae78512cd71.
Cc: <[email protected]>
Fixes: 409c39ec92a3 ("clk: Use device_get_match_data()")
Signed-off-by: Marek Szyprowski <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
Hi Stephen,
Please take this patch into current fixes v6.9.
Best regards,
Krzysztof
drivers/clk/samsung/clk-exynos-clkout.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/samsung/clk-exynos-clkout.c b/drivers/clk/samsung/clk-exynos-clkout.c
index 3484e6cc80ad..503c6f5b20d5 100644
--- a/drivers/clk/samsung/clk-exynos-clkout.c
+++ b/drivers/clk/samsung/clk-exynos-clkout.c
@@ -13,9 +13,9 @@
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
-#include <linux/property.h>
#define EXYNOS_CLKOUT_NR_CLKS 1
#define EXYNOS_CLKOUT_PARENTS 32
@@ -84,17 +84,24 @@ MODULE_DEVICE_TABLE(of, exynos_clkout_ids);
static int exynos_clkout_match_parent_dev(struct device *dev, u32 *mux_mask)
{
const struct exynos_clkout_variant *variant;
+ const struct of_device_id *match;
if (!dev->parent) {
dev_err(dev, "not instantiated from MFD\n");
return -EINVAL;
}
- variant = device_get_match_data(dev->parent);
- if (!variant) {
+ /*
+ * 'exynos_clkout_ids' arrays is not the ids array matched by
+ * the dev->parent driver, so of_device_get_match_data() or
+ * device_get_match_data() cannot be used here.
+ */
+ match = of_match_device(exynos_clkout_ids, dev->parent);
+ if (!match) {
dev_err(dev, "cannot match parent device\n");
return -EINVAL;
}
+ variant = match->data;
*mux_mask = variant->mux_mask;
--
2.43.0
Quoting Krzysztof Kozlowski (2024-04-30 11:46:56)
> From: Marek Szyprowski <[email protected]>
>
> device_get_match_data() function should not be used on the device other
> than the one matched to the given driver, because it always returns the
> match_data of the matched driver. In case of exynos-clkout driver, the
> original code matches the OF IDs on the PARENT device, so replacing it
> with of_device_get_match_data() broke the driver.
>
> This has been already pointed once in commit 2bc5febd05ab ("clk: samsung:
> Revert "clk: samsung: exynos-clkout: Use of_device_get_match_data()"").
> To avoid further confusion, add a comment about this special case, which
> requires direct of_match_device() call to pass custom IDs array.
>
> This partially reverts commit 409c39ec92a35e3708f5b5798c78eae78512cd71.
>
> Cc: <[email protected]>
> Fixes: 409c39ec92a3 ("clk: Use device_get_match_data()")
> Signed-off-by: Marek Szyprowski <[email protected]>
> Link: https://lore.kernel.org/r/[email protected]
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---
Applied to clk-fixes