kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: wharms@bfs.de, Dan Carpenter <dan.carpenter@oracle.com>
Cc: Rob Clark <robdclark@gmail.com>,
	Archit Taneja <architt@codeaurora.org>,
	linux-arm-msm@vger.kernel.org, kernel-janitors@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	Wei Yongjun <yongjun_wei@trendmicro.com.cn>,
	freedreno@lists.freedesktop.org
Subject: Re: [patch] drm/msm/dsi: free first element on error
Date: Thu, 16 Feb 2017 12:25:56 +0000	[thread overview]
Message-ID: <874lzunwyz.fsf@intel.com> (raw)
In-Reply-To: <58A5952C.105@bfs.de>

On Thu, 16 Feb 2017, walter harms <wharms@bfs.de> wrote:
> Am 16.02.2017 12:53, schrieb Dan Carpenter:
>> On Thu, Feb 16, 2017 at 01:27:47PM +0200, Jani Nikula wrote:
>>> On Thu, 16 Feb 2017, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>>>> We want to free msm_host->bus_clks[0] so the > should be >=.
>>>>
>>>> Fixes: 6e0eb52eba9e ("drm/msm/dsi: Parse bus clocks from a list")
>>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>>>
>>>> diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
>>>> index 1fc07ce24686..239e79b39a45 100644
>>>> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
>>>> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
>>>> @@ -437,7 +437,7 @@ static int dsi_bus_clk_enable(struct msm_dsi_host *msm_host)
>>>>  
>>>>  	return 0;
>>>>  err:
>>>> -	for (; i > 0; i--)
>>>> +	for (; i >= 0; i--)
>>>>  		clk_disable_unprepare(msm_host->bus_clks[i]);
>>>
>>> By the looks of it this is also wrong. I didn't look at the functions,
>>> but you probably don't want to unprepare something where prepare failed,
>>> i.e. you want to -1 both the start and end offsets. Perhaps the right
>>> fix is
>>>
>>> 	while (i--)
>>> 		clk_disable_unprepare(msm_host->bus_clks[i]);
>>>
>>> which also seems to be widely used on error paths.
>>>
>> 
>
> We already know that programmers are bad in counting backwards ...
>
> any chance to make that into a forward loop ?

In most cases I'd agree with you. But I see that this while (i--) is
becoming somewhat of a pattern for error paths (grep for it), and I
think following patterns like this is more important. After a while, you
don't have to think about counting when you see it.

Besides, it's generally preferred to cleanup in the reverse order of
init, so a forward counting loop would require two variables here.

BR,
Jani.



>
> re,
>  wh
>
>

-- 
Jani Nikula, Intel Open Source Technology Center

  parent reply	other threads:[~2017-02-16 12:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-16 10:50 [patch] drm/msm/dsi: free first element on error Dan Carpenter
2017-02-16 11:27 ` Jani Nikula
     [not found]   ` <87a89mnznw.fsf-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-02-16 11:53     ` Dan Carpenter
2017-02-16 12:03       ` walter harms
2017-02-16 12:15         ` Rob Clark
2017-02-16 12:25         ` Jani Nikula [this message]
2017-02-16 12:00   ` [patch v2] " Dan Carpenter
2017-02-16 12:16     ` Rob Clark
2017-02-16 12:27       ` Jani Nikula
2017-02-26 20:52         ` Daniel Vetter
2017-02-27 10:18           ` Jani Nikula
     [not found]             ` <87h93ggcnn.fsf-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-02-27 10:25               ` Daniel Vetter
     [not found]                 ` <CAKMK7uGLn3m8eEzYEmPFDPr090B0Cq9Xycg_bJdX7SkRJYtNyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-27 11:25                   ` Rob Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874lzunwyz.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=architt@codeaurora.org \
    --cc=dan.carpenter@oracle.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=robdclark@gmail.com \
    --cc=wharms@bfs.de \
    --cc=yongjun_wei@trendmicro.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).