Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: renesas: div6: Combine clock-private and parent array allocation

Make div6_clock.parents[] a flexible array member, and use the new
struct_size() helper, to combine the allocation of the clock-private
structure and array of parent clocks.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>

+5 -14
+5 -14
drivers/clk/renesas/clk-div6.c
··· 30 30 * @div: divisor value (1-64) 31 31 * @src_shift: Shift to access the register bits to select the parent clock 32 32 * @src_width: Number of register bits to select the parent clock (may be 0) 33 - * @parents: Array to map from valid parent clocks indices to hardware indices 34 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 35 35 */ 36 36 struct div6_clock { 37 37 struct clk_hw hw; ··· 39 39 unsigned int div; 40 40 u32 src_shift; 41 41 u32 src_width; 42 - u8 *parents; 43 42 struct notifier_block nb; 43 + u8 parents[]; 44 44 }; 45 45 46 46 #define to_div6_clock(_hw) container_of(_hw, struct div6_clock, hw) ··· 221 221 struct clk *clk; 222 222 unsigned int i; 223 223 224 - clock = kzalloc(sizeof(*clock), GFP_KERNEL); 224 + clock = kzalloc(struct_size(clock, parents, num_parents), GFP_KERNEL); 225 225 if (!clock) 226 226 return ERR_PTR(-ENOMEM); 227 - 228 - clock->parents = kmalloc_array(num_parents, sizeof(*clock->parents), 229 - GFP_KERNEL); 230 - if (!clock->parents) { 231 - clk = ERR_PTR(-ENOMEM); 232 - goto free_clock; 233 - } 234 227 235 228 clock->reg = reg; 236 229 ··· 252 259 pr_err("%s: invalid number of parents for DIV6 clock %s\n", 253 260 __func__, name); 254 261 clk = ERR_PTR(-EINVAL); 255 - goto free_parents; 262 + goto free_clock; 256 263 } 257 264 258 265 /* Filter out invalid parents */ ··· 275 282 276 283 clk = clk_register(NULL, &clock->hw); 277 284 if (IS_ERR(clk)) 278 - goto free_parents; 285 + goto free_clock; 279 286 280 287 if (notifiers) { 281 288 clock->nb.notifier_call = cpg_div6_clock_notifier_call; ··· 284 291 285 292 return clk; 286 293 287 - free_parents: 288 - kfree(clock->parents); 289 294 free_clock: 290 295 kfree(clock); 291 296 return clk;