diff mbox series

[1/1] virtio: pass argument by value for virtqueue_map_iovec()

Message ID 1541139396-4727-1-git-send-email-dongli.zhang@oracle.com (mailing list archive)
State New, archived
Headers show
Series [1/1] virtio: pass argument by value for virtqueue_map_iovec() | expand

Commit Message

Dongli Zhang Nov. 2, 2018, 6:16 a.m. UTC
Pass num_sg by value instead of by pointer, as num_sg is never modified in
virtqueue_map_iovec().

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
 hw/virtio/virtio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Laurent Vivier Nov. 5, 2018, 8:40 a.m. UTC | #1
CC: Paolo as the use of modified num_sg has been removed by his patch:

  3b3b062821 virtio: slim down allocation of VirtQueueElements

On 02/11/2018 07:16, Dongli Zhang wrote:
> Pass num_sg by value instead of by pointer, as num_sg is never modified in
> virtqueue_map_iovec().
> 
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> ---
>  hw/virtio/virtio.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 4136d23..a5cb4e6 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -796,13 +796,13 @@ static void virtqueue_undo_map_desc(unsigned int out_num, unsigned int in_num,
>  }
>  
>  static void virtqueue_map_iovec(VirtIODevice *vdev, struct iovec *sg,
> -                                hwaddr *addr, unsigned int *num_sg,
> +                                hwaddr *addr, unsigned int num_sg,
>                                  int is_write)
>  {
>      unsigned int i;
>      hwaddr len;
>  
> -    for (i = 0; i < *num_sg; i++) {
> +    for (i = 0; i < num_sg; i++) {
>          len = sg[i].iov_len;
>          sg[i].iov_base = dma_memory_map(vdev->dma_as,
>                                          addr[i], &len, is_write ?
> @@ -821,8 +821,8 @@ static void virtqueue_map_iovec(VirtIODevice *vdev, struct iovec *sg,
>  
>  void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem)
>  {
> -    virtqueue_map_iovec(vdev, elem->in_sg, elem->in_addr, &elem->in_num, 1);
> -    virtqueue_map_iovec(vdev, elem->out_sg, elem->out_addr, &elem->out_num, 0);
> +    virtqueue_map_iovec(vdev, elem->in_sg, elem->in_addr, elem->in_num, 1);
> +    virtqueue_map_iovec(vdev, elem->out_sg, elem->out_addr, elem->out_num, 0);
>  }
>  
>  static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num)
>
Paolo Bonzini Nov. 5, 2018, 10:16 a.m. UTC | #2
On 05/11/2018 09:40, Laurent Vivier wrote:
> CC: Paolo as the use of modified num_sg has been removed by his patch:
> 
>   3b3b062821 virtio: slim down allocation of VirtQueueElements

Indeed, virtqueue_map and virtqueue_map_iovec are only used on migration
now, and that path does not need to modify *num_sg.  After my patch
virtqueue_pop calls virtqueue_map_desc instead of virtqueue_map (and
virtqueue_map_desc does need an in-out argument).

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

> On 02/11/2018 07:16, Dongli Zhang wrote:
>> Pass num_sg by value instead of by pointer, as num_sg is never modified in
>> virtqueue_map_iovec().
>>
>> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
>> ---
>>  hw/virtio/virtio.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>> index 4136d23..a5cb4e6 100644
>> --- a/hw/virtio/virtio.c
>> +++ b/hw/virtio/virtio.c
>> @@ -796,13 +796,13 @@ static void virtqueue_undo_map_desc(unsigned int out_num, unsigned int in_num,
>>  }
>>  
>>  static void virtqueue_map_iovec(VirtIODevice *vdev, struct iovec *sg,
>> -                                hwaddr *addr, unsigned int *num_sg,
>> +                                hwaddr *addr, unsigned int num_sg,
>>                                  int is_write)
>>  {
>>      unsigned int i;
>>      hwaddr len;
>>  
>> -    for (i = 0; i < *num_sg; i++) {
>> +    for (i = 0; i < num_sg; i++) {
>>          len = sg[i].iov_len;
>>          sg[i].iov_base = dma_memory_map(vdev->dma_as,
>>                                          addr[i], &len, is_write ?
>> @@ -821,8 +821,8 @@ static void virtqueue_map_iovec(VirtIODevice *vdev, struct iovec *sg,
>>  
>>  void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem)
>>  {
>> -    virtqueue_map_iovec(vdev, elem->in_sg, elem->in_addr, &elem->in_num, 1);
>> -    virtqueue_map_iovec(vdev, elem->out_sg, elem->out_addr, &elem->out_num, 0);
>> +    virtqueue_map_iovec(vdev, elem->in_sg, elem->in_addr, elem->in_num, 1);
>> +    virtqueue_map_iovec(vdev, elem->out_sg, elem->out_addr, elem->out_num, 0);
>>  }
>>  
>>  static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num)
>>
>
Laurent Vivier Nov. 5, 2018, 11:41 a.m. UTC | #3
On 02/11/2018 07:16, Dongli Zhang wrote:
> Pass num_sg by value instead of by pointer, as num_sg is never modified in
> virtqueue_map_iovec().
> 
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> ---
>  hw/virtio/virtio.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 

Applied to my branch trivial-patches.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 4136d23..a5cb4e6 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -796,13 +796,13 @@  static void virtqueue_undo_map_desc(unsigned int out_num, unsigned int in_num,
 }
 
 static void virtqueue_map_iovec(VirtIODevice *vdev, struct iovec *sg,
-                                hwaddr *addr, unsigned int *num_sg,
+                                hwaddr *addr, unsigned int num_sg,
                                 int is_write)
 {
     unsigned int i;
     hwaddr len;
 
-    for (i = 0; i < *num_sg; i++) {
+    for (i = 0; i < num_sg; i++) {
         len = sg[i].iov_len;
         sg[i].iov_base = dma_memory_map(vdev->dma_as,
                                         addr[i], &len, is_write ?
@@ -821,8 +821,8 @@  static void virtqueue_map_iovec(VirtIODevice *vdev, struct iovec *sg,
 
 void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem)
 {
-    virtqueue_map_iovec(vdev, elem->in_sg, elem->in_addr, &elem->in_num, 1);
-    virtqueue_map_iovec(vdev, elem->out_sg, elem->out_addr, &elem->out_num, 0);
+    virtqueue_map_iovec(vdev, elem->in_sg, elem->in_addr, elem->in_num, 1);
+    virtqueue_map_iovec(vdev, elem->out_sg, elem->out_addr, elem->out_num, 0);
 }
 
 static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num)