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.ander...@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.pinch...@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

Reply via email to