您的位置:首页 > Web前端

Unable to handle kernel NULL pointer dereference at virtual address-----------原因分析 ,及解决办法

2011-06-28 19:34 1641 查看
错误原因是linux内核中出现空指针。
对于我的错误代码如下:
nas_priv->input->name = "nastech_ts";
nas_priv->input->phys = nas_priv->phys;
nas_priv->input->id.bustype = BUS_I2C;
如果把这几行注释了,就不会报错。
大致是因为nas_priv_input是空的。
具体解决方法,如下:
nas_priv的定义如下
struct nas_ts_priv {TOUCH_DATA_st *touchData;struct i2c_client *client;struct input_dev *input;};static struct nas_ts_priv *nas_priv=NULL;
 
在linux内核空间,应显式分配所有的内存。
nas_priv=kzalloc(sizeof(struct nas_ts_priv), GFP_KERNEL);nas_priv->client=kzalloc(sizeof(struct i2c_client),GFP_KERNEL);nas_priv->touchData =kzalloc(sizeof(TOUCH_DATA_st), GFP_KERNEL);nas_priv->input =kzalloc(sizeof(struct input_dev), GFP_KERNEL);
 
然后,OK了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  null linux内核 struct input c
相关文章推荐