linux - 如何使用 devm_regulator_get 处理错误
问题描述
我正在尝试处理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 。
推荐阅读
- contacts - 雅虎是否停止了他们的联系人 API?
- javascript - 请向我解释一下回调函数,就像我 5 岁一样
- java - 如何从 Spring Batch Step 访问执行上下文?错误:没有可用于作业范围的上下文持有者
- python - Python 桌面应用程序 - 在 OAuth2 PKCE 流程中关闭浏览器
- python - PyCharm 没有启动
- jmeter - Jmeter oracle连接问题
- c# - AspNet Dotnet Core API 调用 Get 带参数
- build - 如何解析管道脚本中的人工触发器输出?
- authentication - 一个生产 IIS 服务器询问凭据,其他服务器完全接受 Windows 身份验证
- jenkins - Jenkins 管道无法在 pod 中执行 docker 命令