All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim MacArthur <jim.macarthur@linaro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v2 2/6] virtio-snd: add pcm_state_to_str()
Date: Wed, 11 Nov 2026 10:47:02 +0000	[thread overview]
Message-ID: <avRHpir8yFEA5QkA@linaro.org> (raw)
In-Reply-To: <20261110-virtio-snd-fixes-v2-2-d5b654217676@linaro.org>

On Tue, Nov 10, 2026 at 02:39:31PM +0200, Manos Pitsidianakis wrote:
> Add macro to print the stream state in a human-understandable state,
> since this is an internal enum and one would have to inspect the source
> code to understand what a e.g. "2" state means in an error message.
> 
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
>  hw/audio/virtio-snd.c | 49 +++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 39 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
> index bed36203f2..f1dc03d1b8 100644
> --- a/hw/audio/virtio-snd.c
> +++ b/hw/audio/virtio-snd.c
> @@ -38,6 +38,26 @@ typedef enum virtio_snd_pcm_state {
>      VIRTIO_SND_PCM_STATE_RELEASED,
>  } virtio_snd_pcm_state;
>  
> +static inline const char *pcm_state_to_str(virtio_snd_pcm_state s)
> +{
> +    switch (s) {
> +    case VIRTIO_SND_PCM_STATE_UNINIT:
> +        return "UNINIT";
> +    case VIRTIO_SND_PCM_STATE_PARAMS_SET:
> +        return "PARAMS_SET";
> +    case VIRTIO_SND_PCM_STATE_PREPARED:
> +        return "PREPARED";
> +    case VIRTIO_SND_PCM_STATE_STARTED:
> +        return "STARTED";
> +    case VIRTIO_SND_PCM_STATE_STOPPED:
> +        return "STOPPED";
> +    case VIRTIO_SND_PCM_STATE_RELEASED:
> +        return "RELEASED";
> +    default:
> +        return "invalid";
> +    }
> +}
> +
>  static inline bool virtio_snd_pcm_state_prepared(virtio_snd_pcm_state s)
>  {
>      return s > VIRTIO_SND_PCM_STATE_PARAMS_SET &&
> @@ -310,8 +330,10 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,
>      case VIRTIO_SND_PCM_STATE_RELEASED:
>          break;
>      default:
> -        error_report("%s unexpected stream state in %s: %"PRIu32,
> -                     VIRTIO_DEVICE(s)->name, __func__, stream->state);
> +        error_report("%s unexpected stream state in %s: "
> +                     "%s (%"PRIu32")", VIRTIO_DEVICE(s)->name,
> +                     __func__, pcm_state_to_str(stream->state),
> +                     stream->state);
>          return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>      }
>  
> @@ -535,8 +557,10 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
>      case VIRTIO_SND_PCM_STATE_RELEASED:
>          break;
>      default:
> -        error_report("%s unexpected stream state in %s: %"PRIu32,
> -                     VIRTIO_DEVICE(s)->name, __func__, stream->state);
> +        error_report("%s unexpected stream state in %s: "
> +                     "%s (%"PRIu32")", VIRTIO_DEVICE(s)->name,
> +                     __func__, pcm_state_to_str(stream->state),
> +                     stream->state);
>          return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>      }
>  
> @@ -624,8 +648,10 @@ static uint32_t virtio_snd_pcm_start_stop(VirtIOSound *s,
>          case VIRTIO_SND_PCM_STATE_STOPPED:
>              break;
>          default:
> -            error_report("%s unexpected stream state in %s start: %"PRIu32,
> -                         VIRTIO_DEVICE(s)->name, __func__, stream->state);
> +            error_report("%s unexpected stream state in %s start: "
> +                         "%s (%"PRIu32")", VIRTIO_DEVICE(s)->name,
> +                         __func__, pcm_state_to_str(stream->state),
> +                         stream->state);
>              return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>          }
>  
> @@ -635,8 +661,9 @@ static uint32_t virtio_snd_pcm_start_stop(VirtIOSound *s,
>          case VIRTIO_SND_PCM_STATE_STARTED:
>              break;
>          default:
> -            error_report("%s unexpected stream state in %s stop: %"PRIu32,
> -                         VIRTIO_DEVICE(s)->name, __func__,
> +            error_report("%s unexpected stream state in %s stop: "
> +                         "%s (%"PRIu32")", VIRTIO_DEVICE(s)->name,
> +                         __func__, pcm_state_to_str(stream->state),
>                           stream->state);
>              return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>          }
> @@ -736,8 +763,10 @@ static void virtio_snd_handle_pcm_release(VirtIOSound *s,
>      case VIRTIO_SND_PCM_STATE_STOPPED:
>          break;
>      default:
> -        error_report("%s unexpected stream state in %s: %"PRIu32,
> -                     VIRTIO_DEVICE(s)->name, __func__, stream->state);
> +        error_report("%s unexpected stream state in %s: "
> +                     "%s (%"PRIu32")", VIRTIO_DEVICE(s)->name,
> +                     __func__, pcm_state_to_str(stream->state),
> +                     stream->state);
>          cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>          return;
>      }
> 

Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org>


  reply	other threads:[~2026-11-11 10:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 12:39 [PATCH v2 0/6] Various virtio-snd fixes again Manos Pitsidianakis
2026-11-10 12:39 ` [PATCH v2 1/6] virtio-snd: convert virtio_error to error_report Manos Pitsidianakis
2026-11-11 10:46   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 2/6] virtio-snd: add pcm_state_to_str() Manos Pitsidianakis
2026-11-11 10:47   ` Jim MacArthur [this message]
2026-11-10 12:39 ` [PATCH v2 3/6] virtio-snd: reject invalid feats in set_pcm_params Manos Pitsidianakis
2026-11-11 10:47   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 4/6] virtio-snd: don't allocate pcm_info zero-count buf Manos Pitsidianakis
2026-11-11 10:47   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 5/6] virtio-snd: cap maximum buffer_bytes to half a GiB Manos Pitsidianakis
2026-11-11 10:48   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 6/6] virtio-snd: period_bytes divides buffer_bytes Manos Pitsidianakis
2026-11-11 10:48   ` Jim MacArthur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avRHpir8yFEA5QkA@linaro.org \
    --to=jim.macarthur@linaro.org \
    --cc=kraxel@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.