linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Osama Abdelkader <osama.abdelkader@gmail.com>
Cc: Oliver Upton <oupton@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: arm64: vgic: add default case to switch statement
Date: Fri, 12 Dec 2025 09:28:33 +0000	[thread overview]
Message-ID: <86qzt0nj5q.wl-maz@kernel.org> (raw)
In-Reply-To: <20251211224033.18079-1-osama.abdelkader@gmail.com>

On Thu, 11 Dec 2025 22:40:28 +0000,
Osama Abdelkader <osama.abdelkader@gmail.com> wrote:
> 
> The switch statement in vgic_validate_injection() handles all enum
> values for irq->config, but lacked a default case. Add one to match
> the pattern used in other switch statements in the same file and make

News flash: there is no other switch statement in this file. This is
the only one.

> the defensive return explicit.

I'd suggest you read the code more carefully, and consider the
following observations:

enum vgic_irq_config {
	VGIC_CONFIG_EDGE = 0,
	VGIC_CONFIG_LEVEL
};

struct vgic_irq {
	[...]
	enum vgic_irq_config config:1;	/* Level or edge */
	[...]
};

With these two definitions in mind, let's revisit the function you are
patching:

static bool vgic_validate_injection(struct vgic_irq *irq, bool level, void *owner)
{
	[...]

	switch (irq->config) {
	case VGIC_CONFIG_LEVEL:
		return irq->line_level != level;
	case VGIC_CONFIG_EDGE:
		return level;
	}

	return false;
}

Please explain how it is possible that the switch does not cover
*exhaustively* all the possible values that are constraint to exactly
One. Single. Bit? How adding a default case makes things better? The
compiler already knows that we are covering all the possible values of
the enum (yes, even a C compiler can achieve that), so it can *prove*
that there is no need for a default.

If anything, I'd have expected a patch dropping the last return, as it
is remarkably pointless. But just moving it? What does it change?

I'd suggest you think a bit more before posting random patches and
wasting people's time. I spent a good 15 minutes writing this, which
you could have used yourself to realise this change is pointless.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.


      reply	other threads:[~2025-12-12  9:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 22:40 [PATCH] KVM: arm64: vgic: add default case to switch statement Osama Abdelkader
2025-12-12  9:28 ` Marc Zyngier [this message]

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=86qzt0nj5q.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=osama.abdelkader@gmail.com \
    --cc=oupton@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).