.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * r8a7790 Common Clock Framework support |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2013 Renesas Solutions Corp. |
---|
5 | 6 | * |
---|
6 | 7 | * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; version 2 of the License. |
---|
11 | 8 | */ |
---|
12 | 9 | |
---|
13 | 10 | #include <linux/clk-provider.h> |
---|
.. | .. |
---|
33 | 30 | * @div: divisor value (1-64) |
---|
34 | 31 | * @src_shift: Shift to access the register bits to select the parent clock |
---|
35 | 32 | * @src_width: Number of register bits to select the parent clock (may be 0) |
---|
36 | | - * @parents: Array to map from valid parent clocks indices to hardware indices |
---|
37 | 33 | * @nb: Notifier block to save/restore clock state for system resume |
---|
| 34 | + * @parents: Array to map from valid parent clocks indices to hardware indices |
---|
38 | 35 | */ |
---|
39 | 36 | struct div6_clock { |
---|
40 | 37 | struct clk_hw hw; |
---|
.. | .. |
---|
42 | 39 | unsigned int div; |
---|
43 | 40 | u32 src_shift; |
---|
44 | 41 | u32 src_width; |
---|
45 | | - u8 *parents; |
---|
46 | 42 | struct notifier_block nb; |
---|
| 43 | + u8 parents[]; |
---|
47 | 44 | }; |
---|
48 | 45 | |
---|
49 | 46 | #define to_div6_clock(_hw) container_of(_hw, struct div6_clock, hw) |
---|
.. | .. |
---|
219 | 216 | struct raw_notifier_head *notifiers) |
---|
220 | 217 | { |
---|
221 | 218 | unsigned int valid_parents; |
---|
222 | | - struct clk_init_data init = {}; |
---|
| 219 | + struct clk_init_data init; |
---|
223 | 220 | struct div6_clock *clock; |
---|
224 | 221 | struct clk *clk; |
---|
225 | 222 | unsigned int i; |
---|
226 | 223 | |
---|
227 | | - clock = kzalloc(sizeof(*clock), GFP_KERNEL); |
---|
| 224 | + clock = kzalloc(struct_size(clock, parents, num_parents), GFP_KERNEL); |
---|
228 | 225 | if (!clock) |
---|
229 | 226 | return ERR_PTR(-ENOMEM); |
---|
230 | | - |
---|
231 | | - clock->parents = kmalloc_array(num_parents, sizeof(*clock->parents), |
---|
232 | | - GFP_KERNEL); |
---|
233 | | - if (!clock->parents) { |
---|
234 | | - clk = ERR_PTR(-ENOMEM); |
---|
235 | | - goto free_clock; |
---|
236 | | - } |
---|
237 | 227 | |
---|
238 | 228 | clock->reg = reg; |
---|
239 | 229 | |
---|
.. | .. |
---|
262 | 252 | pr_err("%s: invalid number of parents for DIV6 clock %s\n", |
---|
263 | 253 | __func__, name); |
---|
264 | 254 | clk = ERR_PTR(-EINVAL); |
---|
265 | | - goto free_parents; |
---|
| 255 | + goto free_clock; |
---|
266 | 256 | } |
---|
267 | 257 | |
---|
268 | 258 | /* Filter out invalid parents */ |
---|
.. | .. |
---|
277 | 267 | /* Register the clock. */ |
---|
278 | 268 | init.name = name; |
---|
279 | 269 | init.ops = &cpg_div6_clock_ops; |
---|
280 | | - init.flags = CLK_IS_BASIC; |
---|
| 270 | + init.flags = 0; |
---|
281 | 271 | init.parent_names = parent_names; |
---|
282 | 272 | init.num_parents = valid_parents; |
---|
283 | 273 | |
---|
.. | .. |
---|
285 | 275 | |
---|
286 | 276 | clk = clk_register(NULL, &clock->hw); |
---|
287 | 277 | if (IS_ERR(clk)) |
---|
288 | | - goto free_parents; |
---|
| 278 | + goto free_clock; |
---|
289 | 279 | |
---|
290 | 280 | if (notifiers) { |
---|
291 | 281 | clock->nb.notifier_call = cpg_div6_clock_notifier_call; |
---|
.. | .. |
---|
294 | 284 | |
---|
295 | 285 | return clk; |
---|
296 | 286 | |
---|
297 | | -free_parents: |
---|
298 | | - kfree(clock->parents); |
---|
299 | 287 | free_clock: |
---|
300 | 288 | kfree(clock); |
---|
301 | 289 | return clk; |
---|
.. | .. |
---|
312 | 300 | |
---|
313 | 301 | num_parents = of_clk_get_parent_count(np); |
---|
314 | 302 | if (num_parents < 1) { |
---|
315 | | - pr_err("%s: no parent found for %s DIV6 clock\n", |
---|
316 | | - __func__, np->name); |
---|
| 303 | + pr_err("%s: no parent found for %pOFn DIV6 clock\n", |
---|
| 304 | + __func__, np); |
---|
317 | 305 | return; |
---|
318 | 306 | } |
---|
319 | 307 | |
---|
.. | .. |
---|
324 | 312 | |
---|
325 | 313 | reg = of_iomap(np, 0); |
---|
326 | 314 | if (reg == NULL) { |
---|
327 | | - pr_err("%s: failed to map %s DIV6 clock register\n", |
---|
328 | | - __func__, np->name); |
---|
| 315 | + pr_err("%s: failed to map %pOFn DIV6 clock register\n", |
---|
| 316 | + __func__, np); |
---|
329 | 317 | goto error; |
---|
330 | 318 | } |
---|
331 | 319 | |
---|
.. | .. |
---|
337 | 325 | |
---|
338 | 326 | clk = cpg_div6_register(clk_name, num_parents, parent_names, reg, NULL); |
---|
339 | 327 | if (IS_ERR(clk)) { |
---|
340 | | - pr_err("%s: failed to register %s DIV6 clock (%ld)\n", |
---|
341 | | - __func__, np->name, PTR_ERR(clk)); |
---|
| 328 | + pr_err("%s: failed to register %pOFn DIV6 clock (%ld)\n", |
---|
| 329 | + __func__, np, PTR_ERR(clk)); |
---|
342 | 330 | goto error; |
---|
343 | 331 | } |
---|
344 | 332 | |
---|