Re: [PATCH] clk-kona-setup: Use kmalloc_array() in parent_process()

From: Alex Elder
Date: Wed Sep 14 2016 - 14:45:21 EST


On 09/14/2016 01:40 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> Date: Wed, 14 Sep 2016 20:26:05 +0200
>
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "kmalloc_array".
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>

Probably not needed in practice, but safer nevertheless.

Reviewed-by: Alex Elder <elder@xxxxxxxxxx>

> ---
> drivers/clk/bcm/clk-kona-setup.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/bcm/clk-kona-setup.c b/drivers/clk/bcm/clk-kona-setup.c
> index 526b0b0..a2e7e91 100644
> --- a/drivers/clk/bcm/clk-kona-setup.c
> +++ b/drivers/clk/bcm/clk-kona-setup.c
> @@ -586,8 +586,9 @@ static u32 *parent_process(const char *clocks[],
> }
>
> /* There is at least one parent, so allocate a selector array */
> -
> - parent_sel = kmalloc(parent_count * sizeof(*parent_sel), GFP_KERNEL);
> + parent_sel = kmalloc_array(parent_count,
> + sizeof(*parent_sel),
> + GFP_KERNEL);
> if (!parent_sel) {
> pr_err("%s: error allocating %u parent selectors\n", __func__,
> parent_count);
>