mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user