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


Groups > linux.kernel > #1469129

Re: [PATCH v2] serial: vt8500_serial: Fix a parameter of find_first_zero_bit.

From Arnd Bergmann <arnd@arndb.de>
Newsgroups linux.kernel
Subject Re: [PATCH v2] serial: vt8500_serial: Fix a parameter of find_first_zero_bit.
Date 2016-08-24 09:30 +0200
Message-ID <s9ANj-7rr-1@gated-at.bofh.it> (permalink)
References <s9yBP-64G-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wednesday, August 24, 2016 7:06:58 AM CEST Christophe JAILLET wrote:
> The 2nd parameter of 'find_first_zero_bit' is the number of bits to search.
> In this case, we are passing 'sizeof(vt8500_ports_in_use)'.
> 'vt8500_ports_in_use' is an 'unsigned long'. So the sizeof is likely to
> return 4 on a 32 bits kernel.
> 
> A few lines below, we check if it is below VT8500_MAX_PORTS, which is 6.
> 
> It is likely that the number of bits in a long was expected here.
> 
> In order to fix it:
>    - use DECLARE_BITMAP when declaring the vt8500_ports_in_use
>    - use VT8500_MAX_PORTS as a maximum value when checking/setting bits in
>      this bitmap
>    - modify code now that 'vt8500_ports_in_use' has become a pointer
>      because of the use of DECLARE_BITMAP
> 
> 
> It has been spotted by the following coccinelle script:
> @@
> expression ret, x;
> 
> @@
> *  ret = \(find_first_bit \| find_first_zero_bit\) (x, sizeof(...));
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> v2: - use of VT8500_MAX_PORTS instead of BITS_PER_LONG to better self
>       document the code
>     - declare vt8500_ports_in_use with DECLARE_BITMAP in order to self
>       document even better and to be foolproof should VT8500_MAX_PORTS
>       be changed one day

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

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


Thread

[PATCH v2] serial: vt8500_serial: Fix a parameter of find_first_zero_bit. Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-08-24 07:10 +0200
  Re: [PATCH v2] serial: vt8500_serial: Fix a parameter of find_first_zero_bit. Arnd Bergmann <arnd@arndb.de> - 2016-08-24 09:30 +0200

csiph-web