Skip to content

[components][sal]replace netdev's spin_lock_irqsave to spin_lock #9423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2024
Merged
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
40 changes: 17 additions & 23 deletions components/net/netdev/src/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ static RT_DEFINE_SPINLOCK(_spinlock);
*/
int netdev_register(struct netdev *netdev, const char *name, void *user_data)
{
rt_base_t level;
rt_uint16_t flags_mask;
rt_uint16_t index;

Expand Down Expand Up @@ -103,7 +102,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
/* initialize current network interface device single list */
rt_slist_init(&(netdev->list));

level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);

if (netdev_list == RT_NULL)
{
Expand All @@ -115,7 +114,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
rt_slist_append(&(netdev_list->list), &(netdev->list));
}

rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);

if (netdev_default == RT_NULL)
{
Expand Down Expand Up @@ -146,7 +145,6 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
*/
int netdev_unregister(struct netdev *netdev)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *cur_netdev = RT_NULL;

Expand All @@ -157,7 +155,7 @@ int netdev_unregister(struct netdev *netdev)
return -RT_ERROR;
}

level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);

for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
Expand Down Expand Up @@ -188,7 +186,7 @@ int netdev_unregister(struct netdev *netdev)
break;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);

#if defined(SAL_USING_AF_NETLINK)
rtnl_ip_notify(netdev, RTM_DELLINK);
Expand Down Expand Up @@ -233,7 +231,6 @@ void netdev_set_register_callback(netdev_callback_fn register_callback)
*/
struct netdev *netdev_get_first_by_flags(uint16_t flags)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;

Expand All @@ -242,19 +239,19 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
return RT_NULL;
}

level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);

for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (netdev->flags & flags) != 0)
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}

rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);

return RT_NULL;
}
Expand All @@ -270,7 +267,6 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
*/
struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;

Expand All @@ -279,19 +275,19 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
return RT_NULL;
}

level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);

for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && ip_addr_cmp(&(netdev->ip_addr), ip_addr))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}

rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);

return RT_NULL;
}
Expand All @@ -307,7 +303,6 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
*/
struct netdev *netdev_get_by_name(const char *name)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;

Expand All @@ -316,19 +311,19 @@ struct netdev *netdev_get_by_name(const char *name)
return RT_NULL;
}

level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);

for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(name) < RT_NAME_MAX ? rt_strlen(name) : RT_NAME_MAX) == 0))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}

rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);

return RT_NULL;
}
Expand All @@ -345,7 +340,6 @@ struct netdev *netdev_get_by_name(const char *name)
*/
struct netdev *netdev_get_by_family(int family)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
struct sal_proto_family *pf = RT_NULL;
Expand All @@ -355,15 +349,15 @@ struct netdev *netdev_get_by_family(int family)
return RT_NULL;
}

level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);

for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
Expand All @@ -374,12 +368,12 @@ struct netdev *netdev_get_by_family(int family)
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->sec_family == family && netdev_is_up(netdev))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}

rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);

return RT_NULL;
}
Expand Down
Loading