devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liu Ying <Ying.Liu@freescale.com>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: devicetree@vger.kernel.org, mturquette@linaro.org,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RFC 09/15] drm: imx: Add MIPI DSI host controller driver
Date: Thu, 18 Dec 2014 10:46:33 +0800	[thread overview]
Message-ID: <54924009.8040207@freescale.com> (raw)
In-Reply-To: <20141217104049.GU11285@n2100.arm.linux.org.uk>

Hi Russell,

On 12/17/2014 06:40 PM, Russell King - ARM Linux wrote:
> On Wed, Dec 17, 2014 at 05:44:33PM +0800, Liu Ying wrote:
>> Hi Thierry,
>>
>> Sorry for the late response.
>> I tried to address almost all your comments locally first.
>> More feedback below.
>>
>> On 12/10/2014 09:16 PM, Thierry Reding wrote:
>>> On Wed, Dec 10, 2014 at 04:37:22PM +0800, Liu Ying wrote:
>>>> +static int check_status(struct imx_mipi_dsi *dsi, u32 reg, u32 status,
>>>> +			int timeout, bool to_set)
>>>> +{
>>>> +	u32 val;
>>>> +	bool out = false;
>>>> +
>>>> +	val = dsi_read(dsi, reg);
>>>> +	for (;;) {
>>>> +		out = to_set ? (val & status) : !(val & status);
>>>> +		if (out)
>>>> +			break;
>>>> +
>>>> +		if (!timeout--)
>>>> +			return -EFAULT;
>>>> +
>>>> +		msleep(1);
>>>> +		val = dsi_read(dsi, reg);
>>>> +	}
>>>> +	return 0;
>>>> +}
>>>
>>> You should probably use a properly timed loop here. msleep() isn't
>>> guaranteed to return after exactly one millisecond, so your timeout is
>>> never going to be accurate. Something like the following would be better
>>> in my opinion:
>>>
>>> 	timeout = jiffies + msecs_to_jiffies(timeout);
>>>
>>> 	while (time_before(jiffies, timeout)) {
>>> 		...
>>> 	}
>>>
>>> Also timeout should be unsigned long in that case.
>>
>> Accepted.
>
> Actually, that's a bad example: what we want to do is to assess success
> after we wait, before we decide that something has failed.  In other
> words, we don't want to wait, and decide that we failed without first
> checking for success.
>
> In any case, returning -EFAULT is not sane: EFAULT doesn't mean "fault"
> it means "Bad address", and it is returned to userspace to mean that
> userspace passed the kernel a bad address.  That definition does /not/
> fit what's going on here.
>
> 	timeout = jiffies + msecs_to_jiffies(timeout);
>
> 	do {
> 		val = dsi_read(dsi, reg);
> 		out = to_set ? (val & status) : !(val & status);
> 		if (out)
> 			break;
>
> 		if (time_is_after_jiffies(timeout))

time_is_after_jiffies(a) is defined as time_before(jiffies, a).

So, this line should be changed to

	if (time_after(jiffies, timeout))

Right?

> 			return -ETIMEDOUT;
>
> 		msleep(1);
> 	} while (1);
>
> 	return 0;
>
> would be better: we only fail immediately after we have checked whether
> we succeeded, and we also do the first check immediately.
>

Does this one look better?  I use cpu_relax() instead of msleep(1).

         expire = jiffies + msecs_to_jiffies(timeout);
         for (;;) {
                 val = dsi_read(dsi, reg);
                 out = to_set ? (val & status) : !(val & status);
                 if (out)
                         break;

                 if (time_after(jiffies, expire))
                         return -ETIMEDOUT;

                 cpu_relax();
         }

	return 0;

Regards,

Liu Ying
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2014-12-18  2:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-10  8:37 [PATCH RFC 00/15] Add support for i.MX MIPI DSI DRM driver Liu Ying
     [not found] ` <1418200648-32656-1-git-send-email-Ying.Liu-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2014-12-10  8:37   ` [PATCH RFC 01/15] clk: divider: Correct parent clk round rate if no bestdiv is normally found Liu Ying
2014-12-10  8:37 ` [PATCH RFC 02/15] of: Add vendor prefix for Himax Technologies Inc Liu Ying
2014-12-10  8:37 ` [PATCH RFC 03/15] of: Add vendor prefix for Truly Semiconductors Limited Liu Ying
2014-12-10  8:37 ` [PATCH RFC 04/15] drm/dsi: Do not add DSI devices for the child nodes with input-port property Liu Ying
2014-12-10 12:21   ` Thierry Reding
2014-12-11  2:52     ` Liu Ying
2014-12-11  5:50       ` Liu Ying
2014-12-10  8:37 ` [PATCH RFC 05/15] ARM: dts: imx6qdl: Add input-port property to MIPI DSI node's CTRC child nodes Liu Ying
2014-12-10  8:37 ` [PATCH RFC 06/15] ARM: dts: imx6q: Add MIPI DSI remote end points for IPU2 DI0/1 end points Liu Ying
2014-12-10  8:37 ` [PATCH RFC 07/15] ARM: imx6q: Add GPR3 MIPI muxing control register field shift bits definition Liu Ying
2014-12-10  8:37 ` [PATCH RFC 08/15] ARM: imx6q: clk: Add the video_27m clock Liu Ying
2014-12-10  8:37 ` [PATCH RFC 09/15] drm: imx: Add MIPI DSI host controller driver Liu Ying
2014-12-10 13:16   ` Thierry Reding
2014-12-17  9:44     ` Liu Ying
2014-12-17 10:40       ` Russell King - ARM Linux
2014-12-18  2:46         ` Liu Ying [this message]
2014-12-10  8:37 ` [PATCH RFC 10/15] drm: panel: Add support for Himax HX8369A MIPI DSI panel Liu Ying
2014-12-10 14:03   ` Thierry Reding
2014-12-17 10:27     ` Liu Ying
2014-12-10  8:37 ` [PATCH RFC 11/15] ARM: dtsi: imx6qdl: Add support for MIPI DSI host controller Liu Ying
2014-12-10  8:37 ` [PATCH RFC 12/15] ARM: dts: imx6qdl-sabresd: Add support for TRULY TFT480800-16-E MIPI DSI panel Liu Ying
2014-12-10 14:07   ` Thierry Reding
2014-12-17 10:35     ` Liu Ying
2014-12-10  8:37 ` [PATCH RFC 13/15] ARM: imx_v6_v7_defconfig: Cleanup for imx drm being moved out of staging Liu Ying
2014-12-10  8:37 ` [PATCH RFC 14/15] ARM: imx_v6_v7_defconfig: Add support for MIPI DSI host controller Liu Ying
2014-12-10  8:37 ` [PATCH RFC 15/15] ARM: imx_v6_v7_defconfig: Add support for Himax HX8369A panel Liu Ying

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=54924009.8040207@freescale.com \
    --to=ying.liu@freescale.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mturquette@linaro.org \
    /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).