]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pinctrl: tegra: Duplicate pinmux functions table
authorThierry Reding <treding@nvidia.com>
Tue, 30 May 2023 10:53:07 +0000 (12:53 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 1 Jun 2023 11:17:35 +0000 (13:17 +0200)
The function table is filled with group information based on other
instance-specific data at runtime. However, the function table can be
shared between multiple instances, causing the ->probe() function for
one instance to overwrite the table of a previously probed instance.

Fix this by sharing only the function names and allocating a separate
function table for each instance.

Fixes: 5a0047360743 ("pinctrl: tegra: Separate Tegra194 instances")
Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20230530105308.1292852-1-thierry.reding@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/tegra/pinctrl-tegra.c
drivers/pinctrl/tegra/pinctrl-tegra.h
drivers/pinctrl/tegra/pinctrl-tegra114.c
drivers/pinctrl/tegra/pinctrl-tegra124.c
drivers/pinctrl/tegra/pinctrl-tegra194.c
drivers/pinctrl/tegra/pinctrl-tegra20.c
drivers/pinctrl/tegra/pinctrl-tegra210.c
drivers/pinctrl/tegra/pinctrl-tegra30.c

index 1729b7ddfa946a7835cc86239eec98d7218509cf..21e08fbd1df0e9287ffd62002bad2f8033304fee 100644 (file)
@@ -232,7 +232,7 @@ static const char *tegra_pinctrl_get_func_name(struct pinctrl_dev *pctldev,
 {
        struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
 
-       return pmx->soc->functions[function].name;
+       return pmx->functions[function].name;
 }
 
 static int tegra_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,
@@ -242,8 +242,8 @@ static int tegra_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,
 {
        struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
 
-       *groups = pmx->soc->functions[function].groups;
-       *num_groups = pmx->soc->functions[function].ngroups;
+       *groups = pmx->functions[function].groups;
+       *num_groups = pmx->functions[function].ngroups;
 
        return 0;
 }
@@ -795,10 +795,17 @@ int tegra_pinctrl_probe(struct platform_device *pdev,
        if (!pmx->group_pins)
                return -ENOMEM;
 
+       pmx->functions = devm_kcalloc(&pdev->dev, pmx->soc->nfunctions,
+                                     sizeof(*pmx->functions), GFP_KERNEL);
+       if (!pmx->functions)
+               return -ENOMEM;
+
        group_pins = pmx->group_pins;
+
        for (fn = 0; fn < soc_data->nfunctions; fn++) {
-               struct tegra_function *func = &soc_data->functions[fn];
+               struct tegra_function *func = &pmx->functions[fn];
 
+               func->name = pmx->soc->functions[fn];
                func->groups = group_pins;
 
                for (gn = 0; gn < soc_data->ngroups; gn++) {
index 6130cba7cce54870cc07c9e8a193681943388b41..b3289bdf727d8291ff6d23931eeb0b61ceae6576 100644 (file)
@@ -13,6 +13,7 @@ struct tegra_pmx {
        struct pinctrl_dev *pctl;
 
        const struct tegra_pinctrl_soc_data *soc;
+       struct tegra_function *functions;
        const char **group_pins;
 
        struct pinctrl_gpio_range gpio_range;
@@ -191,7 +192,7 @@ struct tegra_pinctrl_soc_data {
        const char *gpio_compatible;
        const struct pinctrl_pin_desc *pins;
        unsigned npins;
-       struct tegra_function *functions;
+       const char * const *functions;
        unsigned nfunctions;
        const struct tegra_pingroup *groups;
        unsigned ngroups;
index e72ab1eb23983289961c6c913c7d56c1e02d39d0..3d425b2018e78967890e4330ff02c1aaa3517b0b 100644 (file)
@@ -1452,12 +1452,9 @@ enum tegra_mux {
        TEGRA_MUX_VI_ALT3,
 };
 
-#define FUNCTION(fname)                                        \
-       {                                               \
-               .name = #fname,                         \
-       }
+#define FUNCTION(fname) #fname
 
-static struct tegra_function tegra114_functions[] = {
+static const char * const tegra114_functions[] = {
        FUNCTION(blink),
        FUNCTION(cec),
        FUNCTION(cldvfs),
index 26096c6b967e2f7ff8ac307c30c371adbe2ac35b..2a50c5c7516c379e8355e60987a44cce3619d421 100644 (file)
@@ -1611,12 +1611,9 @@ enum tegra_mux {
        TEGRA_MUX_VIMCLK2_ALT,
 };
 
-#define FUNCTION(fname)                                        \
-       {                                               \
-               .name = #fname,                         \
-       }
+#define FUNCTION(fname) #fname
 
-static struct tegra_function tegra124_functions[] = {
+static const char * const tegra124_functions[] = {
        FUNCTION(blink),
        FUNCTION(ccla),
        FUNCTION(cec),
index 277973c884344b2394cd6c6a431c870756371250..69f58df6289779233fc91373d97d1958d835167b 100644 (file)
@@ -1189,12 +1189,9 @@ enum tegra_mux_dt {
 };
 
 /* Make list of each function name */
-#define TEGRA_PIN_FUNCTION(lid)                        \
-       {                                       \
-               .name = #lid,                   \
-       }
+#define TEGRA_PIN_FUNCTION(lid) #lid
 
-static struct tegra_function tegra194_functions[] = {
+static const char * const tegra194_functions[] = {
        TEGRA_PIN_FUNCTION(rsvd0),
        TEGRA_PIN_FUNCTION(rsvd1),
        TEGRA_PIN_FUNCTION(rsvd2),
index 0dc2cf0d05b1ec83c8907cb25ed0a7c85f21d55a..737fc2000f66b91c595f17299d6555eae66f399d 100644 (file)
@@ -1889,12 +1889,9 @@ enum tegra_mux {
        TEGRA_MUX_XIO,
 };
 
-#define FUNCTION(fname)                                        \
-       {                                               \
-               .name = #fname,                         \
-       }
+#define FUNCTION(fname) #fname
 
-static struct tegra_function tegra20_functions[] = {
+static const char * const tegra20_functions[] = {
        FUNCTION(ahb_clk),
        FUNCTION(apb_clk),
        FUNCTION(audio_sync),
index b480f607fa16fc50d55a568f98006ad195be694a..9bb29146dfff7bd524e799b92e97020b47b7ec44 100644 (file)
@@ -1185,12 +1185,9 @@ enum tegra_mux {
        TEGRA_MUX_VIMCLK2,
 };
 
-#define FUNCTION(fname)                                        \
-       {                                               \
-               .name = #fname,                         \
-       }
+#define FUNCTION(fname) #fname
 
-static struct tegra_function tegra210_functions[] = {
+static const char * const tegra210_functions[] = {
        FUNCTION(aud),
        FUNCTION(bcl),
        FUNCTION(blink),
index 7299a371827f1892d8b2be7c6eb8d1b6e50df712..de5aa2d4d28d38f696cec733dafaa6ab68031bc8 100644 (file)
@@ -2010,12 +2010,9 @@ enum tegra_mux {
        TEGRA_MUX_VI_ALT3,
 };
 
-#define FUNCTION(fname)                                        \
-       {                                               \
-               .name = #fname,                         \
-       }
+#define FUNCTION(fname) #fname
 
-static struct tegra_function tegra30_functions[] = {
+static const char * const tegra30_functions[] = {
        FUNCTION(blink),
        FUNCTION(cec),
        FUNCTION(clk_12m_out),