Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions components/net/lwip/port/ethernetif.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,14 @@ static err_t eth_netif_device_init(struct netif *netif)
device = (rt_device_t) ethif;
if (rt_device_init(device) != RT_EOK)
{
return ERR_IF;
rt_kprintf("eth device initialization failed!\n");
}
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
else
{
return ERR_IF;
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
rt_kprintf("eth device open failed!\n");
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the initialization case, removing the error return from device open failure removes important error information from the caller. The function should indicate failure when critical operations like device opening fail. / 与初始化情况类似,从设备打开失败中移除错误返回会从调用者那里移除重要的错误信息。当设备打开等关键操作失败时,函数应该指示失败。

Suggested change
rt_kprintf("eth device open failed!\n");
rt_kprintf("eth device open failed!\n");
return ERR_IF;

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Maihuanyi 这块不需要错误返回?

}
Comment on lines 500 to +506
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the error return (ERR_IF) from device initialization failure changes the function's behavior significantly. The caller will not know that initialization failed, which could lead to undefined behavior when trying to use an uninitialized device. Consider keeping the error return or adding alternative error handling. / 从设备初始化失败中移除错误返回(ERR_IF)显著改变了函数的行为。调用者将不知道初始化失败,这可能在尝试使用未初始化的设备时导致未定义行为。建议保留错误返回或添加替代错误处理。

Copilot uses AI. Check for mistakes.
}

/* copy device flags to netif flags */
Expand Down Expand Up @@ -684,11 +687,14 @@ static err_t af_unix_eth_netif_device_init(struct netif *netif)
device = (rt_device_t) ethif;
if (rt_device_init(device) != RT_EOK)
{
return ERR_IF;
rt_kprintf("eth device initialization failed!\n");
}
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
else
{
return ERR_IF;
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
rt_kprintf("eth device open failed!\n");
}
}

/* copy device flags to netif flags */
Expand Down Expand Up @@ -850,23 +856,65 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)

RT_ASSERT(dev != RT_NULL);

struct eth_device* enetif = (struct eth_device*)dev->netif->state;
rt_device_t device = (rt_device_t)(&(enetif->parent));

level = rt_spin_lock_irqsave(&(dev->spinlock));
dev->link_changed = 0x01;
if (up == RT_TRUE)
{
/* @note Check whether the eth device was successfully initialized, otherwise re-initialize */
if (!(device->flag & RT_DEVICE_FLAG_ACTIVATED))
{
if (rt_device_init(device) != RT_EOK)
{
rt_kprintf("eth device initialization failed!\n");
goto err;
}
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
rt_kprintf("eth device open failed!\n");
goto err;
}
}
dev->link_status = 0x01;
}
else
dev->link_status = 0x00;
rt_spin_unlock_irqrestore(&(dev->spinlock), level);

/* post message to ethernet thread */
return rt_mb_send(&eth_rx_thread_mb, (rt_ubase_t)dev);

err:
rt_spin_unlock_irqrestore(&(dev->spinlock), level);
return -RT_ERROR;
}
#else
/* NOTE: please not use it in interrupt when no RxThread exist */
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
{
struct eth_device* enetif = (struct eth_device*)dev->netif->state;
rt_device_t device = (rt_device_t)(&(enetif->parent));

if (up == RT_TRUE)
{
/* @note Check whether the eth device was successfully initialized, otherwise re-initialize */
if (!(device->flag & RT_DEVICE_FLAG_ACTIVATED))
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable 'device' is used but not declared in this scope. In the #else block (line 897), the device variable is referenced but not defined, unlike in the #if block where it's properly declared on line 861. / 变量 'device' 在此作用域中被使用但未声明。在 #else 块(第897行)中,device 变量被引用但未定义,不像在 #if 块中在第861行正确声明。

Copilot uses AI. Check for mistakes.
{
if (rt_device_init(device) != RT_EOK)
{
rt_kprintf("eth device initialization failed!\n");
return -RT_ERROR;
}
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
rt_kprintf("eth device open failed!\n");
return -RT_ERROR;
}
}
netifapi_netif_set_link_up(dev->netif);
}
else
netifapi_netif_set_link_down(dev->netif);

Expand Down