Skip to content

Commit 7425f24

Browse files
osctobebebarino
authored andcommitted
clk: at91: optimize pmc data allocation
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 <[email protected]> Link: https://lkml.kernel.org/r/fc6f6d67b8cee0beace4a9d9cca7431e5efa769d.1588630999.git.mirq-linux@rere.qmqm.pl Acked-by: Alexandre Belloni <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent e218325 commit 7425f24

File tree

12 files changed

+20
-37
lines changed

12 files changed

+20
-37
lines changed

drivers/clk/at91/at91rm9200.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static void __init at91rm9200_pmc_setup(struct device_node *np)
187187
return;
188188

189189
err_free:
190-
pmc_data_free(at91rm9200_pmc);
190+
kfree(at91rm9200_pmc);
191191
}
192192
/*
193193
* While the TCB can be used as the clocksource, the system timer is most likely

drivers/clk/at91/at91sam9260.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static void __init at91sam926x_pmc_setup(struct device_node *np,
462462
return;
463463

464464
err_free:
465-
pmc_data_free(at91sam9260_pmc);
465+
kfree(at91sam9260_pmc);
466466
}
467467

468468
static void __init at91sam9260_pmc_setup(struct device_node *np)

drivers/clk/at91/at91sam9g45.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void __init at91sam9g45_pmc_setup(struct device_node *np)
210210
return;
211211

212212
err_free:
213-
pmc_data_free(at91sam9g45_pmc);
213+
kfree(at91sam9g45_pmc);
214214
}
215215
/*
216216
* The TCB is used as the clocksource so its clock is needed early. This means

drivers/clk/at91/at91sam9n12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static void __init at91sam9n12_pmc_setup(struct device_node *np)
228228
return;
229229

230230
err_free:
231-
pmc_data_free(at91sam9n12_pmc);
231+
kfree(at91sam9n12_pmc);
232232
}
233233
/*
234234
* The TCB is used as the clocksource so its clock is needed early. This means

drivers/clk/at91/at91sam9rl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,6 @@ static void __init at91sam9rl_pmc_setup(struct device_node *np)
166166
return;
167167

168168
err_free:
169-
pmc_data_free(at91sam9rl_pmc);
169+
kfree(at91sam9rl_pmc);
170170
}
171171
CLK_OF_DECLARE_DRIVER(at91sam9rl_pmc, "atmel,at91sam9rl-pmc", at91sam9rl_pmc_setup);

drivers/clk/at91/at91sam9x5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static void __init at91sam9x5_pmc_setup(struct device_node *np,
278278
return;
279279

280280
err_free:
281-
pmc_data_free(at91sam9x5_pmc);
281+
kfree(at91sam9x5_pmc);
282282
}
283283

284284
static void __init at91sam9g15_pmc_setup(struct device_node *np)

drivers/clk/at91/pmc.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,48 +76,30 @@ struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data)
7676
return ERR_PTR(-EINVAL);
7777
}
7878

79-
void pmc_data_free(struct pmc_data *pmc_data)
80-
{
81-
kfree(pmc_data->chws);
82-
kfree(pmc_data->shws);
83-
kfree(pmc_data->phws);
84-
kfree(pmc_data->ghws);
85-
}
86-
8779
struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
8880
unsigned int nperiph, unsigned int ngck)
8981
{
90-
struct pmc_data *pmc_data = kzalloc(sizeof(*pmc_data), GFP_KERNEL);
82+
unsigned int num_clks = ncore + nsystem + nperiph + ngck;
83+
struct pmc_data *pmc_data;
9184

85+
pmc_data = kzalloc(struct_size(pmc_data, hwtable, num_clks),
86+
GFP_KERNEL);
9287
if (!pmc_data)
9388
return NULL;
9489

9590
pmc_data->ncore = ncore;
96-
pmc_data->chws = kcalloc(ncore, sizeof(struct clk_hw *), GFP_KERNEL);
97-
if (!pmc_data->chws)
98-
goto err;
91+
pmc_data->chws = pmc_data->hwtable;
9992

10093
pmc_data->nsystem = nsystem;
101-
pmc_data->shws = kcalloc(nsystem, sizeof(struct clk_hw *), GFP_KERNEL);
102-
if (!pmc_data->shws)
103-
goto err;
94+
pmc_data->shws = pmc_data->chws + ncore;
10495

10596
pmc_data->nperiph = nperiph;
106-
pmc_data->phws = kcalloc(nperiph, sizeof(struct clk_hw *), GFP_KERNEL);
107-
if (!pmc_data->phws)
108-
goto err;
97+
pmc_data->phws = pmc_data->shws + nsystem;
10998

11099
pmc_data->ngck = ngck;
111-
pmc_data->ghws = kcalloc(ngck, sizeof(struct clk_hw *), GFP_KERNEL);
112-
if (!pmc_data->ghws)
113-
goto err;
100+
pmc_data->ghws = pmc_data->phws + nperiph;
114101

115102
return pmc_data;
116-
117-
err:
118-
pmc_data_free(pmc_data);
119-
120-
return NULL;
121103
}
122104

123105
#ifdef CONFIG_PM

drivers/clk/at91/pmc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct pmc_data {
2424
struct clk_hw **phws;
2525
unsigned int ngck;
2626
struct clk_hw **ghws;
27+
28+
struct clk_hw *hwtable[];
2729
};
2830

2931
struct clk_range {
@@ -95,7 +97,6 @@ struct clk_pcr_layout {
9597
#define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1)
9698
struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
9799
unsigned int nperiph, unsigned int ngck);
98-
void pmc_data_free(struct pmc_data *pmc_data);
99100

100101
int of_at91_get_clk_range(struct device_node *np, const char *propname,
101102
struct clk_range *range);

drivers/clk/at91/sam9x60.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np)
299299
return;
300300

301301
err_free:
302-
pmc_data_free(sam9x60_pmc);
302+
kfree(sam9x60_pmc);
303303
}
304304
/* Some clks are used for a clocksource */
305305
CLK_OF_DECLARE(sam9x60_pmc, "microchip,sam9x60-pmc", sam9x60_pmc_setup);

drivers/clk/at91/sama5d2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,6 @@ static void __init sama5d2_pmc_setup(struct device_node *np)
351351
return;
352352

353353
err_free:
354-
pmc_data_free(sama5d2_pmc);
354+
kfree(sama5d2_pmc);
355355
}
356356
CLK_OF_DECLARE_DRIVER(sama5d2_pmc, "atmel,sama5d2-pmc", sama5d2_pmc_setup);

0 commit comments

Comments
 (0)