@@ -920,6 +920,18 @@ void smc_pnet_exit(void)
static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)
{
+ /**
+ * __pnet_find_base_ndev - Find the base network device in a hierarchy.
+ * ndev: Pointer to the starting network device.
+ *
+ * This function traverses the adjacency list of a network device,
+ * to find the lowest-level (base) network device in the hierarchy.
+ *
+ */
+
+ if (!ndev)
+ return NULL;
+
int i, nest_lvl;
ASSERT_RTNL();
@@ -929,9 +941,9 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)
if (list_empty(lower))
break;
- lower = lower->next;
ndev = netdev_lower_get_next(ndev, &lower);
}
+
return ndev;
}
This patch improves the robustness of the function __pnet_find_base_ndev by: 1. Adding input validation for a NULL `ndev` pointer. 2. Ensuring the function exits gracefully if `netdev_lower_get_next` returns NULL during traversal. 3. Clarifying the function’s purpose with proper documentation. 4. Removing the redundant `lower = lower->next` statement, which caused traversal to skip levels or go beyond the logic intended, potentially leading to invalid memory access. The function now safely traverses the adjacency list of a network device to find the lowest-level (base) device in the hierarchy. Signed-off-by: Abdullah AlSharji <asharji1828@gmail.com> --- net/smc/smc_pnet.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)