globalmem.c:160:2: 警告:从不兼容的指针类型初始化 [默认启用]

本文介绍了如何解决Linux内核2.6.38版本中由于file_operation结构体更新导致的ioctl函数兼容性问题。通过修改globalmem_ioctl函数定义及初始化方式,确保代码能在新内核版本中正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/globalmem.c:160:2: 警告:从不兼容的指针类型初始化 [默认启用]

/globalmem.c:160:2: 警告:(在‘globalmem_fops.unlocked_ioctl’的初始化附近) [默认启用]

这个错误网上搜索发现2.6.38版本内核 file_operation结构体已经删除了ioctl函数,取代的是:

long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);   
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);

file_operation结构体在 /usr/src/linux-2.6.28.8/include/linux/fs.h定义

globalmem解决方案:

globalmem.c中将globalmem_ioctl函数定义做如下修改即可:

static long globalmem_ioctl( struct file *filp,unsigned int cmd, unsigned long arg)

在file_operation 赋值处修改:
.unlocked_ioctl = globalmem_ioctl,


/home/ty/code_data/g99/system/vendor/alps/kernel-5.10/drivers/misc/mediatek/flashlight/globalmem.c:173:8: error: incompatible function pointer types initializing 'ssize_t (*)(struct device *, struct device_attribute *, char *)' (aka 'long (*)(struct device *, struct device_attribute *, char *)') with an expression of type 'ssize_t (struct device *, struct device_attribute *, char *, size_t)' (aka 'long (struct device *, struct device_attribute *, char *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types] static DEVICE_ATTR_RW(debugger); ^~~~~~~~~~~~~~~~~~~~~~~~ /home/ty/code_data/g99/system/vendor/alps/kernel-5.10/include/linux/device.h:132:45: note: expanded from macro 'DEVICE_ATTR_RW' struct device_attribute dev_attr_##_name = __ATTR_RW(_name) ^~~~~~~~~~~~~~~~ /home/ty/code_data/g99/system/vendor/alps/kernel-5.10/include/linux/sysfs.h:138:46: note: expanded from macro '__ATTR_RW' #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) ^~~~~~~~~~~~ <scratch space>:15:1: note: expanded from here debugger_show ^~~~~~~~~~~~~ /home/ty/code_data/g99/system/vendor/alps/kernel-5.10/include/linux/sysfs.h:104:10: note: expanded from macro '__ATTR' .show = _show, \ ^~~~~ /home/ty/code_data/g99/system/vendor/alps/kernel-5.10/drivers/misc/mediatek/flashlight/globalmem.c:173:8: error: incompatible function pointer types initializing 'ssize_t (*)(struct device *, struct device_attribute *, const char *, size_t)' (aka 'long (*)(struct device *, struct device_attribute *, const char *, unsigned long)') with an expression of type 'ssize_t (struct device *, struct device_attribute *, char *, size_t)' (aka 'long (struct device *, struct device_attribute *, char *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types] static DEVICE_ATTR_RW(debugger); ^~
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值