public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Klaus Jensen <its@irrelevant.dk>
To: Han Zhang <ihanzhzh@gmail.com>
Cc: qemu-devel@nongnu.org, kbusch@kernel.org, foss@defmacro.it,
	qemu-block@nongnu.org, Han Zhang <ihanzh@outlook.com>
Subject: Re: [PATCH] hw/nvme: remove unreachable default cases in nvme_directive_receive()
Date: Mon, 23 Mar 2026 12:38:24 +0100	[thread overview]
Message-ID: <acEmMFBXkcgGLtGo@AALNPWKJENSEN.aal.scsc.local> (raw)
In-Reply-To: <20260317010721.232247-1-ihanzh@outlook.com>

[-- Attachment #1: Type: text/plain, Size: 2281 bytes --]

On Mar 17 09:07, Han Zhang wrote:
> Static analysis reported that the default cases in the switch
> statements handling dtype and doper in nvme_directive_receive()
> are unreachable.
> 
> The values of dtype and doper are already validated earlier in the
> function, making the default branches redundant.
> 
> Remove the unreachable cases to simplify the control flow.
> 
> Reported-by: Ekaterina Zilotina
> Fixes: https://gitlab.com/qemu-project/qemu/-/issues/2472
> Signed-off-by: Han Zhang <ihanzh@outlook.com>
> ---
>  hw/nvme/ctrl.c | 24 ++++++------------------
>  1 file changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index cc4593cd42..36df6eeca2 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -7550,25 +7550,13 @@ static uint16_t nvme_directive_receive(NvmeCtrl *n, NvmeRequest *req)
>          return NVME_INVALID_FIELD | NVME_DNR;
>      }
>  
> -    switch (dtype) {
> -    case NVME_DIRECTIVE_IDENTIFY:
> -        switch (doper) {
> -        case NVME_DIRECTIVE_RETURN_PARAMS:
> -            if (ns->endgrp && ns->endgrp->fdp.enabled) {
> -                id.supported |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
> -                id.enabled |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
> -                id.persistent |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
> -            }
> -
> -            return nvme_c2h(n, (uint8_t *)&id, trans_len, req);
> -
> -        default:
> -            return NVME_INVALID_FIELD | NVME_DNR;
> -        }
> -
> -    default:
> -        return NVME_INVALID_FIELD;
> +    if (ns->endgrp && ns->endgrp->fdp.enabled) {
> +        id.supported |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
> +        id.enabled |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
> +        id.persistent |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
>      }
> +
> +    return nvme_c2h(n, (uint8_t *)&id, trans_len, req);
>  }
>  
>  static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeRequest *req)
> -- 
> 2.34.1
> 
> 

I'd rather keep the switches there and drop the early checks. The
switches are good documentation for what's going on. Removing them makes
the code a little "what, is this correct?".

If you update that, I'll be happy to grab this :)


Thanks,
Klaus

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-03-23 11:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17  1:07 [PATCH] hw/nvme: remove unreachable default cases in nvme_directive_receive() Han Zhang
2026-03-23 11:38 ` Klaus Jensen [this message]
2026-03-23 15:57 ` [PATCH v2] hw/nvme: keep switch handling " ihanzhzh

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=acEmMFBXkcgGLtGo@AALNPWKJENSEN.aal.scsc.local \
    --to=its@irrelevant.dk \
    --cc=foss@defmacro.it \
    --cc=ihanzh@outlook.com \
    --cc=ihanzhzh@gmail.com \
    --cc=kbusch@kernel.org \
    --cc=qemu-block@nongnu.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox