Commit e3ec366e authored by Arseniy Krasnov's avatar Arseniy Krasnov Committed by Paolo Abeni

virtio/vsock: check argument to avoid no effect call

Both of these functions have no effect when input argument is 0, so to
avoid useless spinlock access, check argument before it.
Signed-off-by: default avatarArseniy Krasnov <AVKrasnov@sberdevices.ru>
Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent b68ffb1b
...@@ -302,6 +302,9 @@ u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 credit) ...@@ -302,6 +302,9 @@ u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 credit)
{ {
u32 ret; u32 ret;
if (!credit)
return 0;
spin_lock_bh(&vvs->tx_lock); spin_lock_bh(&vvs->tx_lock);
ret = vvs->peer_buf_alloc - (vvs->tx_cnt - vvs->peer_fwd_cnt); ret = vvs->peer_buf_alloc - (vvs->tx_cnt - vvs->peer_fwd_cnt);
if (ret > credit) if (ret > credit)
...@@ -315,6 +318,9 @@ EXPORT_SYMBOL_GPL(virtio_transport_get_credit); ...@@ -315,6 +318,9 @@ EXPORT_SYMBOL_GPL(virtio_transport_get_credit);
void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit) void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit)
{ {
if (!credit)
return;
spin_lock_bh(&vvs->tx_lock); spin_lock_bh(&vvs->tx_lock);
vvs->tx_cnt -= credit; vvs->tx_cnt -= credit;
spin_unlock_bh(&vvs->tx_lock); spin_unlock_bh(&vvs->tx_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment