bpf-devices: normalize how we pass around major/minor values
authorLennart Poettering <lennart@poettering.net>
Fri, 9 Feb 2024 11:21:26 +0000 (12:21 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 9 Feb 2024 14:32:04 +0000 (15:32 +0100)
commit893220f62ff35b6a6f4a36167bf0dbc08ea3f701
treef5aef4b2fcee80872fc3989a0dc0bcda065e4573
parentc5052754761c78b89e20d1f9c3396529dbab26de
bpf-devices: normalize how we pass around major/minor values

There's some unclarity whether major/minor of device nodes are supposed
to be "unsigned" or "dev_t". Various codebases assume the latter, but
glibc's major()/minor() types actually return a value typed to
"unsigned". On glibc dev_t is actually 64bit even if the kernel only
exposes 32bit. Hence this distinction kinda matters.

Let's clean things up a bit with handling: let's followe glibc's type
system here, and use unsigned (and not int).

Also let's pass invalid major/minor values around as UINT_MAX rather
than via pointers, to match how we usually do this, and to shorten our
code a bit. This is safe, since given the linux dev_t space being 32bit
only we can't possibly have a valid major or minor this hight, given
they must be smaller in size. While other archs disagree on the types of
major/minor, they also tend to have similar limits. In fact on FreeBSD
for example major()/minor() returns a signed int. Which would hence also
mean that UINT_MAX cannot be a valid major or minor.
src/core/bpf-devices.c