* [PATCH] IB/mlx5: revisit -Wmaybe-uninitialized warning
@ 2017-12-11 11:45 Arnd Bergmann
2017-12-11 23:41 ` Jason Gunthorpe
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2017-12-11 11:45 UTC (permalink / raw)
To: Matan Barak, Leon Romanovsky, Doug Ledford, Jason Gunthorpe
Cc: Arnd Bergmann, Artemy Kovalyov, Saeed Mahameed, David S. Miller,
Ilya Lesokhin, Bart Van Assche, linux-rdma, linux-kernel
A warning that I thought I had fixed before occasionally comes
back in rare randconfig builds (I found 7 instances in the last
100000 builds, originally it was much more frequent):
drivers/infiniband/hw/mlx5/mr.c: In function 'mlx5_ib_reg_user_mr':
drivers/infiniband/hw/mlx5/mr.c:1229:5: error: 'order' may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (order <= mr_cache_max_order(dev)) {
^
drivers/infiniband/hw/mlx5/mr.c:1247:8: error: 'ncont' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/infiniband/hw/mlx5/mr.c:1247:8: error: 'page_shift' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/infiniband/hw/mlx5/mr.c:1260:2: error: 'npages' may be used uninitialized in this function [-Werror=maybe-uninitialized]
I've looked at all those findings again and noticed that they are all
with CONFIG_INFINIBAND_USER_MEM=n, which means ib_umem_get() returns
an error unconditionally and we never initialize or use those variables.
This triggers a condition in gcc iff mr_umem_get() is partially but not
entirely inlined, which in turn depends on the exact combination of
optimization settings. This is a known problem with gcc, with no
easy solution in the compiler, so this adds another workaround that
should be more reliable than my previous attempt.
Returning an error from mlx5_ib_reg_user_mr() earlier means that we
can completely bypass the logic that caused the warning, the compiler
can now see that the variable is never accessed.
Fixes: 14ab8896f5d9 ("IB/mlx5: avoid bogus -Wmaybe-uninitialized warning")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/infiniband/hw/mlx5/mr.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index ee0ee1f9994b..ad37d8441fa2 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -1206,6 +1206,9 @@ struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
int err;
bool use_umr = true;
+ if (!IS_ENABLED(CONFIG_INFINIBAND_USER_MEM))
+ return ERR_PTR(-EINVAL);
+
mlx5_ib_dbg(dev, "start 0x%llx, virt_addr 0x%llx, length 0x%llx, access_flags 0x%x\n",
start, virt_addr, length, access_flags);
--
2.9.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: IB/mlx5: revisit -Wmaybe-uninitialized warning
2017-12-11 11:45 [PATCH] IB/mlx5: revisit -Wmaybe-uninitialized warning Arnd Bergmann
@ 2017-12-11 23:41 ` Jason Gunthorpe
0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2017-12-11 23:41 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Matan Barak, Leon Romanovsky, Doug Ledford, Artemy Kovalyov,
Saeed Mahameed, David S. Miller, Ilya Lesokhin, Bart Van Assche,
linux-rdma, linux-kernel
On Mon, Dec 11, 2017 at 12:45:44PM +0100, Arnd Bergmann wrote:
> A warning that I thought I had fixed before occasionally comes
> back in rare randconfig builds (I found 7 instances in the last
> 100000 builds, originally it was much more frequent):
>
> drivers/infiniband/hw/mlx5/mr.c: In function 'mlx5_ib_reg_user_mr':
> drivers/infiniband/hw/mlx5/mr.c:1229:5: error: 'order' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> if (order <= mr_cache_max_order(dev)) {
> ^
> drivers/infiniband/hw/mlx5/mr.c:1247:8: error: 'ncont' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> drivers/infiniband/hw/mlx5/mr.c:1247:8: error: 'page_shift' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> drivers/infiniband/hw/mlx5/mr.c:1260:2: error: 'npages' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> I've looked at all those findings again and noticed that they are all
> with CONFIG_INFINIBAND_USER_MEM=n, which means ib_umem_get() returns
> an error unconditionally and we never initialize or use those variables.
> This triggers a condition in gcc iff mr_umem_get() is partially but not
> entirely inlined, which in turn depends on the exact combination of
> optimization settings. This is a known problem with gcc, with no
> easy solution in the compiler, so this adds another workaround that
> should be more reliable than my previous attempt.
>
> Returning an error from mlx5_ib_reg_user_mr() earlier means that we
> can completely bypass the logic that caused the warning, the compiler
> can now see that the variable is never accessed.
>
> Fixes: 14ab8896f5d9 ("IB/mlx5: avoid bogus -Wmaybe-uninitialized warning")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> drivers/infiniband/hw/mlx5/mr.c | 3 +++
> 1 file changed, 3 insertions(+)
Appled to for-next, thanks
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-11 23:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-11 11:45 [PATCH] IB/mlx5: revisit -Wmaybe-uninitialized warning Arnd Bergmann
2017-12-11 23:41 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox