mlxsw: spectrum_kvdl: avoid uninitialized variable warning
authorArnd Bergmann <arnd@arndb.de>
Fri, 23 Feb 2018 13:15:32 +0000 (14:15 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 26 Feb 2018 16:33:02 +0000 (11:33 -0500)
gcc warns that 'resource_id' is not initialized if we don't come though
any of the three 'case' statements before:

drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c: In function 'mlxsw_sp_kvdl_part_init':
drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c:275:8: error: 'resource_id' may be used uninitialized in this function [-Werror=maybe-uninitialized]

In the current code, that won't happen, but it's more robust to explicitly
handle this by returning a failure from mlxsw_sp_kvdl_part_init.

Fixes: 887839e6960d ("mlxsw: spectrum_kvdl: Add support for dynamic partition set")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c

index 6fd701db90c9e951313fb4bf3b812006d18f0f1e..059eb321432885571e259106637ad41d2d752fc2 100644 (file)
@@ -270,6 +270,8 @@ static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp,
        case MLXSW_SP_KVDL_PART_LARGE_CHUNKS:
                resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS;
                break;
+       default:
+               return -EINVAL;
        }
 
        err = devlink_resource_size_get(devlink, resource_id, &resource_size);