Skip to contentSkip to conversation

Trivial patches for 15 to 23 September 2012

GIT PULL New Stefan Hajnoczi 2 participants 16 messages Sep 23, 2012 – Sep 25, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The following changes since commit 93b6599734f81328ee3d608f57667742cafeea72:

audio: Fix warning from static code analysis (2012-09-23 01:34:16 +0400)

are available in the git repository at:

git://github.com/stefanha/qemu.git trivial-patches

for you to fetch changes up to 95df51a4a02a853af8828c281bce2d4f2a41d6fd:

w32: Always use standard instead of native format strings (2012-09-23 07:39:22 +0100)

----------------------------------------------------------------
Alon Levy (1):
dtrace backend: add function to reserved words

Don Slutz (1):
target-i386: Allow tsc-frequency to be larger then 2.147G

Hitoshi Mitake (1):
curses: don't initialize curses when qemu is daemonized

Laszlo Ersek (1):
TextConsole: saturate escape parameter in TTY_STATE_CSI

Paolo Bonzini (1):
qemu-timer: simplify qemu_run_timers

Stefan Weil (9):
qemu-ga: Remove unreachable code after g_error
qemu-sockets: Fix potential memory leak
cadence_uart: Fix buffer overflow
lm4549: Fix buffer overflow
ioh3420: Remove unreachable code
pflash_cfi01: Fix warning caused by unreachable code
linux-user: Remove redundant null check and replace free by g_free net/socket: Fix compiler warning (regression for MinGW)
w32: Always use standard instead of native format strings

 compiler.h                          |    5 +++++
 console.c                           |    7 +++++--
 hw/cadence_uart.c                   |    2 +-
 hw/ioh3420.c                        |    1 -
 hw/lm4549.c                         |    2 +-
 hw/pflash_cfi01.c                   |    8 ++++----
 linux-user/syscall.c                |    4 +---
 net/socket.c                        |    6 +++---
 os-posix.c                          |    5 +++++
 qemu-common.h                       |    5 +++++
 qemu-ga.c                           |    2 --
 qemu-os-posix.h                     |    2 ++
 qemu-os-win32.h                     |    5 +++++
 qemu-sockets.c                      |    2 +-
 qemu-timer.c                        |    7 +++----
 scripts/tracetool/backend/dtrace.py |    2 +-
 target-i386/cpu.c                   |    2 +-
 vl.c                                |    4 +++-
 18 files changed, 46 insertions(+), 25 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/14 target-i386: Allow tsc-frequency to be larger then 2.147G

From: Don Slutz <[email protected]>

The check using INT_MAX (2147483647) is wrong in this case.

---
 target-i386/cpu.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.c +1 -1
index 423e009..cbc172e 100644
@@ -846,7 +846,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
 {
     X86CPU *cpu = X86_CPU(obj);
     const int64_t min = 0;
-    const int64_t max = INT_MAX;
+    const int64_t max = INT64_MAX;
     int64_t value;
 
     visit_type_int(v, &value, name, errp);
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/14 qemu-ga: Remove unreachable code after g_error

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

Report from smatch:
qemu-ga.c:117 register_signal_handlers(11) info: ignoring unreachable code. qemu-ga.c:122 register_signal_handlers(16) info: ignoring unreachable code.

g_error calls abort which terminates the program.

---
 qemu-ga.c |    2 --
 1 file changed, 2 deletions(-)
qemu-ga.c +0 -2
index 7623079..b747470 100644
@@ -114,12 +114,10 @@ static gboolean register_signal_handlers(void)
     ret = sigaction(SIGINT, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
-        return false;
     }
     ret = sigaction(SIGTERM, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
-        return false;
     }
 
     return true;
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/14 qemu-sockets: Fix potential memory leak

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

The old code leaks variable 'peer'.

---
 qemu-sockets.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-sockets.c +1 -1
index 361d890..037775b 100644
@@ -353,7 +353,7 @@ int inet_dgram_opts(QemuOpts *opts)
     if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {
         fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
                 gai_strerror(rc));
-        return -1;
+        goto err;
     }
 
     /* create socket */
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/14 cadence_uart: Fix buffer overflow

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

Report from smatch:
hw/cadence_uart.c:413 uart_read(13) error: buffer overflow 's->r' 18 <= 18

This fixes read access to s->r[R_MAX] which is behind the limits of s->r.

---
 hw/cadence_uart.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/cadence_uart.c +1 -1
index d98e531..f8afc4e 100644
@@ -404,7 +404,7 @@ static uint64_t uart_read(void *opaque, target_phys_addr_t offset,
     uint32_t c = 0;
 
     offset >>= 2;
-    if (offset > R_MAX) {
+    if (offset >= R_MAX) {
         return 0;
     } else if (offset == R_TX_RX) {
         uart_read_rx_fifo(s, &c);
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 5/14 lm4549: Fix buffer overflow

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

Report from smatch:
lm4549.c:234 lm4549_write_samples(14) error:
buffer overflow 's->buffer' 1024 <= 1024

There must be enough space to add two entries starting with index s->buffer_level, therefore the old check was wrong.

[Peter Maydell <[email protected]> clarifies the nature of the analyser warning:

I don't object to making the change to placate the analyser, but I don't think this is actually a buffer overrun. We always add and remove samples from the buffer two at a time, so it's not possible to get here with s->buffer_level == BUFFER_SIZE-1 (which is the only case where the old and new conditions give different answers).]

---
 hw/lm4549.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/lm4549.c +1 -1
index 80b3ec4..e0137d5 100644
@@ -224,7 +224,7 @@ uint32_t lm4549_write_samples(lm4549_state *s, uint32_t left, uint32_t right)
        This model supports 16-bit playback.
     */
 
-    if (s->buffer_level >= LM4549_BUFFER_SIZE) {
+    if (s->buffer_level > LM4549_BUFFER_SIZE - 2) {
         DPRINTF("write_sample Buffer full\n");
         return 0;
     }
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 6/14 ioh3420: Remove unreachable code

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

Report from smatch:
hw/ioh3420.c:128 ioh3420_initfn(35) info: ignoring unreachable code.

---
 hw/ioh3420.c |    1 -
 1 file changed, 1 deletion(-)
hw/ioh3420.c +0 -1
index 94a537c..4d31473 100644
@@ -125,7 +125,6 @@ static int ioh3420_initfn(PCIDevice *d)
     rc = pcie_chassis_add_slot(s);
     if (rc < 0) {
         goto err_pcie_cap;
-        return rc;
     }
     pcie_cap_root_init(d);
     rc = pcie_aer_init(d, IOH_EP_AER_OFFSET);
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 7/14 pflash_cfi01: Fix warning caused by unreachable code

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

Report from smatch:
hw/pflash_cfi01.c:431 pflash_write(180) info: ignoring unreachable code.

Instead of removing the return statement after the switch statement, the patch replaces the return statements in the switch statement by break statements. Other switch statements in the same code do it also like that.

---
 hw/pflash_cfi01.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/pflash_cfi01.c +4 -4
index 9c42d31..855890d 100644
@@ -321,7 +321,7 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,
         }
         pfl->wcycle++;
         pfl->cmd = cmd;
-        return;
+        break;
     case 1:
         switch (pfl->cmd) {
         case 0x10: /* Single Byte Program */
@@ -376,7 +376,7 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,
         default:
             goto error_flash;
         }
-        return;
+        break;
     case 2:
         switch (pfl->cmd) {
         case 0xe8: /* Block write */
@@ -407,7 +407,7 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,
         default:
             goto error_flash;
         }
-        return;
+        break;
     case 3: /* Confirm mode */
         switch (pfl->cmd) {
         case 0xe8: /* Block write */
@@ -423,7 +423,7 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,
         default:
             goto error_flash;
         }
-        return;
+        break;
     default:
         /* Should never happen */
         DPRINTF("%s: invalid write state\n",  __func__);
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH 8/14 dtrace backend: add function to reserved words

In reply to Stefan Hajnoczi

From: Alon Levy <[email protected]>

---
 scripts/tracetool/backend/dtrace.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/tracetool/backend/dtrace.py +1 -1
index 9cab75c..6be7047 100644
@@ -87,7 +87,7 @@ def stap(events):
         if len(e.args) > 0:
             for name in e.args.names():
                 # Append underscore to reserved keywords
-                if name in ('limit', 'in', 'next', 'self'):
+                if name in ('limit', 'in', 'next', 'self', 'function'):
                     name += '_'
                 out('  %s = $arg%d;' % (name, i))
                 i += 1
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 9/14 curses: don't initialize curses when qemu is daemonized

In reply to Stefan Hajnoczi

From: Hitoshi Mitake <[email protected]>

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() isn't called and the problem is avoided.

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal.

Cc Andrzej Zaborowski <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Anthony Liguori <[email protected]>
Cc Michael Roth <[email protected]>
---
 os-posix.c      |    5 +++++
 qemu-os-posix.h |    2 ++
 qemu-os-win32.h |    5 +++++
 vl.c            |    4 +++-
 4 files changed, 15 insertions(+), 1 deletion(-)
os-posix.c +5 -0
index 79fa228..eabccb8 100644
@@ -360,3 +360,8 @@ int qemu_create_pidfile(const char *filename)
     /* keep pidfile open & locked forever */
     return 0;
 }
+
+bool is_daemonized(void)
+{
+    return daemonize;
+}
qemu-os-posix.h +2 -0
index 8e1149d..7f198e4 100644
@@ -46,4 +46,6 @@ typedef struct timeval qemu_timeval;
 typedef struct timespec qemu_timespec;
 int qemu_utimens(const char *path, const qemu_timespec *times);
 
+bool is_daemonized(void);
+
 #endif
qemu-os-win32.h +5 -0
index 753679b..b3e451b 100644
@@ -86,4 +86,9 @@ typedef struct {
 } qemu_timeval;
 int qemu_gettimeofday(qemu_timeval *tp);
 
+static inline bool is_daemonized(void)
+{
+    return false;
+}
+
 #endif
vl.c +3 -1
index 7c577fa..48049ef 100644
@@ -3657,7 +3657,9 @@ int main(int argc, char **argv, char **envp)
         break;
 #if defined(CONFIG_CURSES)
     case DT_CURSES:
-        curses_display_init(ds, full_screen);
+        if (!is_daemonized()) {
+            curses_display_init(ds, full_screen);
+        }
         break;
 #endif
 #if defined(CONFIG_SDL)
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH 10/14 TextConsole: saturate escape parameter in TTY_STATE_CSI

In reply to Stefan Hajnoczi

From: Laszlo Ersek <[email protected]>

---
 console.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
console.c +5 -2
index a8bcc42..3f3d254 100644
@@ -938,8 +938,11 @@ static void console_putchar(TextConsole *s, int ch)
     case TTY_STATE_CSI: /* handle escape sequence parameters */
         if (ch >= '0' && ch <= '9') {
             if (s->nb_esc_params < MAX_ESC_PARAMS) {
-                s->esc_params[s->nb_esc_params] =
-                    s->esc_params[s->nb_esc_params] * 10 + ch - '0';
+                int *param = &s->esc_params[s->nb_esc_params];
+                int digit = (ch - '0');
+
+                *param = (*param <= (INT_MAX - digit) / 10) ?
+                         *param * 10 + digit : INT_MAX;
             }
         } else {
             if (s->nb_esc_params < MAX_ESC_PARAMS)
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 11/14 qemu-timer: simplify qemu_run_timers

In reply to Stefan Hajnoczi

From: Paolo Bonzini <[email protected]>

ptimer_head is an invariant pointer to clock->active_timers. Remove it, and just reference clock->active_timers directly.

---
 qemu-timer.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
qemu-timer.c +3 -4
index c7a1551..908a103 100644
@@ -372,21 +372,20 @@ bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)
 
 void qemu_run_timers(QEMUClock *clock)
 {
-    QEMUTimer **ptimer_head, *ts;
+    QEMUTimer *ts;
     int64_t current_time;
    
     if (!clock->enabled)
         return;
 
     current_time = qemu_get_clock_ns(clock);
-    ptimer_head = &clock->active_timers;
     for(;;) {
-        ts = *ptimer_head;
+        ts = clock->active_timers;
         if (!qemu_timer_expired_ns(ts, current_time)) {
             break;
         }
         /* remove timer from the list before calling the callback */
-        *ptimer_head = ts->next;
+        clock->active_timers = ts->next;
         ts->next = NULL;
 
         /* run the callback (the timer list can be modified) */
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH 12/14 linux-user: Remove redundant null check and replace free by g_free

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

Report from smatch:

linux-user/syscall.c:3632 do_ioctl_dm(220) info:
redundant null check on big_buf calling free()

'big_buf' was allocated by g_malloc0, therefore free was also replaced by g_free.

---
 linux-user/syscall.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
linux-user/syscall.c +1 -3
index 6257a04..471d060 100644
@@ -3628,9 +3628,7 @@ static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
         unlock_user(argptr, arg, target_size);
     }
 out:
-    if (big_buf) {
-        free(big_buf);
-    }
+    g_free(big_buf);
     return ret;
 }
 
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH 13/14 net/socket: Fix compiler warning (regression for MinGW)

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

Commit 213fd5087e2e4e2da10ad266df0ba950cf7618bf removed a type cast which is needed for MinGW:

net/socket.c:136: warning:
pointer targets in passing argument 2 of ‘sendto’ differ in signedness
/usr/lib/gcc/amd64-mingw32msvc/4.4.4/../../../../amd64-mingw32msvc/include/winsock2.h:1313: note:
expected ‘const char *’ but argument is of type ‘const uint8_t *’

Add a 'qemu_sendto' macro which provides that type cast where needed and use the new macro instead of 'sendto'.

---
 net/socket.c  |    6 +++---
 qemu-common.h |    5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)
net/socket.c +3 -3
index 5e0c92e..f3d7878 100644
@@ -131,9 +131,9 @@ static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf,
     ssize_t ret;
 
     do {
-        ret = sendto(s->fd, buf, size, 0,
-                     (struct sockaddr *)&s->dgram_dst,
-                     sizeof(s->dgram_dst));
+        ret = qemu_sendto(s->fd, buf, size, 0,
+                          (struct sockaddr *)&s->dgram_dst,
+                          sizeof(s->dgram_dst));
     } while (ret == -1 && errno == EINTR);
 
     if (ret == -1 && errno == EAGAIN) {
qemu-common.h +5 -0
index e5c2bcd..15d9e4e 100644
@@ -223,9 +223,14 @@ int qemu_pipe(int pipefd[2]);
 #endif
 
 #ifdef _WIN32
+/* MinGW needs a type cast for the 'buf' argument. */
 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
+#define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
+    sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen)
 #else
 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
+#define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
+    sendto(sockfd, buf, len, flags, destaddr, addrlen)
 #endif
 
 /* Error handling.  */
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH 14/14 w32: Always use standard instead of native format strings

In reply to Stefan Hajnoczi

From: Stefan Weil <[email protected]>

GLib 2.0 include files use __printf__ for the format attribute which resolves to native format strings on w32 hosts.

QEMU wants standard format strings instead of native format strings, so we simply change any declaration with __printf__ to use __gnu_printf__.

This works because all basic printf functions support both kinds of format strings.

This fixes a compiler warning:

qapi/string-output-visitor.c: In function ‘print_type_int’:
qapi/string-output-visitor.c:34:5: warning: unknown conversion type character ‘l’ in format [-Wformat] qapi/string-output-visitor.c:34:5: warning: too many arguments for format [-Wformat-extra-args]

---
 compiler.h |    5 +++++
 1 file changed, 5 insertions(+)
compiler.h +5 -0
index 07ba1f8..c734a71 100644
@@ -44,6 +44,11 @@
    /* Use gnu_printf when supported (qemu uses standard format strings). */
 #  define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
 #  define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
+#  if defined(_WIN32)
+    /* Map __printf__ to __gnu_printf__ because we want standard format strings
+     * even when MinGW or GLib include files use __printf__. */
+#   define __printf__ __gnu_printf__
+#  endif
 # endif
 #if defined(_WIN32)
 #define GCC_WEAK __attribute__((weak))
Signature · 1 line
1.7.10.4
#15 lore raw
In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi

The following changes since commit 93b6599734f81328ee3d608f57667742cafeea72:

audio: Fix warning from static code analysis (2012-09-23 01:34:16 +0400)

are available in the git repository at:

git://github.com/stefanha/qemu.git trivial-patches

Pulled. Thanks.

Regards,

Anthony Liguori

Quoted 53 lines

for you to fetch changes up to 95df51a4a02a853af8828c281bce2d4f2a41d6fd:

w32: Always use standard instead of native format strings (2012-09-23 07:39:22 +0100)

----------------------------------------------------------------
Alon Levy (1):
dtrace backend: add function to reserved words

Don Slutz (1):
target-i386: Allow tsc-frequency to be larger then 2.147G

Hitoshi Mitake (1):
curses: don't initialize curses when qemu is daemonized

Laszlo Ersek (1):
TextConsole: saturate escape parameter in TTY_STATE_CSI

Paolo Bonzini (1):
qemu-timer: simplify qemu_run_timers

Stefan Weil (9):
qemu-ga: Remove unreachable code after g_error
qemu-sockets: Fix potential memory leak
cadence_uart: Fix buffer overflow
lm4549: Fix buffer overflow
ioh3420: Remove unreachable code
pflash_cfi01: Fix warning caused by unreachable code
linux-user: Remove redundant null check and replace free by g_free net/socket: Fix compiler warning (regression for MinGW)
w32: Always use standard instead of native format strings

 compiler.h                          |    5 +++++
 console.c                           |    7 +++++--
 hw/cadence_uart.c                   |    2 +-
 hw/ioh3420.c                        |    1 -
 hw/lm4549.c                         |    2 +-
 hw/pflash_cfi01.c                   |    8 ++++----
 linux-user/syscall.c                |    4 +---
 net/socket.c                        |    6 +++---
 os-posix.c                          |    5 +++++
 qemu-common.h                       |    5 +++++
 qemu-ga.c                           |    2 --
 qemu-os-posix.h                     |    2 ++
 qemu-os-win32.h                     |    5 +++++
 qemu-sockets.c                      |    2 +-
 qemu-timer.c                        |    7 +++----
 scripts/tracetool/backend/dtrace.py |    2 +-
 target-i386/cpu.c                   |    2 +-
 vl.c                                |    4 +++-
 18 files changed, 46 insertions(+), 25 deletions(-)
Signature · 1 line
1.7.10.4