* [PATCH] IB/mlx5: Fix a parameter of find_first_bit
@ 2016-08-26 5:16 Christophe JAILLET
[not found] ` <1472188577-14550-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-09-02 17:12 ` Doug Ledford
0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2016-08-26 5:16 UTC (permalink / raw)
To: matanb, leonro, dledford, sean.hefty, hal.rosenstock
Cc: linux-rdma, linux-kernel, kernel-janitors, Christophe JAILLET
The 2nd parameter of 'find_first_bit' is the number of bits to search.
In this case, we are passing 'sizeof(tmp)' which is likely to be 4 or 8
because 'tmp' is an 'unsigned long'.
It is likely that the number of bits of 'tmp' 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>
---
__ffs could be used to reduce code verbosity
---
drivers/infiniband/hw/mlx5/mem.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/hw/mlx5/mem.c b/drivers/infiniband/hw/mlx5/mem.c
index 40df2cca0609..996b54e366b0 100644
--- a/drivers/infiniband/hw/mlx5/mem.c
+++ b/drivers/infiniband/hw/mlx5/mem.c
@@ -71,7 +71,7 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
addr = addr >> page_shift;
tmp = (unsigned long)addr;
- m = find_first_bit(&tmp, sizeof(tmp));
+ m = find_first_bit(&tmp, BITS_PER_LONG);
skip = 1 << m;
mask = skip - 1;
i = 0;
@@ -81,7 +81,7 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
for (k = 0; k < len; k++) {
if (!(i & mask)) {
tmp = (unsigned long)pfn;
- m = min_t(unsigned long, m, find_first_bit(&tmp, sizeof(tmp)));
+ m = min_t(unsigned long, m, find_first_bit(&tmp, BITS_PER_LONG));
skip = 1 << m;
mask = skip - 1;
base = pfn;
@@ -89,7 +89,7 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
} else {
if (base + p != pfn) {
tmp = (unsigned long)p;
- m = find_first_bit(&tmp, sizeof(tmp));
+ m = find_first_bit(&tmp, BITS_PER_LONG);
skip = 1 << m;
mask = skip - 1;
base = pfn;
--
2.7.4
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] IB/mlx5: Fix a parameter of find_first_bit
[not found] ` <1472188577-14550-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
@ 2016-08-26 9:52 ` Majd Dibbiny
2016-08-26 19:33 ` Leon Romanovsky
1 sibling, 0 replies; 4+ messages in thread
From: Majd Dibbiny @ 2016-08-26 9:52 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Matan Barak, Leon Romanovsky, dledford-H+wXaHxf7aLQT0dZR+AlfA,
sean.hefty-ral2JQCrhuEAvxtiuMwx3w,
hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w,
linux-rdma-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA
Acked-by: Majd Dibbiny <majd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> On Aug 26, 2016, at 8:25 AM, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
>
> The 2nd parameter of 'find_first_bit' is the number of bits to search.
> In this case, we are passing 'sizeof(tmp)' which is likely to be 4 or 8
> because 'tmp' is an 'unsigned long'.
>
> It is likely that the number of bits of 'tmp' 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-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
> ---
> __ffs could be used to reduce code verbosity
> ---
> drivers/infiniband/hw/mlx5/mem.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/infiniband/hw/mlx5/mem.c b/drivers/infiniband/hw/mlx5/mem.c
> index 40df2cca0609..996b54e366b0 100644
> --- a/drivers/infiniband/hw/mlx5/mem.c
> +++ b/drivers/infiniband/hw/mlx5/mem.c
> @@ -71,7 +71,7 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
>
> addr = addr >> page_shift;
> tmp = (unsigned long)addr;
> - m = find_first_bit(&tmp, sizeof(tmp));
> + m = find_first_bit(&tmp, BITS_PER_LONG);
> skip = 1 << m;
> mask = skip - 1;
> i = 0;
> @@ -81,7 +81,7 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
> for (k = 0; k < len; k++) {
> if (!(i & mask)) {
> tmp = (unsigned long)pfn;
> - m = min_t(unsigned long, m, find_first_bit(&tmp, sizeof(tmp)));
> + m = min_t(unsigned long, m, find_first_bit(&tmp, BITS_PER_LONG));
> skip = 1 << m;
> mask = skip - 1;
> base = pfn;
> @@ -89,7 +89,7 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
> } else {
> if (base + p != pfn) {
> tmp = (unsigned long)p;
> - m = find_first_bit(&tmp, sizeof(tmp));
> + m = find_first_bit(&tmp, BITS_PER_LONG);
> skip = 1 << m;
> mask = skip - 1;
> base = pfn;
> --
> 2.7.4
>
>
> ---
> L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
> https://www.avast.com/antivirus
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] IB/mlx5: Fix a parameter of find_first_bit
[not found] ` <1472188577-14550-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-08-26 9:52 ` Majd Dibbiny
@ 2016-08-26 19:33 ` Leon Romanovsky
1 sibling, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2016-08-26 19:33 UTC (permalink / raw)
To: Christophe JAILLET
Cc: matanb-VPRAkNaXOzVWk0Htik3J/w, dledford-H+wXaHxf7aLQT0dZR+AlfA,
sean.hefty-ral2JQCrhuEAvxtiuMwx3w,
hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w,
linux-rdma-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 702 bytes --]
On Fri, Aug 26, 2016 at 07:16:17AM +0200, Christophe JAILLET wrote:
> The 2nd parameter of 'find_first_bit' is the number of bits to search.
> In this case, we are passing 'sizeof(tmp)' which is likely to be 4 or 8
> because 'tmp' is an 'unsigned long'.
>
> It is likely that the number of bits of 'tmp' 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-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
Thanks,
Acked-by: Leon Romanovsky <leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] IB/mlx5: Fix a parameter of find_first_bit
2016-08-26 5:16 [PATCH] IB/mlx5: Fix a parameter of find_first_bit Christophe JAILLET
[not found] ` <1472188577-14550-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
@ 2016-09-02 17:12 ` Doug Ledford
1 sibling, 0 replies; 4+ messages in thread
From: Doug Ledford @ 2016-09-02 17:12 UTC (permalink / raw)
To: Christophe JAILLET, matanb, leonro, sean.hefty, hal.rosenstock
Cc: linux-rdma, linux-kernel, kernel-janitors
[-- Attachment #1.1: Type: text/plain, Size: 436 bytes --]
On 8/26/2016 1:16 AM, Christophe JAILLET wrote:
> The 2nd parameter of 'find_first_bit' is the number of bits to search.
> In this case, we are passing 'sizeof(tmp)' which is likely to be 4 or 8
> because 'tmp' is an 'unsigned long'.
>
> It is likely that the number of bits of 'tmp' was expected here. So use
> BITS_PER_LONG instead.
Thanks, applied.
--
Doug Ledford <dledford@redhat.com>
GPG Key ID: 0E572FDD
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-02 17:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-26 5:16 [PATCH] IB/mlx5: Fix a parameter of find_first_bit Christophe JAILLET
[not found] ` <1472188577-14550-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-08-26 9:52 ` Majd Dibbiny
2016-08-26 19:33 ` Leon Romanovsky
2016-09-02 17:12 ` Doug Ledford
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).