linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/mlx5: fpga: avoid uninitialized return codes
@ 2017-09-14 11:06 Arnd Bergmann
  2017-09-14 12:54 ` Leon Romanovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2017-09-14 11:06 UTC (permalink / raw)
  To: Ilan Tayari, Saeed Mahameed, Matan Barak, Leon Romanovsky
  Cc: Arnd Bergmann, Boris Pismenny, netdev, linux-rdma, linux-kernel

calling mlx5_fpga_mem_{read,write}_i2c() with a zero length on
older compiler version such as gcc-4.6 results in a warning that
the return code is not initialized:

drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c:147:6: error: ‘err’ may be used uninitialized in this function [-Werror=uninitialized]
drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c:126:6: error: ‘err’ may be used uninitialized in this function [-Werror=uninitialized]

On newer compilers, the 'err' variable is optimized away in this
code path and assumed to be zero when the loop completes, so we
don't get this warning.

I'm changing the function here to instead return -EINVAL for the
case, under the assumption that it was never meant to be called
with a zero length argument.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c
index 3c11d6e2160a..914fb9d77a1a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c
@@ -64,7 +64,7 @@ static int mlx5_fpga_mem_read_i2c(struct mlx5_fpga_device *fdev, size_t size,
 	size_t max_size = MLX5_FPGA_ACCESS_REG_SIZE_MAX;
 	size_t bytes_done = 0;
 	u8 actual_size;
-	int err;
+	int err = -EINVAL;
 
 	if (!fdev->mdev)
 		return -ENOTCONN;
@@ -93,7 +93,7 @@ static int mlx5_fpga_mem_write_i2c(struct mlx5_fpga_device *fdev, size_t size,
 	size_t max_size = MLX5_FPGA_ACCESS_REG_SIZE_MAX;
 	size_t bytes_done = 0;
 	u8 actual_size;
-	int err;
+	int err = -EINVAL;
 
 	if (!fdev->mdev)
 		return -ENOTCONN;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-14 18:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-14 11:06 [PATCH] net/mlx5: fpga: avoid uninitialized return codes Arnd Bergmann
2017-09-14 12:54 ` Leon Romanovsky
2017-09-14 18:39   ` Saeed Mahameed

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).