When using template API with a represented_port pattern item that
has no spec, mlx5dr_rule_skip() dereferences a NULL pointer when
accessing v->port_id.

Now validating the spec before accessing port_id.

Fixes: 405242c52dd5 ("net/mlx5/hws: add rule object")
Cc: [email protected]

Signed-off-by: Shani Peretz <[email protected]>
Acked-by: Bing Zhao <[email protected]>
---
 drivers/net/mlx5/hws/mlx5dr_rule.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/mlx5/hws/mlx5dr_rule.c 
b/drivers/net/mlx5/hws/mlx5dr_rule.c
index 895ac858ec..23327d2b73 100644
--- a/drivers/net/mlx5/hws/mlx5dr_rule.c
+++ b/drivers/net/mlx5/hws/mlx5dr_rule.c
@@ -38,6 +38,10 @@ static void mlx5dr_rule_skip(struct mlx5dr_matcher *matcher,
 
        if (mt->item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) {
                v = items[mt->vport_item_id].spec;
+               if (unlikely(!v)) {
+                       DR_LOG(NOTICE, "Fail to get vport item, ignoring");
+                       return;
+               }
                vport = flow_hw_conv_port_id(matcher->tbl->ctx, v->port_id);
                if (unlikely(!vport)) {
                        DR_LOG(ERR, "Fail to map port ID %d, ignoring", 
v->port_id);
-- 
2.43.0

Reply via email to