unregister_chrdev_region和__unregister_chrdev_region和cdev_del

本文详细介绍了Linux内核中用于卸载字符设备的函数unregister_chrdev_region和__unregister_chrdev_region的使用,特别是两者的区别,以及cdev_del函数在设备删除过程中的作用。cdev_del通过cdev_unmap释放设备,并通过kobject_put处理内核对象的释放。
摘要由CSDN通过智能技术生成
/**
 * unregister_chrdev_region() - return a range of device numbers
 * @from: the first in the range of numbers to unregister
 * @count: the number of device numbers to unregister
 *
 * This function will unregister a range of @count device numbers,
 * starting with @from.  The caller should normally be the one who
 * allocated those numbers in the first place...
 */
void unregister_chrdev_region(dev_t from, unsigned count)
{
	dev_t to = from + count;
	dev_t n, next;

	for (n = from; n < to; n = next) {
		next = MKDEV(MAJOR(n)+1, 0);
		if (next > to)
			next = to;
		kfree(__unregister_chrdev_region(MAJOR(n), MINOR(n), next - n));
	}
}

参数1:设备号,参数2:要卸载的个数

说明:大部分代码和register_chrdev_region差不多,区别在于__unregister_chrdev_region(MAJOR(n), MINOR(n), next - n)这个函数

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值