当devm_regulator_get
找不到匹配的调节器时,我正试图处理这个案子。我在内核4.9.30上编程
从linux内核源代码我们可以看到以下描述[drivers/regulator/devres.c / drivers/regulator/core.c]
司机/调节器/ devres.c
/**
* devm_regulator_get - Resource managed regulator_get()
* @dev: device for regulator "consumer"
* @id: Supply name or regulator ID.
*
* Managed regulator_get(). Regulators returned from this function are
* automatically regulator_put() on driver detach. See regulator_get() for more
* information.
*/
struct regulator *devm_regulator_get(struct device *dev, const char *id)
{
return _devm_regulator_get(dev, id, NORMAL_GET);
}
EXPORT_SYMBOL_GPL(devm_regulator_get);
司机/调节器/ core.c
/**
* regulator_get - lookup and obtain a reference to a regulator.
* @dev: device for regulator "consumer"
* @id: Supply name or regulator ID.
*
* Returns a struct regulator corresponding to the regulator producer,
* or IS_ERR() condition containing errno.
*
* Use of supply names configured via regulator_set_device_supply() is
* strongly encouraged. It is recommended that the supply name used
* should match the name used for the supply and/or the relevant
* device pins in the datasheet.
*/
struct regulator *regulator_get(struct device *dev, const char *id)
{
return _regulator_get(dev, id, false, true);
}
EXPORT_SYMBOL_GPL(regulator_get);
这是我的代码
struct regulator *power_regulator = devm_regulator_get(&pdev->dev, "zdfhkfgv");
if(IS_ERR(power_regulator))
{
ERROR("Invalid power regulator\r\n");
return -EINVAL;
}
然而,即使找不到调节器,我也永远不会陷入错误的情况。
这是内核输出:
# insmod mod.ko
module : Init driver
module : Device allocated and initialized
module supply zdfhkfgv not found, using dummy regulator
module : device is not powered
[...]
所以我可以看到devm_regulator_get
未能找到监管机构,但我没有陷入错误的情况。这非常令人讨厌,因为当调节器未设置时,我将返回。而不是代码继续运行与未供电的设备。
我在这做错了什么?
如果您不想依赖虚拟调节器,则应使用devm_regulator_get_optional()。然后它将返回-ENODEV。