From: Andrzej Hajda <a.hajda@samsung.com>
To: Thierry Reding <thierry.reding@gmail.com>,
Hyungwon Hwang <human.hwang@samsung.com>
Cc: Donghwa Lee <dh09.lee@samsung.com>,
Sangbae Lee <sangbae90.lee@samsung.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3] drm/panel: add s6e3ha2 AMOLED panel driver
Date: Thu, 05 Feb 2015 12:17:27 +0100 [thread overview]
Message-ID: <54D35147.7080706@samsung.com> (raw)
In-Reply-To: <20150203125150.GD15068@ulmo.nvidia.com>
Hi Thierry,
On 02/03/2015 01:51 PM, Thierry Reding wrote:
> On Tue, Jan 27, 2015 at 10:48:32AM +0900, Hyungwon Hwang wrote:
(...)
>> +
>> + /* This field is tested by functions directly accessing DSI bus before
>> + * transfer, transfer is skipped if it is set. In case of transfer
>> + * failure or unexpected response the field is set to error value.
>> + * Such construct allows to eliminate many checks in higher level
>> + * functions.
>> + */
>> + int error;
>
> I hate myself for not NAK'ing the first patch that introduced this idiom
> stronger. I think it's a really bad concept and you're not doing
> yourself any favours by using it.
The main favor of using it is much shorter code. The idiom eliminates
redundant error checking in case of nested function calls - and this is
quite common for panel drivers.
Moreover the same idiom is used also in other places. I have not dig too
much but as I remember it is present at least in:
- V4L2 core: struct v4l2_ctrl_handler.error,
- fs/seq_file: struct seq_file overflow handling
(...)
>> +static int s6e3ha2_prepare(struct drm_panel *panel)
>> +{
>> + struct s6e3ha2 *ctx = panel_to_s6e3ha2(panel);
>> + int ret;
>> +
>> + ret = s6e3ha2_power_on(ctx);
>> + if (ret < 0)
>> + return ret;
>> +
>> + s6e3ha2_panel_init(ctx);
>> + if (ctx->error < 0)
>
> This is one of the reasons why ctx->error is a bad idea. It's completely
> unintuitive to check ctx->error here because nobody's actually setting
> it in this context.
>
But this is classical example of passing variable by reference. You pass
ctx to s6e3ha2_panel_init to allow ctx modification. So the natural
thing is to check after the call what was changed, for example by
reading ctx->error.
The advantage of the idiom is that you are not obliged to do it now, it
can be done later. In case of propagating error by return value you
should check the error after every call and it results in much more
bloated code.
Regards
Andrzej
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
prev parent reply other threads:[~2015-02-05 11:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-27 1:48 [PATCH v3] drm/panel: add s6e3ha2 AMOLED panel driver Hyungwon Hwang
2015-02-03 12:51 ` Thierry Reding
2015-02-05 11:17 ` Andrzej Hajda [this message]
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=54D35147.7080706@samsung.com \
--to=a.hajda@samsung.com \
--cc=dh09.lee@samsung.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=human.hwang@samsung.com \
--cc=sangbae90.lee@samsung.com \
--cc=thierry.reding@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.