gpt4 book ai didi

linux-kernel - 为什么检查 debugfs api 的 -ENODEV 是不明智的

转载 作者:行者123 更新时间:2023-12-01 23:43:44 30 4
gpt4 key购买 nike

debugfs api 例如debugfs_create_dir

If debugfs is not enabled in the kernel, the value -ENODEV will be returned. It is not wise to check for this value, but rather, check for NULL or !NULL instead as to eliminate the need for #ifdef in the calling code.

但为什么不明智呢?你能给我一些关于消除调用代码中#ifdef 的需要的例子吗?

最佳答案

人们可能会将 -ENODEV 解释为成功,直到使用 dentry 返回一些东西,除了删除它 (debugfs_remove) 并将它用作另一个文件的目录 (debugfs_create_-family ).当 CONFIG_DEBUG_FS 被禁用时,所有这些功能都会正确处理案例。

这就是为什么只检查 NULL 或 !NULL 就足够了。

在极少数情况下,当 debugfs_create_*() 返回的 dentry 被显式引用时(例如,为了访问 inode 的私有(private)数据),检查就足够了,只有第一个这样的调用不返回 -ENODEV。

关于linux-kernel - 为什么检查 debugfs api 的 -ENODEV 是不明智的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30119167/

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