Re: [PATCH] wifi: nl80211: drop impossible negative band check
From: Johannes Berg
Date: Wed Feb 04 2026 - 03:37:19 EST
On Wed, 2026-02-04 at 16:18 +0800, Sun Jian wrote:
> band is derived from nla_type() of a nested netlink attribute, which is
> a masked u16 value and therefore cannot be negative. Drop the dead
> "band < 0" checks and keep the upper bound validation.
I've seen this before, but I'm not really convinced it is entirely
correct. C says:
All enumerations have an underlying type. The underlying type can be
explicitly specified using an enum type specifier and is its fixed
underlying type. If it is not explicitly specified, the underlying
type is the enumeration’s compatible type, which is either char or a
standard or extended signed or unsigned integer type.
It would thus _seem_ to be possible for an enum to generally be a signed
type, and therefore a 'signed short', and therefore an nla_type() that's
a u16 could end up with a negative value...
Am I wrong?
johannes