From: "Brigham Campbell" <me@brighamcampbell.com>
To: "Doug Anderson" <dianders@chromium.org>
Cc: <tejasvipin76@gmail.com>, <diogo.ivo@tecnico.ulisboa.pt>,
<skhan@linuxfoundation.org>,
<linux-kernel-mentees@lists.linux.dev>,
<dri-devel@lists.freedesktop.org>, <linux-doc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>
Subject: Re: [PATCH v4 1/4] drm: Create mipi_dsi_dual macro
Date: Fri, 18 Jul 2025 11:17:48 -0600 [thread overview]
Message-ID: <DBFCOJFGI5HB.1RNJBDPNTEL2U@brighamcampbell.com> (raw)
In-Reply-To: <CAD=FV=WYBFrm-J55BTEJ7s=Jk4EFuMVAkahVZfdzW6V8mxE7Tg@mail.gmail.com>
On Fri Jul 18, 2025 at 10:10 AM MDT, Doug Anderson wrote:
>> +#define mipi_dsi_dual(_func, _dsi1, _dsi2, _ctx, ...) \
>> + _mipi_dsi_dual(_func, _dsi1, _dsi2, _ctx, ##__VA_ARGS__)
>> +
>> +#define _mipi_dsi_dual(_func, _dsi1, _dsi2, _ctx, ...) \
>> + do { \
>> + (_ctx)->dsi = (_dsi1); \
>> + _func((_ctx), ##__VA_ARGS__); \
>
> nit: shouldn't func be in parenthesis for safety? It's unlikely to
> really matter, but just in case it's somehow a calculated value that
> would make it safe from an order-of-operations point of view.
My assumption is that wrapping _func in parenthesis would cause a
compilation error in the case of _func being a macro (more on that
later...). I'll test that later today.
>> + (_ctx)->dsi = (_dsi2); \
>> + _func((_ctx), ##__VA_ARGS__); \
>> + } while (0)
>
> Can you explain why you need the extra level of indirection here (in
> other words, why do you need to define _mipi_dsi_dual() and then use
> it in mipi_dsi_dual())? I don't see it buying anything, but maybe it's
> performing some magic trick I'm not aware of?
I mentioned this in v3 after the changelog and prompty forgot to include
that information in v4: The extra indirection between mipi_dsi_dual()
and _mipi_dsi_dual() is to allow for the expansion of _func in the case
that _func is also a macro (as is the case with
mipi_dsi_generic_write_seq_multi, i believe). Compilation fails after
removing the indirection.
There may very well be a better solution to this problem. I'd appreciate
your thoughts.
> Reading this with a fresh set of eyes, I also realize that this macro
> is probably vulnerable to issues where arguments have side effects
> since we have to repeat them. I don't think there's a way around this
> and I think the macro is still worthwhile, but something to go into
> with open eyes. Possibly worth noting in the macro description? We
> could probably at least eliminate the need to reference "_ctx" more
> than once by assigning it to a local variable. I think referencing
> "_func" and "__VA_ARGS__" more than once is unavoidable...
I'm using _func, _ctx, and __VA_ARGS__ more than once in this macro and
I don't expect the indirection to fix the potential issue of unintended
side effects. I believe we can use GNU extensions to eliminate side
effects to _ctx, but especially since _func can be a macro, I don't
think there's much to be done about it. Not sure about __VA_ARGS__.
I fear my inexperience is made sorely manifest here.
Happy Friday,
Brigham
next prev parent reply other threads:[~2025-07-18 17:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 16:40 [PATCH v3 0/4] drm: Fix bug in panel driver, update MIPI support macros Brigham Campbell
2025-07-17 16:40 ` [PATCH v4 1/4] drm: Create mipi_dsi_dual macro Brigham Campbell
2025-07-18 16:10 ` Doug Anderson
2025-07-18 17:17 ` Brigham Campbell [this message]
2025-07-18 20:32 ` Doug Anderson
2025-07-17 16:40 ` [PATCH v4 2/4] drm/panel: jdi-lpm102a188a: Fix bug and clean up driver Brigham Campbell
2025-07-18 10:43 ` Diogo Ivo
2025-07-18 16:11 ` Doug Anderson
2025-07-19 17:10 ` Diogo Ivo
2025-07-20 7:50 ` Brigham Campbell
2025-07-20 11:19 ` Diogo Ivo
2025-07-21 15:46 ` Doug Anderson
2025-07-17 16:40 ` [PATCH v4 3/4] drm: Remove unused MIPI write seq and chatty functions Brigham Campbell
2025-07-17 16:40 ` [PATCH v4 4/4] drm: docs: Update task from drm TODO list Brigham Campbell
2025-07-17 18:41 ` [PATCH v3 0/4] drm: Fix bug in panel driver, update MIPI support macros Brigham Campbell
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=DBFCOJFGI5HB.1RNJBDPNTEL2U@brighamcampbell.com \
--to=me@brighamcampbell.com \
--cc=airlied@gmail.com \
--cc=dianders@chromium.org \
--cc=diogo.ivo@tecnico.ulisboa.pt \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tejasvipin76@gmail.com \
--cc=tzimmermann@suse.de \
/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).