Skip to content

Commit 8ee7ec4

Browse files
Alex Elderkuba-moo
authored andcommitted
net: ipa: embed interconnect array in the power structure
Rather than allocating the interconnect array dynamically, represent the interconnects with a variable-length array at the end of the ipa_power structure. Signed-off-by: Alex Elder <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 63ac8cc commit 8ee7ec4

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

drivers/net/ipa/ipa_power.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,20 @@ struct ipa_power {
6767
spinlock_t spinlock; /* used with STOPPED/STARTED power flags */
6868
DECLARE_BITMAP(flags, IPA_POWER_FLAG_COUNT);
6969
u32 interconnect_count;
70-
struct icc_bulk_data *interconnect;
70+
struct icc_bulk_data interconnect[];
7171
};
7272

7373
/* Initialize interconnects required for IPA operation */
7474
static int ipa_interconnect_init(struct ipa_power *power, struct device *dev,
7575
const struct ipa_interconnect_data *data)
7676
{
7777
struct icc_bulk_data *interconnect;
78-
u32 count;
7978
int ret;
80-
81-
count = power->interconnect_count;
82-
interconnect = kcalloc(count, sizeof(*interconnect), GFP_KERNEL);
83-
if (!interconnect)
84-
return -ENOMEM;
85-
power->interconnect = interconnect;
79+
u32 i;
8680

8781
/* Initialize our interconnect data array for bulk operations */
88-
while (count--) {
82+
interconnect = &power->interconnect[0];
83+
for (i = 0; i < power->interconnect_count; i++) {
8984
/* interconnect->path is filled in by of_icc_bulk_get() */
9085
interconnect->name = data->name;
9186
interconnect->avg_bw = data->average_bandwidth;
@@ -97,23 +92,15 @@ static int ipa_interconnect_init(struct ipa_power *power, struct device *dev,
9792
ret = of_icc_bulk_get(dev, power->interconnect_count,
9893
power->interconnect);
9994
if (ret)
100-
goto err_free;
95+
return ret;
10196

10297
/* All interconnects are initially disabled */
10398
icc_bulk_disable(power->interconnect_count, power->interconnect);
10499

105100
/* Set the bandwidth values to be used when enabled */
106101
ret = icc_bulk_set_bw(power->interconnect_count, power->interconnect);
107102
if (ret)
108-
goto err_bulk_put;
109-
110-
return 0;
111-
112-
err_bulk_put:
113-
icc_bulk_put(power->interconnect_count, power->interconnect);
114-
err_free:
115-
kfree(power->interconnect);
116-
power->interconnect = NULL;
103+
icc_bulk_put(power->interconnect_count, power->interconnect);
117104

118105
return ret;
119106
}
@@ -122,8 +109,6 @@ static int ipa_interconnect_init(struct ipa_power *power, struct device *dev,
122109
static void ipa_interconnect_exit(struct ipa_power *power)
123110
{
124111
icc_bulk_put(power->interconnect_count, power->interconnect);
125-
kfree(power->interconnect);
126-
power->interconnect = NULL;
127112
}
128113

129114
/* Enable IPA power, enabling interconnects and the core clock */
@@ -372,6 +357,7 @@ ipa_power_init(struct device *dev, const struct ipa_power_data *data)
372357
{
373358
struct ipa_power *power;
374359
struct clk *clk;
360+
size_t size;
375361
int ret;
376362

377363
clk = clk_get(dev, "core");
@@ -388,7 +374,8 @@ ipa_power_init(struct device *dev, const struct ipa_power_data *data)
388374
goto err_clk_put;
389375
}
390376

391-
power = kzalloc(sizeof(*power), GFP_KERNEL);
377+
size = data->interconnect_count * sizeof(power->interconnect[0]);
378+
power = kzalloc(sizeof(*power) + size, GFP_KERNEL);
392379
if (!power) {
393380
ret = -ENOMEM;
394381
goto err_clk_put;

0 commit comments

Comments
 (0)