在看《LINUX设备驱动程序》的时候书籍,实机跑scull示例

scull源码下载地址:

链接:https://pan.baidu.com/s/1pw4D5VBQqn3LMSbE2T9Z6w?pwd=1234 
提取码:1234

在编译scull驱动程序时,报如上错误,原因是scull最初适配的是2.6的内核版本,而我现在需要在5.15的内核上编译,内核代码已经发生很大的改变了。

报错代码如下:

static struct scull_dev scull_u_device;
static int scull_u_count;       /* initialized to 0 by default */
static uid_t scull_u_owner;     /* initialized to 0 by default */
static spinlock_t scull_u_lock; /* = SPIN_LOCK_UNLOCKED; */static int scull_u_open(struct inode *inode, struct file *filp) {struct scull_dev *dev = &scull_u_device; /* device information */spin_lock(&scull_u_lock);if (scull_u_count && (scull_u_owner != current->cred->uid) &&  /* allow user */(scull_u_owner != current->cred->euid) && /* allow whoever did su */!capable(CAP_DAC_OVERRIDE)) { /* still allow root */spin_unlock(&scull_u_lock);return -EBUSY;   /* -EPERM would confuse the user */}if (scull_u_count == 0)scull_u_owner = current->cred->uid; /* grab it */scull_u_count++;spin_unlock(&scull_u_lock);/* then, everything else is copied from the bare scull device */if ((filp->f_flags & O_ACCMODE) == O_WRONLY) scull_trim(dev);filp->private_data = dev;return 0;          /* success */
}

scull_u_owner的类型是uid_t ,而新的内核current->cred->uid的类型是kuid_t,所以才报上述错误。

current是一个宏,返回当前进程的上下文,返回类型为struct task_struct*, 结构体定义在<linux/sched.h>;

current->cred的类型为struct cred;结构体定义在<linux/cred.h>

current->cred->uid的类型是struct kgid_t;结构体定义在<linux/uidgid.h>

内容为:

typedef struct {uid_t val;
} kuid_t;

所以把current->cred->uid改为current->cred->uid.val就可以解决上述错误了

error: invalid operands to binary == (have ‘uid_t’ {aka ‘unsigned int’} and ‘kuid_t’相关推荐

  1. error: invalid operands to binary % (have ‘double‘ and ‘int‘)取模mod %

    此处出现错误: 因为%不可以用于浮点型(double,float类型),只能用于整型(int类型) 可以强制类型转换,将浮点型强制转换为整型,解决此问题 double b = (int) floor( ...

  2. [Error] invalid operands of types ‘float‘ and ‘float‘ to binary ‘operator%‘

    是因为求余运算符%要求左边的数是整数,但是把一个 float 类型的数放在%左边进行运算,就会报以上 错误 .所以要么转型(int)a,但是必须是a本身是整数的情况或者说符合题目要求只需要整型部分,不 ...

  3. reorg_cls_centerness.cpp:4658:74: error: invalid conversion from ‘int’ to ‘PyObject* {aka _object*}’

    运行python rotation_setup.py build时,报错: rotation/reorg_cls_centerness.cpp: In function 'int __Pyx_Init ...

  4. c++中结构体套结构体用 = {0}初始化编译报错解决办法(用memset或者={})(error: invalid conversion)

    我这有个结构体: VENC_CHN_ATTR_S venc_chn_attr; /* the attribute of the venc chnl*/ typedef struct rkVENC_CH ...

  5. OTS parsing error: invalid version tag woff和ttf文件被Filter拦截

    从服务器下载的字体文件放在本地,执行无法展示iconfont,浏览器控制台报出 Failed to decode downloaded font: http://127.0.0.1:8080/mhr/ ...

  6. ruby环境sass编译中文出现Syntax error: Invalid GBK character错误解决方法

    sass文件编译时候使用ruby环境,无论是界面化的koala工具还是命令行模式的都无法通过,真是令人烦恼. 容易出现中文注释时候无法编译通过,或者出现乱码,找了几天的解决方法终于解决了. 这个问题的 ...

  7. 【笔记】Error while loading PyV8 binary: exit code 1解决方法

    [笔记]Error while loading PyV8 binary: exit code 1解决方法 参考文章: (1)[笔记]Error while loading PyV8 binary: e ...

  8. cuda error invalid argument

    用pytorch训练时报的错 在loss.backward时报错 估计应该是loss出现了异常值. 网上其他答案: 问题: RuntimeError: CUDA error: invalid conf ...

  9. runtime error: invalid memory address or nil pointer dereference

    runtime error: invalid memory address or nil pointer dereference 解决方法: tcallback((unsigned char*)pac ...

  10. Package CJK Error: Invalid character code. 问题解决方法--xelatex和pdflatex编译的转换

    Package CJK Error: Invalid character code. 问题解决方法--xelatex和pdflatex编译的转换 解决方法:添加格式说明信息 将下面语句: \docum ...

最新文章

  1. ASP.NET中的页面指示标识
  2. python实现文件上传预览_Python文件上传功能简单实现
  3. Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button展示图片事件)
  4. 中国半光漆市场需求前景与投资规划研究报告2021年版
  5. python3练习-装饰器
  6. python读文本文件的过程是怎样的_读写文本文件的步骤_Python读写txt文本文件的操作方法全解析...
  7. 当开启了延迟加载的开关,对象是怎么变成代理对象的?
  8. [http]HTTP状态码含义
  9. linux将db2账户添加到组_超实用的shell脚本--Linux安全加固设置,值得收藏
  10. 反向输出一个三位数(信息学奥赛一本通-T1031)
  11. vue弹出框消息重置问题---一个投机取巧的方法
  12. 易语言html代码解释器,易语言执行javascript
  13. matlab光滑曲线链接,在Matlab中使用光滑曲线连接点
  14. 如何在DPDK盒子上使用TRex
  15. C++幕后故事(七)--一个对象的生与死
  16. python 插值求包络线
  17. 远程开机:一个简单的嵌入式项目开发
  18. Linux - 常见端口和服务的对照和解释
  19. 简易钓鱼网站的构建(Kali SetoolKit)
  20. html中什么是功能链接,链接是什么?(链接的意思与功能)

热门文章

  1. 寻找故障检测相关论文的期刊
  2. flutter BoxDecoration设置背景 image 报错:type ‘Image‘ is not a subtype of type ‘ImageProvider<Object> 解决方法
  3. 几百万数据量的 Excel 导出会内存溢出和卡顿?那是你没用对方法!
  4. 163邮箱登录页面在哪儿?如何在手机、电脑上登陆163邮箱?
  5. 【应用】Android平台最佳健身
  6. 计算机原理求循环余数,国防科技大学2003年计算机原理考研试题
  7. “燕云十六将”之三弟王静
  8. excel合并两列内容_WPS-excel简单将几个单元格的内容合并到一起
  9. 郭盛华是如何登上神坛?令全世界认识了中国的黑科技
  10. 郭盛华技术有多牛?外媒:稳坐亚洲第一