From: Sean Anderson <sean.anderson@linux.dev>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
"open list:DRM DRIVERS FOR XILINX"
<dri-devel@lists.freedesktop.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Michal Simek <michal.simek@amd.com>,
Maxime Ripard <mripard@kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Bart Van Assche <bvanassche@acm.org>,
Dan Carpenter <dan.carpenter@linaro.org>,
"moderated list:ARM/ZYNQ ARCHITECTURE"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v2 2/2] drm: zynqmp_dp: Use scope-based mutex helpers
Date: Fri, 7 Feb 2025 12:06:25 -0500 [thread overview]
Message-ID: <5f05d772-5d25-4b94-8759-95db3e283a6f@linux.dev> (raw)
In-Reply-To: <20250207164446.GB24886@pendragon.ideasonboard.com>
On 2/7/25 11:44, Laurent Pinchart wrote:
> Hi Sean,
>
> Thank you for the patch.
>
> On Fri, Feb 07, 2025 at 11:25:28AM -0500, Sean Anderson wrote:
>> Convert most mutex_(un)lock calls to use (scoped_)guard instead. This
>> generally reduces line count and prevents bugs like forgetting to unlock
>> the mutex. I've left traditional calls in a few places where scoped
>> helpers would be more verbose. This mostly happens where
>> debugfs_file_put needs to be called regardless. I looked into defining a
>> CLASS for debugfs_file, but it seems like more effort than it's worth
>> since debugfs_file_get can fail.
>>
>> Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
>> ---
>>
>> Changes in v2:
>> - Convert some conditional return statements to returns of ternary
>> expressions.
>> - Remove unnecessary whitespace change
>>
>> drivers/gpu/drm/xlnx/zynqmp_dp.c | 147 +++++++++++--------------------
>> 1 file changed, 50 insertions(+), 97 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c
>> index 189a08cdc73c..63842f657836 100644
>> --- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
>> +++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
>> @@ -1534,10 +1534,10 @@ zynqmp_dp_bridge_mode_valid(struct drm_bridge *bridge,
>> }
>>
>> /* Check with link rate and lane count */
>> - mutex_lock(&dp->lock);
>> - rate = zynqmp_dp_max_rate(dp->link_config.max_rate,
>> - dp->link_config.max_lanes, dp->config.bpp);
>> - mutex_unlock(&dp->lock);
>> + scoped_guard(mutex, &dp->lock)
>> + rate = zynqmp_dp_max_rate(dp->link_config.max_rate,
>> + dp->link_config.max_lanes,
>> + dp->config.bpp);
>
> Could we use curly braces even for single-statement scopes ?
>
> scoped_guard(mutex, &dp->lock) {
> rate = zynqmp_dp_max_rate(dp->link_config.max_rate,
> dp->link_config.max_lanes,
> dp->config.bpp);
> }
>
> I think this would make the scope clearer.
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
FWIW around 25% of existing scoped_guards use this style, and it seems
to be idiomatic for short scopes:
$ git grep scoped_guard | wc -l
523
$ git grep 'scoped_guard[^{]*$' | wc -l
156
$ git grep -A2 'scoped_guard.*{' | grep } | wc -l
25
--Sean
next prev parent reply other threads:[~2025-02-07 17:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 16:25 [PATCH v2 0/2] " Sean Anderson
2025-02-07 16:25 ` [PATCH v2 1/2] drm: zynqmp_dp: Fix a deadlock in zynqmp_dp_ignore_hpd_set() Sean Anderson
2025-02-07 16:33 ` Laurent Pinchart
2025-02-07 16:25 ` [PATCH v2 2/2] drm: zynqmp_dp: Use scope-based mutex helpers Sean Anderson
2025-02-07 16:44 ` Laurent Pinchart
2025-02-07 17:06 ` Sean Anderson [this message]
2025-02-12 8:01 ` [PATCH v2 0/2] " Tomi Valkeinen
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=5f05d772-5d25-4b94-8759-95db3e283a6f@linux.dev \
--to=sean.anderson@linux.dev \
--cc=airlied@gmail.com \
--cc=bvanassche@acm.org \
--cc=dan.carpenter@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=michal.simek@amd.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tomi.valkeinen@ideasonboard.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
all inboxes | Powered by JetHome®