All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/2] qemu-sparc queue 20210207
@ 2021-02-07 22:29 Mark Cave-Ayland
  2021-02-07 22:29 ` [PULL 1/2] utils/fifo8: change fatal errors from abort() to assert() Mark Cave-Ayland
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mark Cave-Ayland @ 2021-02-07 22:29 UTC (permalink / raw)
  To: qemu-devel, peter.maydell

The following changes since commit 5b19cb63d9dfda41b412373b8c9fe14641bcab60:

  Merge remote-tracking branch 'remotes/rth-gitlab/tags/pull-tcg-20210205' into staging (2021-02-05 22:59:12 +0000)

are available in the Git repository at:

  git://github.com/mcayland/qemu.git tags/qemu-sparc-20210207

for you to fetch changes up to cdf01ca4810203e229bcac822b42eba58e1abbf9:

  utils/fifo8: add VMSTATE_FIFO8_TEST macro (2021-02-07 20:38:34 +0000)

----------------------------------------------------------------
qemu-sparc queue

----------------------------------------------------------------
Mark Cave-Ayland (2):
      utils/fifo8: change fatal errors from abort() to assert()
      utils/fifo8: add VMSTATE_FIFO8_TEST macro

 include/qemu/fifo8.h | 16 ++++++++++------
 util/fifo8.c         | 16 ++++------------
 2 files changed, 14 insertions(+), 18 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PULL 1/2] utils/fifo8: change fatal errors from abort() to assert()
  2021-02-07 22:29 [PULL 0/2] qemu-sparc queue 20210207 Mark Cave-Ayland
@ 2021-02-07 22:29 ` Mark Cave-Ayland
  2021-02-07 22:29 ` [PULL 2/2] utils/fifo8: add VMSTATE_FIFO8_TEST macro Mark Cave-Ayland
  2021-02-08 11:10 ` [PULL 0/2] qemu-sparc queue 20210207 Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Cave-Ayland @ 2021-02-07 22:29 UTC (permalink / raw)
  To: qemu-devel, peter.maydell

Developer errors are better represented with assert() rather than abort(). Also
improve the strictness of the checks by using range checks within the assert()
rather than converting the existing equality checks to inequality checks.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20210121102518.20112-1-mark.cave-ayland@ilande.co.uk>
---
 util/fifo8.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/util/fifo8.c b/util/fifo8.c
index a5dd789ce5..d4d1c135e0 100644
--- a/util/fifo8.c
+++ b/util/fifo8.c
@@ -31,9 +31,7 @@ void fifo8_destroy(Fifo8 *fifo)
 
 void fifo8_push(Fifo8 *fifo, uint8_t data)
 {
-    if (fifo->num == fifo->capacity) {
-        abort();
-    }
+    assert(fifo->num < fifo->capacity);
     fifo->data[(fifo->head + fifo->num) % fifo->capacity] = data;
     fifo->num++;
 }
@@ -42,9 +40,7 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num)
 {
     uint32_t start, avail;
 
-    if (fifo->num + num > fifo->capacity) {
-        abort();
-    }
+    assert(fifo->num + num <= fifo->capacity);
 
     start = (fifo->head + fifo->num) % fifo->capacity;
 
@@ -63,9 +59,7 @@ uint8_t fifo8_pop(Fifo8 *fifo)
 {
     uint8_t ret;
 
-    if (fifo->num == 0) {
-        abort();
-    }
+    assert(fifo->num > 0);
     ret = fifo->data[fifo->head++];
     fifo->head %= fifo->capacity;
     fifo->num--;
@@ -76,9 +70,7 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num)
 {
     uint8_t *ret;
 
-    if (max == 0 || max > fifo->num) {
-        abort();
-    }
+    assert(max > 0 && max <= fifo->num);
     *num = MIN(fifo->capacity - fifo->head, max);
     ret = &fifo->data[fifo->head];
     fifo->head += *num;
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PULL 2/2] utils/fifo8: add VMSTATE_FIFO8_TEST macro
  2021-02-07 22:29 [PULL 0/2] qemu-sparc queue 20210207 Mark Cave-Ayland
  2021-02-07 22:29 ` [PULL 1/2] utils/fifo8: change fatal errors from abort() to assert() Mark Cave-Ayland
@ 2021-02-07 22:29 ` Mark Cave-Ayland
  2021-02-08 11:10 ` [PULL 0/2] qemu-sparc queue 20210207 Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Cave-Ayland @ 2021-02-07 22:29 UTC (permalink / raw)
  To: qemu-devel, peter.maydell

Rewrite the existing VMSTATE_FIFO8 macro to use VMSTATE_FIFO8_TEST as per the
standard pattern in include/migration/vmstate.h.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20210128221728.14887-3-mark.cave-ayland@ilande.co.uk>
---
 include/qemu/fifo8.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h
index 489c354291..28bf2cee57 100644
--- a/include/qemu/fifo8.h
+++ b/include/qemu/fifo8.h
@@ -148,12 +148,16 @@ uint32_t fifo8_num_used(Fifo8 *fifo);
 
 extern const VMStateDescription vmstate_fifo8;
 
-#define VMSTATE_FIFO8(_field, _state) {                              \
-    .name       = (stringify(_field)),                               \
-    .size       = sizeof(Fifo8),                                     \
-    .vmsd       = &vmstate_fifo8,                                    \
-    .flags      = VMS_STRUCT,                                        \
-    .offset     = vmstate_offset_value(_state, _field, Fifo8),       \
+#define VMSTATE_FIFO8_TEST(_field, _state, _test) {                  \
+    .name         = (stringify(_field)),                             \
+    .field_exists = (_test),                                         \
+    .size         = sizeof(Fifo8),                                   \
+    .vmsd         = &vmstate_fifo8,                                  \
+    .flags        = VMS_STRUCT,                                      \
+    .offset       = vmstate_offset_value(_state, _field, Fifo8),     \
 }
 
+#define VMSTATE_FIFO8(_field, _state)                                \
+    VMSTATE_FIFO8_TEST(_field, _state, NULL)
+
 #endif /* QEMU_FIFO8_H */
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PULL 0/2] qemu-sparc queue 20210207
  2021-02-07 22:29 [PULL 0/2] qemu-sparc queue 20210207 Mark Cave-Ayland
  2021-02-07 22:29 ` [PULL 1/2] utils/fifo8: change fatal errors from abort() to assert() Mark Cave-Ayland
  2021-02-07 22:29 ` [PULL 2/2] utils/fifo8: add VMSTATE_FIFO8_TEST macro Mark Cave-Ayland
@ 2021-02-08 11:10 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2021-02-08 11:10 UTC (permalink / raw)
  To: Mark Cave-Ayland; +Cc: QEMU Developers

On Sun, 7 Feb 2021 at 22:29, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> The following changes since commit 5b19cb63d9dfda41b412373b8c9fe14641bcab60:
>
>   Merge remote-tracking branch 'remotes/rth-gitlab/tags/pull-tcg-20210205' into staging (2021-02-05 22:59:12 +0000)
>
> are available in the Git repository at:
>
>   git://github.com/mcayland/qemu.git tags/qemu-sparc-20210207
>
> for you to fetch changes up to cdf01ca4810203e229bcac822b42eba58e1abbf9:
>
>   utils/fifo8: add VMSTATE_FIFO8_TEST macro (2021-02-07 20:38:34 +0000)
>
> ----------------------------------------------------------------
> qemu-sparc queue
>


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/6.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-08 17:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-07 22:29 [PULL 0/2] qemu-sparc queue 20210207 Mark Cave-Ayland
2021-02-07 22:29 ` [PULL 1/2] utils/fifo8: change fatal errors from abort() to assert() Mark Cave-Ayland
2021-02-07 22:29 ` [PULL 2/2] utils/fifo8: add VMSTATE_FIFO8_TEST macro Mark Cave-Ayland
2021-02-08 11:10 ` [PULL 0/2] qemu-sparc queue 20210207 Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.