]> git.baikalelectronics.ru Git - kernel.git/commitdiff
clk: at91: optimize pmc data allocation
authorMichał Mirosław <mirq-linux@rere.qmqm.pl>
Mon, 4 May 2020 22:37:56 +0000 (00:37 +0200)
committerStephen Boyd <sboyd@kernel.org>
Wed, 27 May 2020 03:22:34 +0000 (20:22 -0700)
Alloc whole data structure in one block. This makes the code shorter,
more efficient and easier to extend in following patch.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Link: https://lkml.kernel.org/r/fc6f6d67b8cee0beace4a9d9cca7431e5efa769d.1588630999.git.mirq-linux@rere.qmqm.pl
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
12 files changed:
drivers/clk/at91/at91rm9200.c
drivers/clk/at91/at91sam9260.c
drivers/clk/at91/at91sam9g45.c
drivers/clk/at91/at91sam9n12.c
drivers/clk/at91/at91sam9rl.c
drivers/clk/at91/at91sam9x5.c
drivers/clk/at91/pmc.c
drivers/clk/at91/pmc.h
drivers/clk/at91/sam9x60.c
drivers/clk/at91/sama5d2.c
drivers/clk/at91/sama5d3.c
drivers/clk/at91/sama5d4.c

index c44a431b6c9723770ee286f46499aa462e9c47d0..6f4e1151553d25fe797d1278582e67c484bfdccb 100644 (file)
@@ -187,7 +187,7 @@ static void __init at91rm9200_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(at91rm9200_pmc);
+       kfree(at91rm9200_pmc);
 }
 /*
  * While the TCB can be used as the clocksource, the system timer is most likely
index a9d4234758d7d42258a6686866bb20ba7aa0f847..946f03a09858c2b5f9fd3dd0784d62d0dbc69114 100644 (file)
@@ -462,7 +462,7 @@ static void __init at91sam926x_pmc_setup(struct device_node *np,
        return;
 
 err_free:
-       pmc_data_free(at91sam9260_pmc);
+       kfree(at91sam9260_pmc);
 }
 
 static void __init at91sam9260_pmc_setup(struct device_node *np)
index 38a7d2d2df0c748b66374d5a6c51f9fbd7225fd3..53e8252b8a63be33b7bccfaee6da5725d2f7f8c3 100644 (file)
@@ -210,7 +210,7 @@ static void __init at91sam9g45_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(at91sam9g45_pmc);
+       kfree(at91sam9g45_pmc);
 }
 /*
  * The TCB is used as the clocksource so its clock is needed early. This means
index 8bb39d2ba84b77ba8632d770a29f6c4cc36ed9ec..f3ae1cd3cb8d7c27c6d8c55d20f1853224c87d71 100644 (file)
@@ -228,7 +228,7 @@ static void __init at91sam9n12_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(at91sam9n12_pmc);
+       kfree(at91sam9n12_pmc);
 }
 /*
  * The TCB is used as the clocksource so its clock is needed early. This means
index 77fe83a73bf480815e3aca23678231fee960235d..cc739d214ae34864b140a33552431ebfaf9129eb 100644 (file)
@@ -166,6 +166,6 @@ static void __init at91sam9rl_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(at91sam9rl_pmc);
+       kfree(at91sam9rl_pmc);
 }
 CLK_OF_DECLARE_DRIVER(at91sam9rl_pmc, "atmel,at91sam9rl-pmc", at91sam9rl_pmc_setup);
index 086cf0b4955c2ec5591e740785abe658452853fb..aac99d6995689a1da4cb2a41e08169126626bbaa 100644 (file)
@@ -278,7 +278,7 @@ static void __init at91sam9x5_pmc_setup(struct device_node *np,
        return;
 
 err_free:
-       pmc_data_free(at91sam9x5_pmc);
+       kfree(at91sam9x5_pmc);
 }
 
 static void __init at91sam9g15_pmc_setup(struct device_node *np)
index e164069c81bd9520b9b386012d096ce671e7735c..ac8a76ca0266b0a680a2b1a51c5a91d8a882d0e9 100644 (file)
@@ -76,48 +76,30 @@ struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data)
        return ERR_PTR(-EINVAL);
 }
 
-void pmc_data_free(struct pmc_data *pmc_data)
-{
-       kfree(pmc_data->chws);
-       kfree(pmc_data->shws);
-       kfree(pmc_data->phws);
-       kfree(pmc_data->ghws);
-}
-
 struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
                                   unsigned int nperiph, unsigned int ngck)
 {
-       struct pmc_data *pmc_data = kzalloc(sizeof(*pmc_data), GFP_KERNEL);
+       unsigned int num_clks = ncore + nsystem + nperiph + ngck;
+       struct pmc_data *pmc_data;
 
+       pmc_data = kzalloc(struct_size(pmc_data, hwtable, num_clks),
+                          GFP_KERNEL);
        if (!pmc_data)
                return NULL;
 
        pmc_data->ncore = ncore;
-       pmc_data->chws = kcalloc(ncore, sizeof(struct clk_hw *), GFP_KERNEL);
-       if (!pmc_data->chws)
-               goto err;
+       pmc_data->chws = pmc_data->hwtable;
 
        pmc_data->nsystem = nsystem;
-       pmc_data->shws = kcalloc(nsystem, sizeof(struct clk_hw *), GFP_KERNEL);
-       if (!pmc_data->shws)
-               goto err;
+       pmc_data->shws = pmc_data->chws + ncore;
 
        pmc_data->nperiph = nperiph;
-       pmc_data->phws = kcalloc(nperiph, sizeof(struct clk_hw *), GFP_KERNEL);
-       if (!pmc_data->phws)
-               goto err;
+       pmc_data->phws = pmc_data->shws + nsystem;
 
        pmc_data->ngck = ngck;
-       pmc_data->ghws = kcalloc(ngck, sizeof(struct clk_hw *), GFP_KERNEL);
-       if (!pmc_data->ghws)
-               goto err;
+       pmc_data->ghws = pmc_data->phws + nperiph;
 
        return pmc_data;
-
-err:
-       pmc_data_free(pmc_data);
-
-       return NULL;
 }
 
 #ifdef CONFIG_PM
index 9b8db9cdcda5382b9fa64d608660916072066cdf..fc3ef772b9d9f8845b382cb790ef6b374dcd94f0 100644 (file)
@@ -24,6 +24,8 @@ struct pmc_data {
        struct clk_hw **phws;
        unsigned int ngck;
        struct clk_hw **ghws;
+
+       struct clk_hw *hwtable[];
 };
 
 struct clk_range {
@@ -95,7 +97,6 @@ struct clk_pcr_layout {
 #define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1)
 struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
                                   unsigned int nperiph, unsigned int ngck);
-void pmc_data_free(struct pmc_data *pmc_data);
 
 int of_at91_get_clk_range(struct device_node *np, const char *propname,
                          struct clk_range *range);
index cc19e8fb83bec717d3fd360928ed1088a9c2f06c..a7d4f648db264668ff9eb4c5228930fbc7469407 100644 (file)
@@ -299,7 +299,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(sam9x60_pmc);
+       kfree(sam9x60_pmc);
 }
 /* Some clks are used for a clocksource */
 CLK_OF_DECLARE(sam9x60_pmc, "microchip,sam9x60-pmc", sam9x60_pmc_setup);
index 73b287fbecb8c3de98e802c497c33f6aeff1def7..a86b42e40aef8a3b7fef28213828ed5ddc32213f 100644 (file)
@@ -351,6 +351,6 @@ static void __init sama5d2_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(sama5d2_pmc);
+       kfree(sama5d2_pmc);
 }
 CLK_OF_DECLARE_DRIVER(sama5d2_pmc, "atmel,sama5d2-pmc", sama5d2_pmc_setup);
index 88506f909c080b15194633ce12eaae4103a9c24d..914e6f225510b040542888882446b7884a2fd2b3 100644 (file)
@@ -231,7 +231,7 @@ static void __init sama5d3_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(sama5d3_pmc);
+       kfree(sama5d3_pmc);
 }
 /*
  * The TCB is used as the clocksource so its clock is needed early. This means
index a6dee4a3b6e48eade40a187be4b195cf0c7b17fe..4ca9a46195006f6b3e05a3de5971cb3bc296c002 100644 (file)
@@ -267,6 +267,6 @@ static void __init sama5d4_pmc_setup(struct device_node *np)
        return;
 
 err_free:
-       pmc_data_free(sama5d4_pmc);
+       kfree(sama5d4_pmc);
 }
 CLK_OF_DECLARE_DRIVER(sama5d4_pmc, "atmel,sama5d4-pmc", sama5d4_pmc_setup);