gpt4 book ai didi

linux - 如何使用 devm_regulator_get 处理错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:34:49 31 4
gpt4 key购买 nike

我正在尝试处理 devm_regulator_get 找不到匹配调节器的情况。我在内核 4.9.30 上编程

从 linux 内核源代码中我们可以看到以下描述 [ drivers/regulator/devres.c/drivers/regulator/core.c ]

drivers/regulator/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);

drivers/regulator/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。

关于linux - 如何使用 devm_regulator_get 处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50745249/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com