lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5f05d772-5d25-4b94-8759-95db3e283a6f@linux.dev>
Date: Fri, 7 Feb 2025 12:06:25 -0500
From: Sean Anderson <sean.anderson@...ux.dev>
To: Laurent Pinchart <laurent.pinchart@...asonboard.com>
Cc: Tomi Valkeinen <tomi.valkeinen@...asonboard.com>,
 "open list:DRM DRIVERS FOR XILINX" <dri-devel@...ts.freedesktop.org>,
 Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
 David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
 Michal Simek <michal.simek@....com>, Maxime Ripard <mripard@...nel.org>,
 open list <linux-kernel@...r.kernel.org>,
 Thomas Zimmermann <tzimmermann@...e.de>, Bart Van Assche
 <bvanassche@....org>, Dan Carpenter <dan.carpenter@...aro.org>,
 "moderated list:ARM/ZYNQ ARCHITECTURE" <linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH v2 2/2] drm: zynqmp_dp: Use scope-based mutex helpers

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@...ux.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@...asonboard.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ