net/mlx5: Fix a compilation warning in events.c [Linux 5.0]

net/mlx5: Fix a compilation warning in events.c [Linux 5.0]

This Linux kernel change "net/mlx5: Fix a compilation warning in events.c" is included in the Linux 5.0 release. This change is authored by Tariq Toukan <tariqt [at] mellanox.com> on Tue Jan 22 14:18:04 2019 +0200. The commit for this change in Linux stable tree is 5400261 (patch).

net/mlx5: Fix a compilation warning in events.c

Eliminate the following compilation warning:

drivers/net/ethernet/mellanox/mlx5/core/events.c: warning: 'error_str'
may be used uninitialized in this function [-Wuninitialized]:  => 238:3

Fixes: c2fb3db22d35 ("net/mlx5: Rework handling of port module events")
Signed-off-by: Tariq Toukan <[email protected]>
Reviewed-by: Mikhael Goikhman <[email protected]>
Signed-off-by: Saeed Mahameed <[email protected]>

There are 17 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/net/ethernet/mellanox/mlx5/core/events.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/events.c b/drivers/net/ethernet/mellanox/mlx5/core/events.c
index fbc42b7..5030354 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/events.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/events.c
@@ -211,11 +211,10 @@ static int port_module(struct notifier_block *nb, unsigned long type, void *data
    enum port_module_event_status_type module_status;
    enum port_module_event_error_type error_type;
    struct mlx5_eqe_port_module *module_event_eqe;
-   const char *status_str, *error_str;
+   const char *status_str;
    u8 module_num;

    module_event_eqe = &eqe->data.port_module;
-   module_num = module_event_eqe->module;
    module_status = module_event_eqe->module_status &
            PORT_MODULE_EVENT_MODULE_STATUS_MASK;
    error_type = module_event_eqe->error_type &
@@ -223,25 +222,27 @@ static int port_module(struct notifier_block *nb, unsigned long type, void *data

    if (module_status < MLX5_MODULE_STATUS_NUM)
        events->pme_stats.status_counters[module_status]++;
-   status_str = mlx5_pme_status_to_string(module_status);

-   if (module_status == MLX5_MODULE_STATUS_ERROR) {
+   if (module_status == MLX5_MODULE_STATUS_ERROR)
        if (error_type < MLX5_MODULE_EVENT_ERROR_NUM)
            events->pme_stats.error_counters[error_type]++;
-       error_str = mlx5_pme_error_to_string(error_type);
-   }

    if (!printk_ratelimit())
        return NOTIFY_OK;

-   if (module_status == MLX5_MODULE_STATUS_ERROR)
+   module_num = module_event_eqe->module;
+   status_str = mlx5_pme_status_to_string(module_status);
+   if (module_status == MLX5_MODULE_STATUS_ERROR) {
+       const char *error_str = mlx5_pme_error_to_string(error_type);
+
        mlx5_core_err(events->dev,
                  "Port module event[error]: module %u, %s, %s\n",
                  module_num, status_str, error_str);
-   else
+   } else {
        mlx5_core_info(events->dev,
                   "Port module event: module %u, %s\n",
                   module_num, status_str);
+   }

    return NOTIFY_OK;
 }

Leave a Reply

Your email address will not be published. Required fields are marked *