前言

今天在一个群里面看到的一个朋友提交,说of_property_read_string 这个函数有两个定义,到底是用了哪个呢?

所以这篇文章就说下这个函数。

函数引用的头文件

引用的头文件位置在

kernel-4.4includelinuxof.h

其中一个是

extern int of_property_read_string(struct device_node *np,const char *propname,const char **out_string);

还有一个是

static inline int of_property_read_string(struct device_node *np,const char *propname,const char **out_string)
{return -ENOSYS;
}

但是并不是两个都用到,他们用了一个宏 CONFIG_OF 来选择

CONFIG_OF 宏有什么用?

这个宏的解释是

Open Firmware. This was invented long time ago when Apple was producing laptops based on PowerPC CPUs. Openfirmware provides a good description of the devices connected to the platform. In Linux kernel the part that works with device data is called Device Tree (DT). More details in theUsage model.

他的作用是

Openfirmware provides a good description of the devices connected to the platform

他提供了一种更好的方式来连接设备和驱动。

他是名字是

called Device Tree (DT)

DTS,那很明显了,开了这个宏,就表示使用了DTS设备树的方式来连接设备和驱动程序。

of_property_read_string 函数本体

函数位置

"./drivers/of/base.c"

函数原型

/*** of_property_read_string - Find and read a string from a property* @np:         device node from which the property value is to be read.* @propname:   name of the property to be searched.* @out_string: pointer to null terminated return string, modified only if*              return value is 0.** Search for a property in a device tree node and retrieve a null* terminated string value (pointer to data, not a copy). Returns 0 on* success, -EINVAL if the property does not exist, -ENODATA if property* does not have a value, and -EILSEQ if the string is not null-terminated* within the length of the property data.** The out_string pointer is modified only if a valid string can be decoded.*/
int of_property_read_string(struct device_node *np, const char *propname,const char **out_string)
{struct property *prop = of_find_property(np, propname, NULL);if (!prop)return -EINVAL;if (!prop->value)return -ENODATA;if (strnlen(prop->value, prop->length) >= prop->length)return -EILSEQ;*out_string = prop->value;return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_string);

函数的作用:

返回propname对应dts节点对应的值。

使用方式:

传入np,就是设备树的节点,然后返回 "clock-output-names" 字符串对应的值,存入clk_name 里面。

of_property_read_string 函数剖析

int of_property_read_string(struct device_node *np, const char *propname,const char **out_string)
{struct property *prop = of_find_property(np, propname, NULL);if (!prop)return -EINVAL;if (!prop->value)return -ENODATA;if (strnlen(prop->value, prop->length) >= prop->length)return -EILSEQ;*out_string = prop->value;return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_string);

  • of_find_property 这个是找到这个dts节点,怎么找,可以再去这个函数分析一下。
  • strnlen功能「获取字符串实际字符个数,不包括结尾的'0';如果实际个数 <= 第二个参数,则返回字符串实际字符个数,否则返回第二个参数。」
  • prop->length 是之前预设的一个值,strnlen正常情况返回的就是字符串的长度 减1「去掉n字符」。
  • *out_string = prop->value 这里就是二级指针起到作用了,没有重新分配内存,直接把指针指向字符串位置。

我们再看看prop 的结构体,就一目了然了。

struct property {char   *name;int   length;void *value;struct property *next;unsigned long _flags;unsigned int unique_id;struct bin_attribute attr;
};

read函数头文件 window_of_property_read_string 剖析相关推荐

  1. listlength函数头文件_酷町问答 - 我们编程时,通常要用到哪些头文件,包含什么函数...

    1.常用数学函数 头文件 #include  或者 #include 函数原型 功能 返回值 int abs(int x) 求整数x的绝对值 绝对值 double acos(double x) 计算a ...

  2. c语言中常用函数头文件,c语言中常用的函数和头文件

    头文件ctype.h 函数列表 函数类别函数目的详细说明 字符测试为字符和数字的isalnum 是否为isalpha字符 是否控制字符iscntrl 是否为数字isdigit 是否能够显示文字(空格除 ...

  3. strstr函数头文件_C语言(函数)学习之strstr strcasestr

    一.strstr函数使用 [1] 函数原型 char *strstr(const char *haystack, const char *needle); [2] 头文件 #include [3] 函 ...

  4. Arduino--库函数头文件

    Arduino库函数头文件汇总(基本包含常用函数) 话不多说先上截图,具体获取链接见文末 继续 使用方法如下: 下载后解压将上述文件夹放在arduino的安装目录下libraries文件夹下即可,如下 ...

  5. linux wait函数头文件_手把手教Linux驱动9-等待队列waitq

    在上一篇<手把手教Linux驱动8-Linux IO模型>我们已经了解了阻塞.非阻塞.同步和异步等相关概念,本文主要讲解如何通过等待队列实现对进程的阻塞. 应用场景: 当进程要获取某些资源 ...

  6. 函数头文件php_PHP 7.4 的 FFI 将支持更好地在 PHP 中使用 C 函数/数据结构

    即将在下月底发布的 PHP 7.4 将会引入一个有趣的新功能,那就是期待已久的对 FFI(外部函数接口,Foreign Function Interface)的支持.此功能使得开发者可以在原生 PHP ...

  7. linux wait函数头文件_第五十八章、linux中的3种正常结束进程的方式你都了解么...

    在前两章中我们了解了创建进程,这一章我们来了解下,在linux下怎么结束进程. 在linux中,有3种正常结束进程的方法和2种异常终止的方法: 1. 正常结束: a. 在main函数中调用return ...

  8. c语言binsearch函数头文件,C++ binary_search()函数详解

    binary_search()函数定义在头文件中,用于查找指定区域内是否包含某个目标元素. 该函数有 2 种语法格式,分别为: //查找 [first, last) 区域内是否包含 val bool ...

  9. C++常用头文件——常用数学函数头文件

    cmath头文件 cmath是c++语言中的标准库头文件.其中的 "c" 表示其中的函数是来自 C标准库,"math"表示为数学常用库函数.此文件原作为< ...

最新文章

  1. 转:.Net 中的反射(反射特性) - Part.3
  2. Java锁详解:“独享锁/共享锁+公平锁/非公平锁+乐观锁/悲观锁+线程锁”
  3. SpringBoot 自定义Kafka消息序列化和反序列化
  4. 德云斗笑社何九华为什么没参加_江西省会为什么是南昌?
  5. 项目管理系列之质量管理
  6. swift 可变參数
  7. 多麦克风做拾音的波束_麦克风丨人声应该用动圈话筒还是电容话筒?
  8. 文本预处理之判断是否包含非法字符或非英文字符(Java)
  9. 人脸方向学习(七):Face Recognition-CosFace 解读
  10. 2021-09-07912. 排序数组
  11. ubuntu硬盘装机_配置系统总结
  12. 怎么使用手机号申请邮箱,注册移动手机邮箱有哪些步骤?
  13. 如何在生化实验中选择合适的牛血清白蛋白(BSA)?
  14. 鸿蒙系统深度解读(三)
  15. 多传感器时频信号处理:多通道非平稳数据的分析工具(Matlab代码实现)
  16. linux 笔记实录(1)
  17. 解决jrebe-JVMTI[FATAL] Couldnt write to C:\Users\启动报错
  18. C#实现拉格朗日、牛顿、Hermite插值
  19. 勇闯掘金小游戏为一款多个小游戏的合集游戏,有五个关卡:找掘金、石头剪刀布、寻找藏宝图、打地鼠、抽奖。基于Vue
  20. PSINS中19维组合导航模块sinsgps详解(滤波部分)

热门文章

  1. 嵌入式linux 配置usb otg,嵌入式linux系统环境下USB设备的驱动实现
  2. centos mysql_CentOS MySQL数据库备份工具mysqldump介绍
  3. Dubbo常见面试题与答案
  4. php oracle 操作 sql语句中能不能添加数组_如何在PHP中使用Oracle数据库_php
  5. fft之后求模值和相位_如何利用相位噪声测量表征时钟抖动来加速设计验证过程...
  6. python matpoltlib绘制动态图_使用Python、Geopandas和Matplotlib制作gif动态
  7. python的django项目中怎么添加app_django下如何创建多个app并设置urls
  8. c语言成绩管理系统开题报告,学生信息管理系统,开题报告(共篇).doc
  9. HTML+CSS+JS实现 ❤️6种transform图片悬停动态效果❤️
  10. linux为已有磁盘扩容 kvm,KVM虚拟磁盘扩容