From: Arnd Bergmann <arnd@arndb.de>
To: linux-arm-kernel@lists.infradead.org
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
linux@prisktech.co.nz, gregkh@linuxfoundation.org,
jslaby@suse.com, kernel-janitors@vger.kernel.org,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] serial: vt8500_serial: Fix a parameter of find_first_zero_bit.
Date: Mon, 22 Aug 2016 10:42:28 +0200 [thread overview]
Message-ID: <2512469.eM8MYFl15l@wuerfel> (raw)
In-Reply-To: <1471814425-18949-1-git-send-email-christophe.jaillet@wanadoo.fr>
On Sunday, August 21, 2016 11:20:25 PM 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.
>
> 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, so use
> BITS_PER_LONG instead.
>
>
> 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>
> ---
> Other options are possible:
> - 'vt8500_ports_in_use' being a 'unsigned long', use ffz to reduce
> code verbosity
> - VT8500_MAX_PORTS, in order to be consistent with the test below
Sorry, but I'm not following the logic here.
> ---
> drivers/tty/serial/vt8500_serial.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
> index 23cfc5e16b45..935076c50cb1 100644
> --- a/drivers/tty/serial/vt8500_serial.c
> +++ b/drivers/tty/serial/vt8500_serial.c
> @@ -664,7 +664,7 @@ static int vt8500_serial_probe(struct platform_device *pdev)
> if (port < 0) {
> /* calculate the port id */
> port = find_first_zero_bit(&vt8500_ports_in_use,
> - sizeof(vt8500_ports_in_use));
> + BITS_PER_LONG);
> }
You argue that the two have the same meaning, which I see, but
why is it better than the existing code?
Arnd
next prev parent reply other threads:[~2016-08-22 8:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-21 21:20 [PATCH] serial: vt8500_serial: Fix a parameter of find_first_zero_bit Christophe JAILLET
2016-08-22 8:42 ` Arnd Bergmann [this message]
2016-08-23 4:20 ` Christophe JAILLET
2016-08-23 9:23 ` Arnd Bergmann
2016-08-23 20:24 ` Christophe JAILLET
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2512469.eM8MYFl15l@wuerfel \
--to=arnd@arndb.de \
--cc=christophe.jaillet@wanadoo.fr \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@prisktech.co.nz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox