Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1409778

Re: [PATCH trivial] include/linux/memblock.h: Clean up code for several trivial details

From Chen Gang <chengang@emindsoft.com.cn>
Newsgroups linux.kernel
Subject Re: [PATCH trivial] include/linux/memblock.h: Clean up code for several trivial details
Date 2016-05-31 04:10 +0200
Message-ID <rEHi1-4nT-3@gated-at.bofh.it> (permalink)
References <rEacp-7x8-15@gated-at.bofh.it> <rEavL-7SI-1@gated-at.bofh.it> <rEwmB-5kR-17@gated-at.bofh.it> <rEwwi-5os-33@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 2016年05月30日 22:33, Joe Perches wrote:
> On Mon, 2016-05-30 at 22:21 +0800, Chen Gang wrote:
>> No, they are not necessary. But for me, it will be more clearer, since
>> in our kernel (at least in include/linux/), almost all Boolean functions
>> use Boolean value or expression for return (and "!!" are often used).
> 
> Opinions vary.
> 
> There seem to be fewer than 20 !! uses in bool return
> functions in include/linux/
>

  ide.h:854
  mlx4/driver.h:76
  mlx5/device.h:744
  mmzone.h:793
  mtd/mtd.h:412
  nilfs2_fs.h:568
  nilfs2_fs.h:602
  nilfs2_fs.h:667
  nilfs2_fs.h:771
  page-flags.h:711
  pagemap.h:54

For me, we can change the related functions to Boolean functions
directly.
 
> Finding the quantity of bool conversions in include/linux
> from something other than 0, 1, true, or false to 0 or 1
> is not trivial, but it is non-zero and seems rather more
> than 20.
> 

[root@localhost linux]# grep -rn "\<return\>" * | grep ' & ' | grep -v "==" | grep -v '||' | grep -v 'struct' | grep -v '!=' | grep -v ',' | grep -v '?' | grep -v '!' | grep -v '&&' | wc -l
259

After give a glance, more than 60% are not for bool functions (so I
guess about 100 area hint).

But I guess, quite a few of none Boolean functions above can be changed
to Boolean functions, too (but have to read more code).

So I guess, about 200+ matches the hint (not use "!!" for & operation in
Boolean functions) in the 1000+ Boolean functions in include/linux.


All together, for me:

The return statement is much special than normal statements:

 - It is related with function's type (non-return function, Boolean
   function, or normal function), not only related with type cast within
   the statement itself.

 - Even for normal function, the type cast in return statement is also
   better: when reading source code, return statements have much more
   chances to be read than the function return type.

 - For finding Boolean function in existing normal functions, we often
   read the return value to know about whether it is a Boolean function
   or not.

So, I still suggest to add type cast explicitly in return statement.

Welcome any ideas, suggestions, and completions.

Thanks.
-- 
Chen Gang (陈刚)

Managing Natural Environments is the Duty of Human Beings.

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH trivial] include/linux/memblock.h: Clean up code for several trivial details chengang@emindsoft.com.cn - 2016-05-29 16:50 +0200
  Re: [PATCH trivial] include/linux/memblock.h: Clean up code for  several trivial details Joe Perches <joe@perches.com> - 2016-05-29 17:10 +0200
    Re: [PATCH trivial] include/linux/memblock.h: Clean up code for several  trivial details Chen Gang <chengang@emindsoft.com.cn> - 2016-05-30 16:30 +0200
      Re: [PATCH trivial] include/linux/memblock.h: Clean up code for  several trivial details Joe Perches <joe@perches.com> - 2016-05-30 16:40 +0200
        Re: [PATCH trivial] include/linux/memblock.h: Clean up code for several  trivial details Chen Gang <chengang@emindsoft.com.cn> - 2016-05-31 00:20 +0200
        Re: [PATCH trivial] include/linux/memblock.h: Clean up code for  several trivial details Chen Gang <chengang@emindsoft.com.cn> - 2016-05-31 04:10 +0200

csiph-web