Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1517057

Re: [PATCH] clk: Free struct clk allocated during clk_hw_register()

Path csiph.com!news.redatomik.org!weretis.net!feeder4.news.weretis.net!news.unit0.net!news.panservice.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod
From Rajendra Nayak <rnayak@codeaurora.org>
Newsgroups linux.kernel
Subject Re: [PATCH] clk: Free struct clk allocated during clk_hw_register()
Date Tue, 08 Nov 2016 11:40:01 +0100
Message-ID <sBbYR-8bd-5@gated-at.bofh.it> (permalink)
References <sB9X4-6WX-21@gated-at.bofh.it> <sBb2O-7xW-29@gated-at.bofh.it> <sBbvP-7Zq-13@gated-at.bofh.it>
X-Original-To Geert Uytterhoeven <geert@linux-m68k.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1478601483; bh=sUuiN3H/RUG+uyL3bQhztSocmcazCARtaVLIqSOi51o=; h=Date:From:To:CC:Subject:References:In-Reply-To:From; b=W//uhVjq6bG9fn6/S8/3QffO0vpVhNjtiEgw5K8p/ffk69xRKev47/KLASzhIypDo lRN5ksjpFuGahNsftvaKfZdbeMgU9Q6r6XvOmVLBDtO1XRM3BkS+yhM+YJRzuDN6da s2qKhA2LWsSnfkcTQMfVf1RwkGISxZfxX6PyBYJo=
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1478601483; bh=sUuiN3H/RUG+uyL3bQhztSocmcazCARtaVLIqSOi51o=; h=Date:From:To:CC:Subject:References:In-Reply-To:From; b=W//uhVjq6bG9fn6/S8/3QffO0vpVhNjtiEgw5K8p/ffk69xRKev47/KLASzhIypDo lRN5ksjpFuGahNsftvaKfZdbeMgU9Q6r6XvOmVLBDtO1XRM3BkS+yhM+YJRzuDN6da s2qKhA2LWsSnfkcTQMfVf1RwkGISxZfxX6PyBYJo=
Dmarc-Filter OpenDMARC Filter v1.3.1 smtp.codeaurora.org 3FA4F6159E
Authentication-Results pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org
Authentication-Results pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=rnayak@codeaurora.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 63
Organization linux.* mail to news gateway
X-Original-Cc Stephen Boyd <sboyd@codeaurora.org>, Michael Turquette <mturquette@baylibre.com>, linux-clk <linux-clk@vger.kernel.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
X-Original-Date Tue, 08 Nov 2016 16:07:58 +0530
X-Original-Message-ID <5821AB06.4060303@codeaurora.org>
X-Original-References <1478593430-23102-1-git-send-email-rnayak@codeaurora.org> <CAMuHMdW6-oRJ4CKbUeXOixvKFOZ3vf8pGhCH87rOx1KuE8bdGQ@mail.gmail.com> <5821A331.5060405@codeaurora.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1517057

Show key headers only | View raw


On 11/08/2016 03:34 PM, Rajendra Nayak wrote:
> 
> 
> On 11/08/2016 03:06 PM, Geert Uytterhoeven wrote:
>> Hi Rajendra,
>>
>> On Tue, Nov 8, 2016 at 9:23 AM, Rajendra Nayak <rnayak@codeaurora.org> wrote:
>>> With clk_hw_register() API we hide the struct clk from the caller
>>> and return an int error code instead, so the caller (clk provider)
>>> is not expected to use hw->clk on return.
>>
>> That's correct, in case of failure.
> 
> sorry, maybe the commit text needs to be reworded. I meant 'clk_hw_register() returns
> an int (not a struct clk pointer), 0 on success or an error code in case of a failure.
> 
>>
>>> Free the memory, and mark hw->clk as NULL before returning.
>>>
>>> Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
>>> ---
>>>  drivers/clk/clk.c | 10 +++++++++-
>>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>>> index 0fb39fe..f81e4aa 100644
>>> --- a/drivers/clk/clk.c
>>> +++ b/drivers/clk/clk.c
>>> @@ -2628,7 +2628,15 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)
>>>   */
>>>  int clk_hw_register(struct device *dev, struct clk_hw *hw)
>>>  {
>>> -       return PTR_ERR_OR_ZERO(clk_register(dev, hw));
>>> +       struct clk *c;
>>> +
>>> +       c = clk_register(dev, hw);
>>> +       if (IS_ERR(c))
>>> +               return PTR_ERR(c);
>>> +
>>> +       __clk_free_clk(c);
>>> +       hw->clk = NULL;
>>
>> This is the success path, not the failure path (on failure, clk_register()
>> has already freed the struct clk).
>> Why do you free the struct clk in case of success?
>>
>> What am I missing?
> 
> so with 'per-user' clks, I thought we now have one struct clk per user, allocated
> when the user does a clk_get() and freed with a clk_put(), so we shouldn't ideally
> need one during clk registration?
> The one allocated in clk_register() is for legacy users who need to get a struct clk *
> back. For users of clk_hw_register() this should not be needed, no?

Looking through this a little more, I don't think we can get rid of the 'struct clk'
allocations at registration time as yet.
It seems to be used by clk_get_parent() at least, which does not yet do a 
__clk_create_clk() and relies on hw->clk

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH] clk: Free struct clk allocated during clk_hw_register() Rajendra Nayak <rnayak@codeaurora.org> - 2016-11-08 09:30 +0100
  Re: [PATCH] clk: Free struct clk allocated during clk_hw_register() Geert Uytterhoeven <geert@linux-m68k.org> - 2016-11-08 10:40 +0100
    Re: [PATCH] clk: Free struct clk allocated during clk_hw_register() Rajendra Nayak <rnayak@codeaurora.org> - 2016-11-08 11:10 +0100
      Re: [PATCH] clk: Free struct clk allocated during clk_hw_register() Rajendra Nayak <rnayak@codeaurora.org> - 2016-11-08 11:40 +0100

csiph-web