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

错误原因是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了。

你可能感兴趣的:(c,struct,null,input,linux内核)