linux/rust/kernel
Alice Ryhl 8121353a4b
rust: regulator: do not assume that regulator_get() returns non-null
The Rust `Regulator` abstraction uses `NonNull` to wrap the underlying
`struct regulator` pointer. When `CONFIG_REGULATOR` is disabled, the C
stub for `regulator_get` returns `NULL`. `from_err_ptr` does not treat
`NULL` as an error, so it was passed to `NonNull::new_unchecked`,
causing undefined behavior.

Fix this by using a raw pointer `*mut bindings::regulator` instead of
`NonNull`. This allows `inner` to be `NULL` when `CONFIG_REGULATOR` is
disabled, and leverages the C stubs which are designed to handle `NULL`
or are no-ops.

Fixes: 9b614ceada ("rust: regulator: add a bare minimum regulator abstraction")
Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://lore.kernel.org/r/20260322193830.89324-1-ojeda@kernel.org
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20260324-regulator-fix-v1-1-a5244afa3c15@google.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-03-24 13:08:21 +00:00
..
alloc
block
debugfs
device
drm
fs
io
iommu
irq
list
mm
net
num
pci
ptr
str
sync
time
.gitignore
acpi.rs
alloc.rs
auxiliary.rs
bitmap.rs
bits.rs
block.rs
bug.rs
build_assert.rs
clk.rs
configfs.rs
cpu.rs
cpufreq.rs
cpumask.rs
cred.rs
debugfs.rs
device.rs
device_id.rs
devres.rs
dma.rs
driver.rs
error.rs
faux.rs
firmware.rs
fmt.rs
fs.rs
generated_arch_reachable_asm.rs.S
generated_arch_static_branch_asm.rs.S
generated_arch_warn_asm.rs.S
i2c.rs
id_pool.rs
impl_flags.rs
init.rs
io.rs
ioctl.rs
iov.rs
irq.rs
jump_label.rs
kunit.rs
lib.rs
list.rs
maple_tree.rs
miscdevice.rs
mm.rs
module_param.rs
net.rs
num.rs
of.rs
opp.rs
page.rs
pci.rs
pid_namespace.rs
platform.rs
prelude.rs
print.rs
processor.rs
ptr.rs
pwm.rs
rbtree.rs
regulator.rs
revocable.rs
safety.rs
scatterlist.rs
security.rs
seq_file.rs
sizes.rs
slice.rs
soc.rs
static_assert.rs
std_vendor.rs
str.rs
sync.rs
task.rs
time.rs
tracepoint.rs
transmute.rs
types.rs
uaccess.rs
usb.rs
workqueue.rs
xarray.rs