evdev的一个BUG

     自己调试的系统偶有死机,跟同事们一起琢磨的结果如下:在evdev.c文件中存在一个隐患的BUG。

static int evdev_open(struct inode *inode, struct file *file)
{
                struct evdev *evdev;
  struct evdev_client *client;
  int i = iminor(inode) - EVDEV_MINOR_BASE;
  int error;

                if (i >= EVDEV_MINORS)
  return -ENODEV;

  error = mutex_lock_interruptible(&evdev_table_mutex);
  if (error)
  return error;
                evdev = evdev_table[i];
  if (evdev)
                                get_device(&evdev->dev);
                mutex_unlock(&evdev_table_mutex);
                if (!evdev)
  return -ENODEV;
  error = evdev_open_device(evdev);
  if (error)
                                goto err_put_evdev;


  client = kzalloc(sizeof(struct evdev_client), GFP_KERNEL);
  if (!client) {
                                error = -ENOMEM;
                                goto err_put_evdev;
                }

  spin_lock_init(&client->buffer_lock);
  wake_lock_init(&client->wake_lock, WAKE_LOCK_SUSPEND, evdev->name);
  client->evdev = evdev;
  evdev_attach_client(evdev, client);

                error = evdev_open_device(evdev);
                 if (error)
                                goto err_put_evdev;


  file->private_data = client;
  return 0;

err_free_client:
                evdev_detach_client(evdev, client);
  kfree(client);
err_put_evdev:
                put_device(&evdev->dev);
                return error;
}
可能的问题在于:在wake_lock_init(&client->wake_lock, WAKE_LOCK_SUSPEND, evdev->name);中会把wake_lock插入到唤醒锁的链表中,如果在这个语句后面蓝色处还有导致err_free_client的发生,其里面有kfree(client)会把刚插入的那个wake_lock空间也释放,造成链表断裂,引起系统不稳定。所以要将可能导致goto err_put_evdev的evdev_open_device放在插入wake_lock之前,即红色处。

mark:以后测试机器有用
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值