免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1573 | 回复: 1
打印 上一主题 下一主题

kmalloc出问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-06-19 19:28 |只看该作者 |倒序浏览
最近碰到一个很诡异的问题,在写内核模块时,kmalloc出问题了,如下面这个很简单的hello world程序。

硬件平台:XSCALE IXP43x
软件平台:Linux2.6.23.1

代码如下:

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>         /* Needed for the macros */


static int __init hello_start(void)
{
    int* mem;
    size_t size = 64;

    mem = (int*)kmalloc(size, GFP_KERNEL);

    return 0;
}

static void __exit hello_end(void)
{
    printk(KERN_EMERG"Goodbye Mr.\n");
}

module_init(hello_start);
module_exit(hello_end);
MODULE_LICENSE("GPL");

谁碰到过类似问题,帮我看看,谢谢了!

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
2 [报告]
发表于 2010-06-20 13:15 |只看该作者

  1. [root@T-bagwell modules]# insmod hello.ko

  2. Message from syslogd@localhost at Jun 20 13:14:44 ...
  3. kernel:addr = ecd79d40, Thank you Sir.
  4. [root@T-bagwell modules]#
  5. [root@T-bagwell modules]# rmmod hello
  6. [root@T-bagwell modules]#
  7. Message from syslogd@localhost at Jun 20 13:14:51 ...
  8. kernel:Goodbye Sir.

  9. [root@T-bagwell modules]# insmod hello.ko
  10. [root@T-bagwell modules]#
  11. Message from syslogd@localhost at Jun 20 13:14:58 ...
  12. kernel:addr = ed07b200, Thank you Sir.

  13. [root@T-bagwell modules]# lsmod | grep hello
  14. hello                   1300  0
  15. [root@T-bagwell modules]#

复制代码
楼主的错误信息能发出来看看不?
exit的时候应该kfree一下kmalloc的mem吧?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP