[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <158474978337.125146.7055726274356736414@swboyd.mtv.corp.google.com>
Date: Fri, 20 Mar 2020 17:16:23 -0700
From: Stephen Boyd <sboyd@...nel.org>
To: Alexandre Belloni <alexandre.belloni@...tlin.com>,
Ludovic Desroches <ludovic.desroches@...rochip.com>,
Michael Turquette <mturquette@...libre.com>,
<mirq-linux@...e.qmqm.pl>,
Nicolas Ferre <nicolas.ferre@...rochip.com>
Cc: linux-clk@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/3] clk: at91: optimize pmc data allocation
Quote
> Alloc whole data structure in one block. This makes the code shorter,
> more efficient and easier to extend in following patch.
>
Generally looks good to me.
> diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c
> index b71515acdec1..fe788512fcc0 100644
> --- a/drivers/clk/at91/pmc.c
> +++ b/drivers/clk/at91/pmc.c
> @@ -76,48 +76,30 @@ struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data)
> return ERR_PTR(-EINVAL);
> }
>
> -void pmc_data_free(struct pmc_data *pmc_data)
> -{
> - kfree(pmc_data->chws);
> - kfree(pmc_data->shws);
> - kfree(pmc_data->phws);
> - kfree(pmc_data->ghws);
> -}
> -
> struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
> unsigned int nperiph, unsigned int ngck)
> {
> - struct pmc_data *pmc_data = kzalloc(sizeof(*pmc_data), GFP_KERNEL);
> + unsigned int num_clks = ncore + nsystem + nperiph + ngck;
> + struct pmc_data *pmc_data;
>
> + pmc_data = kzalloc(sizeof(*pmc_data) + num_clks * sizeof(struct clk_hw *),
I think we have struct_size() for this?
> + GFP_KERNEL);
> if (!pmc_data)
> return NULL;
>
> pmc_data->ncore = ncore;
> - pmc_data->chws = kcalloc(ncore, sizeof(struct clk_hw *), GFP_KERNEL);
> - if (!pmc_data->chws)
> - goto err;
> + pmc_data->chws = pmc_data->hwtable;
>
> pmc_data->nsystem = nsystem;
> - pmc_data->shws = kcalloc(nsystem, sizeof(struct clk_hw *), GFP_KERNEL);
> - if (!pmc_data->shws)
> - goto err;
> + pmc_data->shws = pmc_data->chws + ncore;
>
> pmc_data->nperiph = nperiph;
> - pmc_data->phws = kcalloc(nperiph, sizeof(struct clk_hw *), GFP_KERNEL);
> - if (!pmc_data->phws)
> - goto err;
> + pmc_data->phws = pmc_data->shws + nsystem;
>
> pmc_data->ngck = ngck;
> - pmc_data->ghws = kcalloc(ngck, sizeof(struct clk_hw *), GFP_KERNEL);
> - if (!pmc_data->ghws)
> - goto err;
> + pmc_data->ghws = pmc_data->phws + nperiph;
>
> return pmc_data;
> -
> -err:
> - pmc_data_free(pmc_data);
> -
> - return NULL;
> }
>
> #ifdef CONFIG_PM
> diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
> index 9b8db9cdcda5..49cc3d67b98e 100644
> --- a/drivers/clk/at91/pmc.h
> +++ b/drivers/clk/at91/pmc.h
> @@ -24,6 +24,8 @@ struct pmc_data {
> struct clk_hw **phws;
> unsigned int ngck;
> struct clk_hw **ghws;
> +
> + struct clk_hw *hwtable[0];
I've seen people making this C99 compliant for clang. Please make it
struct clk_hw *hwtable[];
instead.
> };
>
Powered by blists - more mailing lists