globalmem.c:193:2: 错误:隐式声明函数‘kmalloc’ [-Werror=implicit-function-declaration]

本文解决了因函数未声明导致的编译错误问题,通过引入正确的头文件来确保kmalloc与kfree等函数能被正确识别。

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

隐式声明函数错误的意思是函数在未声明之前就被调用了,需要先声明这两个函数,版本变化导致这个错误的出现。

解决方法:

找到kmalloc与kfree的声明头文件并include进来就可以了

#include <linux/slab.h>

/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、付费专栏及课程。

余额充值