mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@igalia.com>
To: Thomas Zimmermann <tzimmermann@suse.de>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	kernel-dev@igalia.com, Kees Cook <keescook@chromium.org>,
	Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
	Mario Limonciello <mario.limonciello@amd.com>
Subject: Re: [PATCH] drm: drm_auth: Convert mutex usage to guard(mutex)
Date: Mon, 12 May 2025 11:27:40 -0300	[thread overview]
Message-ID: <86103c8d-0cdf-4fc8-aa79-5a03b299d26e@igalia.com> (raw)
In-Reply-To: <7133e9b4-c05a-4901-940e-de3e70bbbb1e@suse.de>

Hi Thomas,

Thanks for the feedback.

Em 12/05/2025 03:52, Thomas Zimmermann escreveu:
> Hi
> 
> Am 09.05.25 um 16:26 schrieb André Almeida:
>> Replace open-coded mutex handling with cleanup.h guard(mutex). This
>> simplifies the code and removes the "goto unlock" pattern.
>>
>> Tested with igt tests core_auth and core_setmaster.
>>
>> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> 
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> 
> but with questions below
> 
>> ---
>>
>> For more information about guard(mutex):
>> https://www.kernel.org/doc/html/latest/core-api/cleanup.html
> 
> This page lists issues with guards, so conversion from manual locking 
> should be decided on a case-by-case base IMHO.
> 

Sure, agreed. The places that I have converted to guard(mutex) here 
looks like a good fit for this conversion, where the scope of the mutex 
is well defined inside a function without conditional locking.

>> ---
>>   drivers/gpu/drm/drm_auth.c | 64 ++++++++++++++------------------------
>>   1 file changed, 23 insertions(+), 41 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
>> index 22aa015df387..d6bf605b4b90 100644
>> --- a/drivers/gpu/drm/drm_auth.c
>> +++ b/drivers/gpu/drm/drm_auth.c
>> @@ -95,7 +95,7 @@ int drm_getmagic(struct drm_device *dev, void *data, 
>> struct drm_file *file_priv)
>>       struct drm_auth *auth = data;
>>       int ret = 0;
>> -    mutex_lock(&dev->master_mutex);
>> +    guard(mutex)(&dev->master_mutex);
> 
> These guard statements are hidden variable declarations. Shouldn't they 
> rather go to the function top with the other declarations? This would 
> also help to prevent the problem listed in cleanup.html to some extend.
> 

The guard statements should go exactly where the lock should be taken, 
as it not only declares anonymous variables but also really takes the 
lock. The lock is then release when the mutex goes out of scope. File 
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c has some usage of 
guard(mutex) as well, where Mario did a similar cleanup:

f123fda19752 drm/amd/display: Use scoped guards for handle_hpd_irq_helper()
aca9ec9b050c drm/amd/display: Use scoped guard for 
amdgpu_dm_update_connector_after_detect()
f24a74d59e14 drm/amd/display: Use scoped guard for dm_resume()


> Best regards
> Thomas
> 

  reply	other threads:[~2025-05-12 14:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-09 14:26 André Almeida
2025-05-12  6:52 ` Thomas Zimmermann
2025-05-12 14:27   ` André Almeida [this message]
2025-05-22 18:28   ` André Almeida
2025-05-26  7:37     ` Thomas Zimmermann

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=86103c8d-0cdf-4fc8-aa79-5a03b299d26e@igalia.com \
    --to=andrealmeid@igalia.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=keescook@chromium.org \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mario.limonciello@amd.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tvrtko.ursulin@igalia.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®