lkml.org 
[lkml]   [2019]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] checkpatch: check for nested (un)?likely calls
From
Date
On 8/27/19 8:21 PM, Joe Perches wrote:
> On Tue, 2019-08-27 at 19:55 +0300, Denis Efremov wrote:
>> IS_ERR, IS_ERR_OR_NULL, IS_ERR_VALUE already contain unlikely optimization
>> internally. Thus, there is no point in calling these functions under
>> likely/unlikely.
>>
>> This check is based on the coccinelle rule developed by Enrico Weigelt
>> https://lore.kernel.org/lkml/1559767582-11081-1-git-send-email-info@metux.net/
> []
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
>> @@ -6480,6 +6480,13 @@ sub process {
>> "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
>> }
>>
>> +# nested likely/unlikely calls
>> + if ($perl_version_ok &&
>> + $line =~ /\b(?:(?:un)?likely)\s*\(!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?)\s*${balanced_parens}\s*\)/) {
>> + WARN("LIKELY_MISUSE",
>> + "nested (un)?likely calls, unlikely already used in $1 internally\n" . $herecurr);
>> + }
>> +
>
> Couple things:
>
> 1:
>
> Are you going to submit patches for the just 10 instances that exist?
>
> $ git grep -P -n '\b(?:(?:un)?likely)\s*\(!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?)\s*\([^\)]+\)\s*\)'
> arch/x86/kernel/irq.c:246: if (likely(!IS_ERR_OR_NULL(desc))) {
> drivers/infiniband/hw/hfi1/verbs.c:1044: if (unlikely(IS_ERR_OR_NULL(pbuf))) {
> drivers/input/mouse/alps.c:1479: } else if (unlikely(IS_ERR_OR_NULL(priv->dev3))) {
> fs/ntfs/mft.c:74: if (likely(!IS_ERR(page))) {
> fs/ntfs/mft.c:157: if (likely(!IS_ERR(m)))
> fs/ntfs/mft.c:274: if (likely(!IS_ERR(m))) {
> fs/ntfs/mft.c:1779: if (likely(!IS_ERR(rl2)))
> fs/ntfs/namei.c:118: if (likely(!IS_ERR(dent_inode))) {
> fs/ntfs/runlist.c:954: if (likely(!IS_ERR(old_rl)))
> include/net/udp.h:483: if (unlikely(IS_ERR_OR_NULL(segs))) {

Yes, I will do it in days.

>
> 2:
>
> This will not warn about code like:
>
> fs/ntfs/mft.c: if (unlikely(IS_ERR(rl) || !rl->length || rl->lcn < 0)) {
>
> that could probably be better written as:
>
> if (IS_ERR(rl) || unlikely(!rl->length || rl->lcn < 0)) {
>
>

Ok, I will change the regex in v2 to:
$line =~ /\b(?:(?:un)?likely)\s*\(!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?)/

Should I skip $perl_version_ok check then?

If there are no other suggestions about, for example, warn message or commit
description I will send v2.

Thanks,
Denis

\
 
 \ /
  Last update: 2019-08-27 19:33    [W:0.039 / U:2.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site