From 5ff3dbe6ce4c8c15fbb09fdf2ee64d09ce3be3cc Mon Sep 17 00:00:00 2001
From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Date: Thu, 6 Oct 2022 09:26:53 +0300
Subject: [PATCH] net/af_xdp: add log on XDP program removal failures

[ upstream commit 5ff3dbe6ce4c8c15fbb09fdf2ee64d09ce3be3cc ]

Make it visible in logs if something goes wrong on XDP program
removal failure.

Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Ferruh Yigit <ferruh.yigit@xilinx.com>
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 9957de2314..f7c2321a18 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -866,18 +866,24 @@ eth_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
-static void
+static int
 remove_xdp_program(struct pmd_internals *internals)
 {
 	uint32_t curr_prog_id = 0;
+	int ret;
 
-	if (bpf_get_link_xdp_id(internals->if_index, &curr_prog_id,
-				XDP_FLAGS_UPDATE_IF_NOEXIST)) {
+	ret = bpf_get_link_xdp_id(internals->if_index, &curr_prog_id,
+				  XDP_FLAGS_UPDATE_IF_NOEXIST);
+	if (ret != 0) {
 		AF_XDP_LOG(ERR, "bpf_get_link_xdp_id failed\n");
-		return;
+		return ret;
 	}
-	bpf_set_link_xdp_fd(internals->if_index, -1,
-			XDP_FLAGS_UPDATE_IF_NOEXIST);
+
+	ret = bpf_set_link_xdp_fd(internals->if_index, -1,
+				  XDP_FLAGS_UPDATE_IF_NOEXIST);
+	if (ret != 0)
+		AF_XDP_LOG(ERR, "bpf_set_link_xdp_fd failed\n");
+	return ret;
 }
 
 static void
@@ -932,7 +938,8 @@ eth_dev_close(struct rte_eth_dev *dev)
 	 */
 	dev->data->mac_addrs = NULL;
 
-	remove_xdp_program(internals);
+	if (remove_xdp_program(internals) != 0)
+		AF_XDP_LOG(ERR, "Error while removing XDP program.\n");
 
 	if (internals->shared_umem) {
 		struct internal_list *list;
-- 
2.33.0

