simple linux kernel program that complains about pointer problem

捕鲸叉 2017-09-07 11:19:58
i write a simple kernel program, and it complains about pointer problem: " dereferencing pointer to incomplete type"
on the "ret->name" "ret->state" "ret->core_size"
how to correct it?
next are the .c file and Makefile


#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/preempt.h>

MODULE_LICENSE("GPL");

static int _init_module_address(void);
static void _exit_module_address(void);

struct module;

int amodule(void)
{
return 0;
}

int _init_module_address(void)
{
struct moudle* ret = NULL;
const unsigned long addr = (const unsigned long)amodule;

preempt_disable();
ret = __module_address(addr);
preempt_enable();


if (ret != NULL)
{
//ret->name; //dereferencing pointer to incomplete type
printk(KERN_INFO "name=%s\n", ret->name);
printk(KERN_INFO "state=%d\n", int(ret->state));
printk(KERN_INFO "core_size=%d\n", int(ret->core_size));
printk(KERN_INFO "module addr return not NULL\n");
return 0;
}

printk(KERN_INFO "module addr return NULL\n");
return 0;
}

void _exit_module_address(void)
{
printk(KERN_INFO "module exit\n");
}

module_init(_init_module_address);
module_exit(_exit_module_address);



ifneq ($(KERNELRELEASE),)
obj-m = _module_address.o
else
PWD := $(shell pwd)
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
endif

default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
rm -rf *.o *.mod.c *.ko *.symvers *.order *.makers *~
...全文
383 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
捕鲸叉 2017-09-07
  • 打赏
  • 举报
回复
sorry for using english, my ubuntu is english version
捕鲸叉 2017-09-07
  • 打赏
  • 举报
回复
引用 2 楼 jklinux 的回复:
// struct moudle* ret = NULL; you wrote the wrong word. it should be "struct module" . besides, what's the program for ? just for getting information about current module?
you are right! how stupid a mistake i made
jklinux 2017-09-07
  • 打赏
  • 举报
回复
// struct moudle* ret = NULL; you wrote the wrong word. it should be "struct module" . besides, what's the program for ? just for getting information about current module?

1,318

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧