net/can: replace net_lock with conn_lock and conn_lock_dev

Protect can resources through netdev_lock, conn_lock, and can_list_lock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-06-19 14:03:24 +08:00
committed by Xiang Xiao
parent 4fa74e4d18
commit 02e7ed7cc4
10 changed files with 90 additions and 29 deletions
+6 -12
View File
@@ -248,7 +248,7 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
* because we don't want anything to happen until we are ready.
*/
net_lock();
conn_dev_lock(&conn->sconn, dev);
#if CONFIG_NET_SEND_BUFSIZE > 0
if ((iob_get_queue_size(&conn->write_q) + msg->msg_iov->iov_len) >
@@ -313,21 +313,15 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
}
else
{
unsigned int count;
int blresult;
/* iob_copyin might wait for buffers to be freed, but if
* network is locked this might never happen, since network
* driver is also locked, therefore we need to break the lock
*/
blresult = net_breaklock(&count);
conn_dev_unlock(&conn->sconn, dev);
ret = iob_copyin(wb_iob, (FAR uint8_t *)msg->msg_iov->iov_base,
msg->msg_iov->iov_len, 0, false);
if (blresult >= 0)
{
net_restorelock(count);
}
conn_dev_lock(&conn->sconn, dev);
}
if (ret < 0)
@@ -389,7 +383,7 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
/* unlock */
net_unlock();
conn_dev_unlock(&conn->sconn, dev);
/* Notify the device driver that new TX data is available. */
@@ -399,7 +393,7 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
{
/* unlock */
net_unlock();
conn_dev_unlock(&conn->sconn, dev);
}
return msg->msg_iov->iov_len;
@@ -411,7 +405,7 @@ errout_with_wq:
iob_free_queue(&conn->write_q);
errout_with_lock:
net_unlock();
conn_dev_unlock(&conn->sconn, dev);
return ret;
}