]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net/mlx5e: Fix trap event handling
authorJiri Pirko <jiri@nvidia.com>
Thu, 24 Nov 2022 12:05:53 +0000 (13:05 +0100)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 9 Feb 2023 04:40:56 +0000 (20:40 -0800)
Current code does not return correct return value from event handler.
Fix it by returning NOTIFY_* and propagate err over newly introduce ctx
structure.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/devlink.c
drivers/net/ethernet/mellanox/mlx5/core/devlink.h
drivers/net/ethernet/mellanox/mlx5/core/en_main.c

index 5bd83c0275f8218af3a2f182376706cfbff08c7c..c06baa317fbd16bed30be094b37330edaf26cf61 100644 (file)
@@ -263,9 +263,10 @@ static int mlx5_devlink_trap_action_set(struct devlink *devlink,
                                        struct netlink_ext_ack *extack)
 {
        struct mlx5_core_dev *dev = devlink_priv(devlink);
+       struct mlx5_devlink_trap_event_ctx trap_event_ctx;
        enum devlink_trap_action action_orig;
        struct mlx5_devlink_trap *dl_trap;
-       int err = 0;
+       int err;
 
        if (is_mdev_switchdev_mode(dev)) {
                NL_SET_ERR_MSG_MOD(extack, "Devlink traps can't be set in switchdev mode");
@@ -275,26 +276,25 @@ static int mlx5_devlink_trap_action_set(struct devlink *devlink,
        dl_trap = mlx5_find_trap_by_id(dev, trap->id);
        if (!dl_trap) {
                mlx5_core_err(dev, "Devlink trap: Set action on invalid trap id 0x%x", trap->id);
-               err = -EINVAL;
-               goto out;
+               return -EINVAL;
        }
 
-       if (action != DEVLINK_TRAP_ACTION_DROP && action != DEVLINK_TRAP_ACTION_TRAP) {
-               err = -EOPNOTSUPP;
-               goto out;
-       }
+       if (action != DEVLINK_TRAP_ACTION_DROP && action != DEVLINK_TRAP_ACTION_TRAP)
+               return -EOPNOTSUPP;
 
        if (action == dl_trap->trap.action)
-               goto out;
+               return 0;
 
        action_orig = dl_trap->trap.action;
        dl_trap->trap.action = action;
+       trap_event_ctx.trap = &dl_trap->trap;
+       trap_event_ctx.err = 0;
        err = mlx5_blocking_notifier_call_chain(dev, MLX5_DRIVER_EVENT_TYPE_TRAP,
-                                               &dl_trap->trap);
-       if (err)
+                                               &trap_event_ctx);
+       if (err == NOTIFY_BAD)
                dl_trap->trap.action = action_orig;
-out:
-       return err;
+
+       return trap_event_ctx.err;
 }
 
 static const struct devlink_ops mlx5_devlink_ops = {
index fd033df248560105cefe265d7c6e35888425fe8d..b84cb70eb3aefb8d99960bc56533d267c332f1b1 100644 (file)
@@ -24,6 +24,11 @@ struct mlx5_devlink_trap {
        struct list_head list;
 };
 
+struct mlx5_devlink_trap_event_ctx {
+       struct mlx5_trap_ctx *trap;
+       int err;
+};
+
 struct mlx5_core_dev;
 void mlx5_devlink_trap_report(struct mlx5_core_dev *dev, int trap_id, struct sk_buff *skb,
                              struct devlink_port *dl_port);
index cff5f2e29e1e2b347197c23924704299e2720b1d..7471c4e8004cd8a726d821e7659c6790eaf22a9c 100644 (file)
@@ -179,17 +179,21 @@ static void mlx5e_disable_async_events(struct mlx5e_priv *priv)
 static int blocking_event(struct notifier_block *nb, unsigned long event, void *data)
 {
        struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv, blocking_events_nb);
+       struct mlx5_devlink_trap_event_ctx *trap_event_ctx = data;
        int err;
 
        switch (event) {
        case MLX5_DRIVER_EVENT_TYPE_TRAP:
-               err = mlx5e_handle_trap_event(priv, data);
+               err = mlx5e_handle_trap_event(priv, trap_event_ctx->trap);
+               if (err) {
+                       trap_event_ctx->err = err;
+                       return NOTIFY_BAD;
+               }
                break;
        default:
-               netdev_warn(priv->netdev, "Sync event: Unknown event %ld\n", event);
-               err = -EINVAL;
+               return NOTIFY_DONE;
        }
-       return err;
+       return NOTIFY_OK;
 }
 
 static void mlx5e_enable_blocking_events(struct mlx5e_priv *priv)