当前位置: 首页>>代码示例>>C++>>正文


C++ cdev_del函数代码示例

本文整理汇总了C++中cdev_del函数的典型用法代码示例。如果您正苦于以下问题:C++ cdev_del函数的具体用法?C++ cdev_del怎么用?C++ cdev_del使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cdev_del函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sstore_init

static int __init sstore_init (void)
{
    int i;
    int rv;

    if(alloc_chrdev_region(&sstore_dev_number,
                sstore_minor, NUM_SSTORE_DEVICES, DEV_NAME) < 0){
        printk(KERN_DEBUG "sstore: unable to register device.\n");
        rv = -EPERM;
        goto init_out;
    }
    sstore_major = MAJOR(sstore_dev_number);

    sstore_class = class_create(THIS_MODULE, DEV_NAME);

    for(i = 0; i < NUM_SSTORE_DEVICES; ++i){
        /* Allocate memory for the per-device structure */
        sstore_devp[i] = kmalloc(sizeof(struct sstore_dev), GFP_KERNEL);
        if (!sstore_devp[i]){
            printk(KERN_DEBUG "sstore: bad kmalloc\n");
            rv = -ENOMEM;
            goto no_devs;
        }

        sstore_devp[i]->open_count = 0;
        sstore_devp[i]->read_count = 0;
        sstore_devp[i]->write_count = 0;
        sstore_devp[i]->del_count = 0;
        sstore_devp[i]->sstore_number = i;

        sstore_devp[i]->sstore_blobp = kzalloc(num_of_blobs *
                sizeof(struct sstore_dev *), GFP_KERNEL);
        if (!sstore_devp[i]->sstore_blobp){
            printk(KERN_DEBUG "sstore: bad kzalloc\n");
            rv = -ENOMEM;
            goto no_blobs;
        }

        /* Init lock(s) */
        mutex_init(&sstore_devp[i]->sstore_lock);
        init_waitqueue_head(&sstore_devp[i]->sstore_wq);

        /* Connect the file operations with the cdev */
        cdev_init(&sstore_devp[i]->cdev, &sstore_fops);
        sstore_devp[i]->cdev.owner = THIS_MODULE;

        /* Connect the major/minor number to the cdev */
        rv = cdev_add(&sstore_devp[i]->cdev,
                MKDEV(sstore_major, sstore_minor + i), 1);
        if (rv) {
            printk(KERN_DEBUG "sstore: bad cdev\n");
            goto no_cdev_connection;
        }

        /* Send uevents to udev, so it'll create /dev nodes */
        device_create(sstore_class, NULL,
                MKDEV(sstore_major, sstore_minor + i), "sstore%d", i);
    }
    
    rv = sstore_proc_init();
    if(rv){
        printk(KERN_DEBUG "sstore: unable to init /proc files.\n");
        goto no_proc_files;
    }

    printk(KERN_INFO "sstore: driver initialized.\n");
    return 0;

/* Evil goto error handling. */
no_proc_files:
    for(; i >=0; --i){
        device_destroy (sstore_class, MKDEV(sstore_major, sstore_minor + i));
        cdev_del(&sstore_devp[i]->cdev);
no_cdev_connection:
        kfree(sstore_devp[i]->sstore_blobp);
no_blobs:
        kfree(sstore_devp[i]);
no_devs:
        continue;
    }

    class_destroy(sstore_class);
init_out:
    return rv;
}
开发者ID:cboylan,项目名称:device_drivers,代码行数:85,代码来源:sstore.c

示例2: vc_mem_connected_init

void
vc_mem_connected_init(void)
{
	int rc = -EFAULT;
	struct device *dev;

	LOG_DBG("%s: called", __func__);

	vc_mem_get_size();

	printk("vc-mem: mm_vc_mem_phys_addr = 0x%08lx\n", mm_vc_mem_phys_addr);
	printk("vc-mem: mm_vc_mem_size      = 0x%08x (%u MiB)\n",
	       mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));

	if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
		LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
		goto out_err;
	}

	cdev_init(&vc_mem_cdev, &vc_mem_fops);
	if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
		LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
		goto out_unregister;
	}

	vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
	if (IS_ERR(vc_mem_class)) {
		rc = PTR_ERR(vc_mem_class);
		LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
		goto out_cdev_del;
	}

	dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
			    DRIVER_NAME);
	if (IS_ERR(dev)) {
		rc = PTR_ERR(dev);
		LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
		goto out_class_destroy;
	}

	vc_mem_proc_entry = create_proc_entry(DRIVER_NAME, 0444, NULL);
	if (vc_mem_proc_entry == NULL) {
		rc = -EFAULT;
		LOG_ERR("%s: create_proc_entry failed", __func__);
		goto out_device_destroy;
	}
	vc_mem_proc_entry->read_proc = vc_mem_proc_read;
	vc_mem_proc_entry->write_proc = vc_mem_proc_write;

	vc_mem_inited = 1;
	return;

      out_device_destroy:
	device_destroy(vc_mem_class, vc_mem_devnum);

      out_class_destroy:
	class_destroy(vc_mem_class);
	vc_mem_class = NULL;

      out_cdev_del:
	cdev_del(&vc_mem_cdev);

      out_unregister:
	unregister_chrdev_region(vc_mem_devnum, 1);

      out_err:
	return;
}
开发者ID:KiwiSteve,项目名称:broadcom-kernel-raspberry-pi,代码行数:68,代码来源:vc_mem.c

示例3: globalfifo_exit

void globalfifo_exit(void)
{
  cdev_del(&globalfifo_devp->cdev); 
  kfree(globalfifo_devp);     
  unregister_chrdev_region(MKDEV(globalfifo_major, 0), 1);
}
开发者ID:liuyang201666,项目名称:akae_sdk,代码行数:6,代码来源:block_another.c

示例4: WMT_init

static int WMT_init(void)
{
    dev_t devID = MKDEV(gWmtMajor, 0);
    INT32 cdevErr = -1;
    INT32 ret = -1;
    WMT_INFO_FUNC("WMT Version= %s DATE=%s\n" , MTK_WMT_VERSION, MTK_WMT_DATE);
    /* Prepare a UCHAR device */
    /*static allocate chrdev*/

    stp_drv_init();

    ret = register_chrdev_region(devID, WMT_DEV_NUM, WMT_DRIVER_NAME);
    if (ret) {
        WMT_ERR_FUNC("fail to register chrdev\n");
        return ret;
    }

    cdev_init(&gWmtCdev, &gWmtFops);
    gWmtCdev.owner = THIS_MODULE;

    cdevErr = cdev_add(&gWmtCdev, devID, WMT_DEV_NUM);
    if (cdevErr) {
        WMT_ERR_FUNC("cdev_add() fails (%d) \n", cdevErr);
        goto error;
    }
    WMT_INFO_FUNC("driver(major %d) installed \n", gWmtMajor);


#if 0
    pWmtDevCtx = wmt_drv_create();
    if (!pWmtDevCtx) {
        WMT_ERR_FUNC("wmt_drv_create() fails \n");
        goto error;
    }

    ret = wmt_drv_init(pWmtDevCtx);
    if (ret) {
        WMT_ERR_FUNC("wmt_drv_init() fails (%d) \n", ret);
        goto error;
    }

    WMT_INFO_FUNC("stp_btmcb_reg\n");
    wmt_cdev_btmcb_reg();

    ret = wmt_drv_start(pWmtDevCtx);
    if (ret) {
        WMT_ERR_FUNC("wmt_drv_start() fails (%d) \n", ret);
        goto error;
    }
#endif
    ret = wmt_lib_init();
    if (ret) {
        WMT_ERR_FUNC("wmt_lib_init() fails (%d) \n", ret);
        goto error;
    }
#if CFG_WMT_DBG_SUPPORT
    wmt_dev_dbg_setup();
#endif

#if  defined(CONFIG_THERMAL) &&  defined(CONFIG_THERMAL_OPEN)
    WMT_INFO_FUNC("wmt_dev_tm_setup\n");
    wmt_dev_tm_setup();
    mtk_wcn_hif_sdio_update_cb_reg(wmt_dev_tra_sdio_update);
#endif

    WMT_INFO_FUNC("success \n");
    return 0;

error:
    wmt_lib_deinit();
#if CFG_WMT_DBG_SUPPORT    
    wmt_dev_dbg_remove();
#endif
    if (cdevErr == 0) {
        cdev_del(&gWmtCdev);
    }

    if (ret == 0) {
        unregister_chrdev_region(devID, WMT_DEV_NUM);
        gWmtMajor = -1;
    }

    WMT_ERR_FUNC("fail \n");

    return -1;
}
开发者ID:agrloki,项目名称:android_kernel_ousheng_V9,代码行数:86,代码来源:wmt_dev.c

示例5: second_exit

/*模块卸载函数*/
void second_exit(void)
{
  cdev_del(&second_devp->cdev);   /*注销cdev*/
  kfree(second_devp);     /*释放设备结构体内存*/
  unregister_chrdev_region(MKDEV(second_major, 0), 1); /*释放设备号*/
}
开发者ID:nsood,项目名称:LinuxDriver_CodeList,代码行数:7,代码来源:second.c

示例6: frandom_init_module

static int frandom_init_module(void)
{
	int result;

	/* The buffer size MUST be at least 256 bytes, because we assume that
	   minimal length in init_rand_state().
	*/       
	if (frandom_bufsize < 256) {
		printk(KERN_ERR "frandom: Refused to load because frandom_bufsize=%d < 256\n",frandom_bufsize);
		return -EINVAL;
	}
	if ((frandom_chunklimit != 0) && (frandom_chunklimit < 256)) {
		printk(KERN_ERR "frandom: Refused to load because frandom_chunklimit=%d < 256 and != 0\n",frandom_chunklimit);
		return -EINVAL;
	}

	erandom_state = kmalloc(sizeof(struct frandom_state), GFP_KERNEL);
	if (!erandom_state)
		return -ENOMEM;

	/* This specific buffer is only used for seeding, so we need
	   256 bytes exactly */
	erandom_state->buf = kmalloc(256, GFP_KERNEL);
	if (!erandom_state->buf) {
		kfree(erandom_state);
		return -ENOMEM;
	}

	sema_init(&erandom_state->sem, 1); /* Init semaphore as a mutex */

	erandom_seeded = 0;

	frandom_class = class_create(THIS_MODULE, "fastrng");
	if (IS_ERR(frandom_class)) {
		result = PTR_ERR(frandom_class);
		printk(KERN_WARNING "frandom: Failed to register class fastrng\n");
		goto error0;
	}
	
	/*
	 * Register your major, and accept a dynamic number. This is the
	 * first thing to do, in order to avoid releasing other module's
	 * fops in frandom_cleanup_module()
	 */

	cdev_init(&frandom_cdev, &frandom_fops);
	frandom_cdev.owner = THIS_MODULE;
	result = cdev_add(&frandom_cdev, MKDEV(frandom_major, frandom_minor), 1);
	if (result) {
	  printk(KERN_WARNING "frandom: Failed to add cdev for /dev/frandom\n");
	  goto error1;
	}

	result = register_chrdev_region(MKDEV(frandom_major, frandom_minor), 1, "/dev/frandom");
	if (result < 0) {
		printk(KERN_WARNING "frandom: can't get major/minor %d/%d\n", frandom_major, frandom_minor);
	  goto error2;
	}

	frandom_device = device_create(frandom_class, NULL, MKDEV(frandom_major, frandom_minor), NULL, "frandom");

	if (IS_ERR(frandom_device)) {
		printk(KERN_WARNING "frandom: Failed to create frandom device\n");
		goto error3;
	}

	cdev_init(&erandom_cdev, &frandom_fops);
	erandom_cdev.owner = THIS_MODULE;
	result = cdev_add(&erandom_cdev, MKDEV(frandom_major, erandom_minor), 1);
	if (result) {
	  printk(KERN_WARNING "frandom: Failed to add cdev for /dev/erandom\n");
	  goto error4;
	}

	result = register_chrdev_region(MKDEV(frandom_major, erandom_minor), 1, "/dev/erandom");
	if (result < 0) {
		printk(KERN_WARNING "frandom: can't get major/minor %d/%d\n", frandom_major, erandom_minor);
		goto error5;
	}

	erandom_device = device_create(frandom_class, NULL, MKDEV(frandom_major, erandom_minor), NULL, "erandom");

	if (IS_ERR(erandom_device)) {
		printk(KERN_WARNING "frandom: Failed to create erandom device\n");
		goto error6;
	}
	return 0; /* succeed */

 error6:
	unregister_chrdev_region(MKDEV(frandom_major, erandom_minor), 1);
 error5:
	cdev_del(&erandom_cdev);
 error4:
	device_destroy(frandom_class, MKDEV(frandom_major, frandom_minor));
 error3:
	unregister_chrdev_region(MKDEV(frandom_major, frandom_minor), 1);
 error2:
	cdev_del(&frandom_cdev);
 error1:
	class_destroy(frandom_class);
//.........这里部分代码省略.........
开发者ID:BlackSoulxxx,项目名称:XerXes,代码行数:101,代码来源:frandom.c

示例7: simple_cleanup

static void simple_cleanup(void)
{
    cdev_del(SimpleDevs);
    cdev_del(SimpleDevs + 1);
    unregister_chrdev_region(MKDEV(simple_major, 0), 2);
}
开发者ID:yushu9,项目名称:linux_kernel_driver,代码行数:6,代码来源:simple.c

示例8: tf_device_register


//.........这里部分代码省略.........
		printk(KERN_ERR "tf_device_register():"
			" register_chrdev_region failed (error %d)!\n",
			error);
		goto register_chrdev_region_failed;
	}

	error = cdev_add(&dev->cdev, dev->dev_number, 1);
	if (error != 0) {
		printk(KERN_ERR "tf_device_register(): "
			"cdev_add failed (error %d)!\n",
			error);
		goto cdev_add_failed;
	}

	/*
	 * Initialize the communication with the Secure World.
	 */
#ifdef CONFIG_TF_TRUSTZONE
	dev->sm.soft_int_irq = soft_interrupt;
#endif
	error = tf_init(&g_tf_dev.sm);
	if (error != S_SUCCESS) {
		dprintk(KERN_ERR "tf_device_register(): "
			"tf_init failed (error %d)!\n",
			error);
		goto init_failed;
	}

#ifdef CONFIG_TF_DRIVER_CRYPTO_FIPS
	error = tf_self_test_post_init(&(g_tf_dev.kobj));
	/* N.B. error > 0 indicates a POST failure, which will not
	   prevent the module from loading. */
	if (error < 0) {
		dprintk(KERN_ERR "tf_device_register(): "
			"tf_self_test_post_vectors failed (error %d)!\n",
			error);
		goto post_failed;
	}
#endif

#ifdef CONFIG_ANDROID
	tf_class = class_create(THIS_MODULE, TF_DEVICE_BASE_NAME);
	device_create(tf_class, NULL,
		dev->dev_number,
		NULL, TF_DEVICE_BASE_NAME);
#endif

#ifdef CONFIG_TF_ZEBRA
	/*
	 * Initializes the /dev/tf_ctrl device node.
	 */
	error = tf_ctrl_device_register();
	if (error)
		goto ctrl_failed;
#endif

#ifdef CONFIG_TF_DRIVER_DEBUG_SUPPORT
	address_cache_property((unsigned long) &tf_device_register);
#endif
	/*
	 * Successful completion.
	 */

	dprintk(KERN_INFO "tf_device_register(): Success\n");
	return 0;

	/*
	 * Error: undo all operations in the reverse order
	 */
#ifdef CONFIG_TF_ZEBRA
ctrl_failed:
#endif
#ifdef CONFIG_TF_DRIVER_CRYPTO_FIPS
	tf_self_test_post_exit();
post_failed:
#endif
init_failed:
	cdev_del(&dev->cdev);
cdev_add_failed:
	unregister_chrdev_region(dev->dev_number, 1);
register_chrdev_region_failed:
	unregister_syscore_ops(&g_tf_device_syscore_ops);
kobject_init_and_add_failed:
	kobject_del(&g_tf_dev.kobj);

#if defined(MODULE) && defined(CONFIG_TF_ZEBRA)
#ifdef CONFIG_TF_DRIVER_CRYPTO_FIPS
	tf_self_test_unregister_device();
self_test_register_device_failed:
	tf_crypto_hmac_module_exit();
hmac_init_failed:
#endif
	tf_device_mshield_exit();
mshield_init_failed:
module_early_init_failed:
#endif
	dprintk(KERN_INFO "tf_device_register(): Failure (error %d)\n",
		error);
	return error;
}
开发者ID:aicjofs,项目名称:android_kernel_fuhu_t8400n,代码行数:101,代码来源:tf_device.c

示例9: hello_driver_exit

__exit static void hello_driver_exit (void) 
{
	unregister_chrdev_region (MKDEV(major, minor), 1) ;
	cdev_del (&hello_cdev) ;
	printk(KERN_ALERT"cleanup module\r\n") ;
}
开发者ID:kk821521286,项目名称:kangkai,代码行数:6,代码来源:hello_driver.c

示例10: globalmem_exit

static void __exit globalmem_exit(void)
{
    cdev_del(&globalmem_devp->cdev);
    kfree(globalmem_devp);
    unregister_chrdev_region(MKDEV(globalmem_major, 0), 1);
}
开发者ID:21cnbao,项目名称:training,代码行数:6,代码来源:globalmem.c

示例11: globalfifo_exit

void globalfifo_exit(void)
{
	cdev_del(&devp->cdev);//注销cdev
	kfree((void*)devp);//释放设备结构体内存
	unregister_chrdev_region(MKDEV(globalfifo_major,0),1);//释放设备号
}
开发者ID:jefby,项目名称:LDD,代码行数:6,代码来源:globalfifo.c

示例12: hello_init

/*模块加载方法*/
static int __init hello_init(void){ 
	int err = -1;
	dev_t dev = 0;
	struct device* temp = NULL;

	printk(KERN_ALERT"Initializing hello device.\n");        

	/*动态分配主设备和从设备号*/
	err = alloc_chrdev_region(&dev, 0, 1, HELLO_DEVICE_NODE_NAME);
	if(err < 0) {
		printk(KERN_ALERT"Failed to alloc char dev region.\n");
		goto fail;
	}

	hello_major = MAJOR(dev);
	hello_minor = MINOR(dev);        

	/*分配helo设备结构体变量*/
	hello_dev = kmalloc(sizeof(struct hello_android_dev), GFP_KERNEL);
	if(!hello_dev) {
		err = -ENOMEM;
		printk(KERN_ALERT"Failed to alloc hello_dev.\n");
		goto unregister;
	}        

	/*初始化设备*/
	err = __hello_setup_dev(hello_dev);
	if(err) {
		printk(KERN_ALERT"Failed to setup dev: %d.\n", err);
		goto cleanup;
	}        

	/*在/sys/class/目录下创建设备类别目录hello*/
	hello_class = class_create(THIS_MODULE, HELLO_DEVICE_CLASS_NAME);
	if(IS_ERR(hello_class)) {
		err = PTR_ERR(hello_class);
		printk(KERN_ALERT"Failed to create hello class.\n");
		goto destroy_cdev;
	}        

	/*在/dev/目录和/sys/class/hello目录下分别创建设备文件hello*/
	temp = device_create(hello_class, NULL, dev, "%s", HELLO_DEVICE_FILE_NAME);
	if(IS_ERR(temp)) {
		err = PTR_ERR(temp);
		printk(KERN_ALERT"Failed to create hello device.");
		goto destroy_class;
	}        

	/*在/sys/class/hello/hello目录下创建属性文件val*/
	err = device_create_file(temp, &dev_attr_val);
	if(err < 0) {
		printk(KERN_ALERT"Failed to create attribute val.");                
		goto destroy_device;
	}

	dev_set_drvdata(temp, hello_dev);        

	/*创建/proc/hello文件*/
	hello_create_proc();

	printk(KERN_ALERT"Succedded to initialize hello device.\n");
	return 0;

destroy_device:
	device_destroy(hello_class, dev);

destroy_class:
	class_destroy(hello_class);

destroy_cdev:
	cdev_del(&(hello_dev->dev));

cleanup:
	kfree(hello_dev);

unregister:
	unregister_chrdev_region(MKDEV(hello_major, hello_minor), 1);

fail:
	return err;
}
开发者ID:dailianyu,项目名称:android,代码行数:82,代码来源:hello.c

示例13: dsps_probe

/**
 * platform driver
 *
 */
static int __devinit dsps_probe(struct platform_device *pdev)
{
	int ret;

	pr_debug("%s.\n", __func__);

	if (pdev->dev.platform_data == NULL) {
		pr_err("%s: platform data is NULL.\n", __func__);
		return -ENODEV;
	}

	drv = kzalloc(sizeof(*drv), GFP_KERNEL);
	if (drv == NULL) {
		pr_err("%s: kzalloc fail.\n", __func__);
		goto alloc_err;
	}
	atomic_set(&drv->crash_in_progress, 0);

	drv->pdata = pdev->dev.platform_data;

	drv->dev_class = class_create(THIS_MODULE, DRV_NAME);
	if (drv->dev_class == NULL) {
		pr_err("%s: class_create fail.\n", __func__);
		goto res_err;
	}

	ret = alloc_chrdev_region(&drv->dev_num, 0, 1, DRV_NAME);
	if (ret) {
		pr_err("%s: alloc_chrdev_region fail.\n", __func__);
		goto alloc_chrdev_region_err;
	}

	drv->dev = device_create(drv->dev_class, NULL,
				     drv->dev_num,
				     drv, DRV_NAME);
	if (IS_ERR(drv->dev)) {
		pr_err("%s: device_create fail.\n", __func__);
		goto device_create_err;
	}

	drv->cdev = cdev_alloc();
	if (drv->cdev == NULL) {
		pr_err("%s: cdev_alloc fail.\n", __func__);
		goto cdev_alloc_err;
	}
	cdev_init(drv->cdev, &dsps_fops);
	drv->cdev->owner = THIS_MODULE;

	ret = cdev_add(drv->cdev, drv->dev_num, 1);
	if (ret) {
		pr_err("%s: cdev_add fail.\n", __func__);
		goto cdev_add_err;
	}

	ret = dsps_alloc_resources(pdev);
	if (ret) {
		pr_err("%s: failed to allocate dsps resources.\n", __func__);
		goto cdev_add_err;
	}

	ret =
	    smsm_state_cb_register(SMSM_DSPS_STATE, SMSM_RESET,
				   dsps_smsm_state_cb, 0);
	if (ret) {
		pr_err("%s: smsm_state_cb_register fail %d\n", __func__,
		       ret);
		goto smsm_register_err;
	}

	dsps_dev = subsys_register(&dsps_ssrops);
	if (IS_ERR(dsps_dev)) {
		ret = PTR_ERR(dsps_dev);
		pr_err("%s: subsys_register fail %d\n", __func__,
		       ret);
		goto ssr_register_err;
	}

	return 0;

ssr_register_err:
	smsm_state_cb_deregister(SMSM_DSPS_STATE, SMSM_RESET,
				 dsps_smsm_state_cb,
				 0);
smsm_register_err:
	cdev_del(drv->cdev);
cdev_add_err:
	kfree(drv->cdev);
cdev_alloc_err:
	device_destroy(drv->dev_class, drv->dev_num);
device_create_err:
	unregister_chrdev_region(drv->dev_num, 1);
alloc_chrdev_region_err:
	class_destroy(drv->dev_class);
res_err:
	kfree(drv);
	drv = NULL;
//.........这里部分代码省略.........
开发者ID:Arunvasu,项目名称:taoshan,代码行数:101,代码来源:msm_dsps.c

示例14: timing_dev_init

/* function called at module load time */
static int __init timing_dev_init(void) {

  int i, rc;
  dev_t dev_num;

 #if DEBUG != 0
  printk(KERN_DEBUG "timing_dev_init entry\n");
 #endif

  /* dynamically assign device number */
  rc = alloc_chrdev_region(&dev_num, FIRST_MINOR,
			   TIMING_DEV_COUNT, MODULE_NAME);
  if (rc) {
    printk(KERN_ALERT "Error allocating dev numbers - timing.c\n");
    return rc;
  }
  
  /* record major number */
  timing_maj_num = MAJOR(dev_num);

  /* set up individual data for each char dev */
  /*     for the 8 IO Ports                   */
  for ( i = 0; i < TIMING_DEV_COUNT; i++ ) {
    
    timing_card[i].offset = 0x00;

    /* device number */
    timing_card[i].num = MKDEV(timing_maj_num, FIRST_MINOR + i);

    /* part of device that this addresses */
    if ( i < TIMING_IOPORT_COUNT )
      timing_card[i].component = PCI7300_ID;
    else if ( i < TIMING_IOPORT_COUNT + TIMING_8254_COUNT )
      timing_card[i].component = TIMER8254_ID;
    else 
      timing_card[i].component = PLX9080_ID;
    
    /* vital driver structures */
    timing_card[i].driver = &timing_driver;
    timing_card[i].fops   = &timing_fops  ;

    /* set up actual cdev */
    cdev_init(&timing_card[i].cdev, &timing_fops);
    timing_card[i].cdev.owner = THIS_MODULE;
    timing_card[i].cdev.ops = &timing_fops;

    /* actual cdev registration */ /* magic # 1 is "count" */
    rc = cdev_add(&timing_card[i].cdev, timing_card[i].num, 1);

    if ( rc < 0 ) {
      printk(KERN_ALERT "Error adding timing cdev %d to sys\n", i);
      goto del_cdev;
    }
  } /* end data initialization for IO port loop */
  
 #if DEBUG != 0
  printk(KERN_DEBUG "timing_dev_init() exit success\n");
 #endif

  /* finally, register as pci dev */
  /* END FLOW OF NORMAL OPERATION */
  return pci_register_driver(&timing_driver);

  /* ERROR HANDLING */
 del_cdev:

  /* unregister char drivers */
  unregister_chrdev_region(dev_num, TIMING_DEV_COUNT);

  /* delete the cdevs that succeeded (up to i) */
  for ( ; !(i < 0); i-- )
    cdev_del(&timing_card[i].cdev);

  return rc;
} /* end timing_init */
开发者ID:kerb-huang,项目名称:timing_driver,代码行数:76,代码来源:timing.c

示例15: dev_release

/*文件释放函数*/
static int dev_release(struct inode *inode, struct file *filp){	cdev_del(&mydevice->cdev); 	/*注销cdev*/

	printk(KERN_INFO "mydev closed!\n");
	return 0;
}
开发者ID:nope8,项目名称:linux-driver,代码行数:6,代码来源:i2c.c


注:本文中的cdev_del函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。