mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-05-05 20:56:12 +02:00
power: regulator: Consistently return -ENOSYS when ops is unimplemented
dev_get_driver_ops() may return NULL when the udevice is invalid. Move the ops check to top of functions to consistently return -ENOSYS when ops is unimplemented and prevent trying to access uclass plat data, also add missing NULL checks to suspend ops. Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
This commit is contained in:
parent
f417c14d88
commit
4386ab9118
@ -55,6 +55,9 @@ int regulator_set_value(struct udevice *dev, int uV)
|
||||
struct dm_regulator_uclass_plat *uc_pdata;
|
||||
int ret, old_uV = uV, is_enabled = 0;
|
||||
|
||||
if (!ops || !ops->set_value)
|
||||
return -ENOSYS;
|
||||
|
||||
uc_pdata = dev_get_uclass_plat(dev);
|
||||
if (uc_pdata->min_uV != -ENODATA && uV < uc_pdata->min_uV)
|
||||
return -EINVAL;
|
||||
@ -63,9 +66,6 @@ int regulator_set_value(struct udevice *dev, int uV)
|
||||
if (uV == -ENODATA)
|
||||
return -EINVAL;
|
||||
|
||||
if (!ops || !ops->set_value)
|
||||
return -ENOSYS;
|
||||
|
||||
if (uc_pdata->ramp_delay) {
|
||||
is_enabled = regulator_get_enable(dev);
|
||||
old_uV = regulator_get_value(dev);
|
||||
@ -87,6 +87,9 @@ int regulator_set_suspend_value(struct udevice *dev, int uV)
|
||||
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||
struct dm_regulator_uclass_plat *uc_pdata;
|
||||
|
||||
if (!ops || !ops->set_suspend_value)
|
||||
return -ENOSYS;
|
||||
|
||||
uc_pdata = dev_get_uclass_plat(dev);
|
||||
if (uc_pdata->min_uV != -ENODATA && uV < uc_pdata->min_uV)
|
||||
return -EINVAL;
|
||||
@ -95,9 +98,6 @@ int regulator_set_suspend_value(struct udevice *dev, int uV)
|
||||
if (uV == -ENODATA)
|
||||
return -EINVAL;
|
||||
|
||||
if (!ops->set_suspend_value)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->set_suspend_value(dev, uV);
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ int regulator_get_suspend_value(struct udevice *dev)
|
||||
{
|
||||
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops->get_suspend_value)
|
||||
if (!ops || !ops->get_suspend_value)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->get_suspend_value(dev);
|
||||
@ -140,6 +140,9 @@ int regulator_set_current(struct udevice *dev, int uA)
|
||||
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||
struct dm_regulator_uclass_plat *uc_pdata;
|
||||
|
||||
if (!ops || !ops->set_current)
|
||||
return -ENOSYS;
|
||||
|
||||
uc_pdata = dev_get_uclass_plat(dev);
|
||||
if (uc_pdata->min_uA != -ENODATA && uA < uc_pdata->min_uA)
|
||||
return -EINVAL;
|
||||
@ -148,9 +151,6 @@ int regulator_set_current(struct udevice *dev, int uA)
|
||||
if (uA == -ENODATA)
|
||||
return -EINVAL;
|
||||
|
||||
if (!ops || !ops->set_current)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->set_current(dev, uA);
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ int regulator_set_suspend_enable(struct udevice *dev, bool enable)
|
||||
{
|
||||
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops->set_suspend_enable)
|
||||
if (!ops || !ops->set_suspend_enable)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->set_suspend_enable(dev, enable);
|
||||
@ -226,7 +226,7 @@ int regulator_get_suspend_enable(struct udevice *dev)
|
||||
{
|
||||
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops->get_suspend_enable)
|
||||
if (!ops || !ops->get_suspend_enable)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->get_suspend_enable(dev);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user