From f52072b06da761c05dcb636dd1a02dea7214174a Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Sun, 16 May 2021 16:21:43 +0200 Subject: [PATCH] extres: regulator: Fix regulator_status for already enable regulators If a regulator hasn't been enable by a driver but is enabled in hardware (most likely enabled by U-Boot), regulator_status will returns that it is enabled and so any call to regulator_disable will panic as it wasn't enabled by one of our drivers. Sponsored by: Diablotin Systems Differential Revision: https://reviews.freebsd.org/D30293 --- sys/dev/extres/regulator/regulator.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/dev/extres/regulator/regulator.c b/sys/dev/extres/regulator/regulator.c index 63b7d116f41..eab79e9dfbc 100644 --- a/sys/dev/extres/regulator/regulator.c +++ b/sys/dev/extres/regulator/regulator.c @@ -985,6 +985,10 @@ regulator_status(regulator_t reg, int *status) KASSERT(regnode->ref_cnt > 0, ("Attempt to access unreferenced regulator: %s\n", regnode->name)); + if (reg->enable_cnt == 0) { + *status = 0; + return (0); + } REG_TOPO_SLOCK(); rv = regnode_status(regnode, status); REG_TOPO_UNLOCK();