diff mbox

[v2,06/45] ivshmem: remove unnecessary dup()

Message ID 1438043577-28636-7-git-send-email-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau July 28, 2015, 12:32 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@gmail.com>

qemu_chr_fe_get_msgfd() transfer ownership, there is no need to dup the fd.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/misc/ivshmem.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

Comments

Eric Blake July 29, 2015, 7:10 p.m. UTC | #1
On 07/27/2015 06:32 PM, Marc-André Lureau wrote:
> From: Marc-André Lureau <marcandre.lureau@gmail.com>
> 
> qemu_chr_fe_get_msgfd() transfer ownership, there is no need to dup the fd.

s/transfer/transfers/

> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Interesting difference in From: vs. S-o-b:; you may want to check your
configuration, and/or update .mailmap so that we can consolidate all
contributions from you under different addresses into a single author
lookup.
Marc-André Lureau July 30, 2015, 1:11 p.m. UTC | #2
hi

On Wed, Jul 29, 2015 at 9:10 PM, Eric Blake <eblake@redhat.com> wrote:
> On 07/27/2015 06:32 PM, Marc-André Lureau wrote:
>> From: Marc-André Lureau <marcandre.lureau@gmail.com>
>>
>> qemu_chr_fe_get_msgfd() transfer ownership, there is no need to dup the fd.
>
> s/transfer/transfers/
>
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Interesting difference in From: vs. S-o-b:; you may want to check your
> configuration, and/or update .mailmap so that we can consolidate all
> contributions from you under different addresses into a single author
> lookup.
>

both fixed, thanks
diff mbox

Patch

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index dd15f0e..fbeb731 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -480,7 +480,7 @@  static bool fifo_update_and_get(IVShmemState *s, const uint8_t *buf, int size,
 static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
 {
     IVShmemState *s = opaque;
-    int incoming_fd, tmp_fd;
+    int incoming_fd;
     int guest_max_eventfd;
     long incoming_posn;
 
@@ -495,21 +495,21 @@  static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
     }
 
     /* pick off s->server_chr->msgfd and store it, posn should accompany msg */
-    tmp_fd = qemu_chr_fe_get_msgfd(s->server_chr);
-    IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, tmp_fd);
+    incoming_fd = qemu_chr_fe_get_msgfd(s->server_chr);
+    IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, incoming_fd);
 
     /* make sure we have enough space for this guest */
     if (incoming_posn >= s->nb_peers) {
         if (increase_dynamic_storage(s, incoming_posn) < 0) {
             error_report("increase_dynamic_storage() failed");
-            if (tmp_fd != -1) {
-                close(tmp_fd);
+            if (incoming_fd != -1) {
+                close(incoming_fd);
             }
             return;
         }
     }
 
-    if (tmp_fd == -1) {
+    if (incoming_fd == -1) {
         /* if posn is positive and unseen before then this is our posn*/
         if ((incoming_posn >= 0) &&
                             (s->peers[incoming_posn].eventfds == NULL)) {
@@ -524,15 +524,6 @@  static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
         }
     }
 
-    /* because of the implementation of get_msgfd, we need a dup */
-    incoming_fd = dup(tmp_fd);
-
-    if (incoming_fd == -1) {
-        error_report("could not allocate file descriptor %s", strerror(errno));
-        close(tmp_fd);
-        return;
-    }
-
     /* if the position is -1, then it's shared memory region fd */
     if (incoming_posn == -1) {