From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751620AbdINSjo (ORCPT ); Thu, 14 Sep 2017 14:39:44 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36182 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751499AbdINSjm (ORCPT ); Thu, 14 Sep 2017 14:39:42 -0400 X-Google-Smtp-Source: AOwi7QDc70CEN3ipgW1kIYtFVDbvwwGm0KDeBq9cQMED46iW7opUiEgjr99FzrbJ1Wh54wApTf1l4EZ/jrX1rYBKk0c= MIME-Version: 1.0 In-Reply-To: <20170914125429.GZ3405@mtr-leonro.local> References: <20170914110628.3590833-1-arnd@arndb.de> <20170914125429.GZ3405@mtr-leonro.local> From: Saeed Mahameed Date: Thu, 14 Sep 2017 11:39:20 -0700 Message-ID: Subject: Re: [PATCH] net/mlx5: fpga: avoid uninitialized return codes To: Leon Romanovsky Cc: Arnd Bergmann , Ilan Tayari , Saeed Mahameed , Matan Barak , Boris Pismenny , Linux Netdev List , linux-rdma@vger.kernel.org, linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v8EIdmPj023286 On Thu, Sep 14, 2017 at 5:54 AM, Leon Romanovsky wrote: > On Thu, Sep 14, 2017 at 01:06:18PM +0200, Arnd Bergmann wrote: >> 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. Thanks Arnd, Looks good. > > I agree with you that size can't be zero and this patch will fix the > warning, but if it is possible, I will prefer to have this check is > written explicitly and not implicitly. > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c > index 3c11d6e2160a..0e85bebe1dad 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c > @@ -69,6 +69,9 @@ static int mlx5_fpga_mem_read_i2c(struct mlx5_fpga_device *fdev, size_t size, > if (!fdev->mdev) > return -ENOTCONN; > > + if (!size) > + return -EINVAL; > + Or simply trust the caller :), and avoid redundant code. > while (bytes_done < size) { > actual_size = min(max_size, (size - bytes_done)); > > Thanks > >> >> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203 >> Signed-off-by: Arnd Bergmann >> --- >> 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 >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html