{"id":8906,"date":"2022-04-08T04:18:18","date_gmt":"2022-04-08T04:18:18","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=8906"},"modified":"2023-01-16T15:59:01","modified_gmt":"2023-01-16T10:29:01","slug":"linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/","title":{"rendered":"Linux Device Driver Programming Lecture 52| Pcd driver with multiple devices code implementation part-4"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 28px;\"><strong><span style=\"color: #000080;\">Pcd driver with multiple devices code implementation part-4<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s continue our discussion on this pcd_driver_init. We almost completed this init function, but we have to fix this a clean up things.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">First of all, let&#8217;s start from the beginning.&nbsp;<\/span><\/p>\n<figure id=\"attachment_8909\" aria-describedby=\"caption-attachment-8909\" style=\"width: 512px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-8909\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-1-2.png\" alt=\"Figure 1.if class_create fails \" width=\"512\" height=\"290\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2.png 512w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2-300x170.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2-120x68.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2-500x283.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2-200x113.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2-400x227.png 400w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><figcaption id=\"caption-attachment-8909\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. if class_create fails<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, if here, the alloc_chrdev_region fails, then goto out.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And the next one is, if class_create fails, then you have to clean up what you did here. That&#8217;s why I would give the label here unreg_chrdev, as shown in Figure 1.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, let&#8217;s implement that unreg_chrdev. Here it is. unregister_chrdev_region of number of devices as shown in Figure 2.<\/span><\/p>\n<figure id=\"attachment_8910\" aria-describedby=\"caption-attachment-8910\" style=\"width: 847px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-8910\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-2-2.png\" alt=\"Figure 2.unreg_chrdev implementation\" width=\"847\" height=\"389\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2.png 847w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-300x138.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-768x353.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-600x276.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-500x230.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-400x184.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-2-800x367.png 800w\" sizes=\"(max-width: 847px) 100vw, 847px\" \/><figcaption id=\"caption-attachment-8910\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. unreg_chrdev implementation<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, here is cdev_add, as shown in Figure 3.<\/span><\/p>\n<figure id=\"attachment_8911\" aria-describedby=\"caption-attachment-8911\" style=\"width: 850px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-8911\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-3-1.png\" alt=\"Figure 3. cdev_add\" width=\"850\" height=\"389\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1.png 850w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-300x137.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-768x351.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-600x275.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-500x229.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-400x183.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-1-800x366.png 800w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><figcaption id=\"caption-attachment-8911\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. cdev_add<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">cdev_add actually executes multiple times. Because, let&#8217;s say if this is a loop of 4, then there will be four passes. The cdev_add can fail at any pass of the loop. The same is true for&nbsp; device_create. This also can fail at any pass of the loop.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, we&#8217;ll do something like this. It doesn&#8217;t matter at which pass these APIs fail; you just cleanup for all number of devices.<\/span><\/p>\n<figure id=\"attachment_8912\" aria-describedby=\"caption-attachment-8912\" style=\"width: 850px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8912\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-4-1.png\" alt=\"Figure 4. cdev_del label creation\" width=\"850\" height=\"389\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1.png 850w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-300x137.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-768x351.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-600x275.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-500x229.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-400x183.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-1-800x366.png 800w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><figcaption id=\"caption-attachment-8912\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. cdev_del label creation<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That&#8217;s why, what I write here is, let me create a label cdev_del, as shown in Figure 4.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_8913\" aria-describedby=\"caption-attachment-8913\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8913\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-5-1.png\" alt=\"Figure 5.class_del label creation\" width=\"849\" height=\"384\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1.png 849w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-300x136.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-768x347.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-600x271.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-120x54.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-500x226.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-200x90.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-400x181.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-1-800x362.png 800w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><figcaption id=\"caption-attachment-8913\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. class_del label creation<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And here let me write the label class_del. If any of these API fails, then will cleanup for all devices. That&#8217;s why what I do here is, let me write cdev_del here.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And let me first write cdev_del and class_del as shown in Figure 6.<\/span><\/p>\n<figure id=\"attachment_8914\" aria-describedby=\"caption-attachment-8914\" style=\"width: 851px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8914\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-6-1.png\" alt=\" Figure 6. cdev_del and class_del label implementation\" width=\"851\" height=\"386\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1.png 851w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-300x136.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-768x348.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-600x272.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-120x54.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-500x227.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-200x91.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-400x181.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-1-800x363.png 800w\" sizes=\"(max-width: 851px) 100vw, 851px\" \/><figcaption id=\"caption-attachment-8914\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. cdev_del and class_del label implementation<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If cdev_add fails, then you have to execute cleanup for both cdev_add and device_create. For that, I would like to use a loop, and I would start cleaning up from the current value of i,&nbsp; that&#8217;s a loop variable. That&#8217;s why I would just give a semicolon here.&nbsp; i&gt;=0, i&#8211;. I go in reverse. First, I would do device_destroy. And after that, I would do cdev_del. And after that, that is class_destroy. This will be our cleanup.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">It doesn&#8217;t matter at what pass or at what stage you fail, you have to clean up everything.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s complete this device_destroy. Let me just search for device_destroy as in Figure 7.<\/span><\/p>\n<figure id=\"attachment_8915\" aria-describedby=\"caption-attachment-8915\" style=\"width: 852px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8915\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-7-1.png\" alt=\"Figure 7. Device_destroy function\" width=\"852\" height=\"390\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1.png 852w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-300x137.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-768x352.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-600x275.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-500x229.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-400x183.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-1-800x366.png 800w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><figcaption id=\"caption-attachment-8915\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Device_destroy function<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You just have to give the class and this dev_t information. dev_t here is the device that was previously registered.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the device was not previously registered, suppose if you pass an invalid value here(dev_t devt). That means if you are trying to do a device destroy without being previously registered or created using&nbsp; device_create.&nbsp; Then, there will be no effect in this API below.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For example, if this(devt) value is invalid, then class_find_device function here would return this (dev) as NULL. That&#8217;s why, if this dev is null, then this code block has no effect.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #ff0000;\">if(dev){<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #ff0000;\">put_device(dev)<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 29px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #ff0000;\">device_unregister(dev);<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #ff0000;\">}<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That&#8217;s why you can call a device_destroy&nbsp; on an invalid device number. You can do that.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, we have to use a class pointer pcdrv_data. This will be class_pcd,&nbsp; the device_number. The device_number is&nbsp; pcdrv_data.device_number+i, as shown in Figure 8.<\/span><\/p>\n<figure id=\"attachment_8916\" aria-describedby=\"caption-attachment-8916\" style=\"width: 844px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8916\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-8-1.png\" alt=\"Figure 8. Device_destroy implementation in our code\" width=\"844\" height=\"308\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1.png 844w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-300x109.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-768x280.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-600x219.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-120x44.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-500x182.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-200x73.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-400x146.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-1-800x292.png 800w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><figcaption id=\"caption-attachment-8916\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Device_destroy implementation in our code<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, cdev_del(shown in Figure 9). Here you have to give the cdev address. Remove a cdev from the system.&nbsp;<\/span><\/p>\n<figure id=\"attachment_8917\" aria-describedby=\"caption-attachment-8917\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8917 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-9-1.png\" alt=\"Pcd driver with multiple devices code implementation\" width=\"849\" height=\"371\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1.png 849w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-300x131.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-768x336.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-600x262.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-120x52.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-500x218.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-200x87.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-400x175.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-1-800x350.png 800w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><figcaption id=\"caption-attachment-8917\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. cdev_del<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the cdev is not present on the system, then there will be no effect in calling this API.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, you just have to pass the address pcdrv_data.pcdev_data[i].cdev.<\/span><\/p>\n<figure id=\"attachment_8918\" aria-describedby=\"caption-attachment-8918\" style=\"width: 848px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8918 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-10-1.png\" alt=\"Pcd driver with multiple devices code implementation\" width=\"848\" height=\"390\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1.png 848w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-300x138.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-768x353.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-600x276.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-500x230.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-400x184.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-1-800x368.png 800w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><figcaption id=\"caption-attachment-8918\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. cdev_del function implementation in our code<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, class_destroy.<\/span><\/p>\n<figure id=\"attachment_8919\" aria-describedby=\"caption-attachment-8919\" style=\"width: 848px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8919 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-11-1.png\" alt=\"Pcd driver with multiple devices code implementation\" width=\"848\" height=\"370\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1.png 848w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-300x131.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-768x335.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-600x262.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-120x52.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-500x218.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-200x87.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-400x175.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-1-800x349.png 800w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><figcaption id=\"caption-attachment-8919\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. class_destroy<\/span><\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p class=\"\"><span style=\"font-weight: 400; color: #000000;\">Just have to pass the pointer.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">&nbsp;So class_destroy (pcdrv_data.class_pcd) as shown in Figure 12.<\/span><\/p>\n<figure id=\"attachment_8920\" aria-describedby=\"caption-attachment-8920\" style=\"width: 847px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8920 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-12-1.png\" alt=\"Pcd driver with multiple devices code implementation\" width=\"847\" height=\"375\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1.png 847w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-300x133.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-768x340.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-600x266.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-120x53.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-500x221.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-200x89.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-400x177.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-1-800x354.png 800w\" sizes=\"(max-width: 847px) 100vw, 847px\" \/><figcaption id=\"caption-attachment-8920\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 12. Class_destroy implementation in our code<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That completes our cleanup procedure, now, let&#8217;s save and quit. And let&#8217;s check this code.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s code for our cleanup.<\/span><\/p>\n<figure id=\"attachment_8921\" aria-describedby=\"caption-attachment-8921\" style=\"width: 844px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8921 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-13-1.png\" alt=\"Pcd driver with multiple devices code implementation\" width=\"844\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1.png 844w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-300x141.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-768x360.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-600x282.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-120x56.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-500x235.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-200x94.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-400x188.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-1-800x375.png 800w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><figcaption id=\"caption-attachment-8921\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 13. Cleanup function<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Save and Compile it.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We completed the init and cleanup functions of our exercise and try to complete up to here. And in the following article, let&#8217;s start implementing the driver methods. I&#8217;ll see you in the next article.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 27px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span><span style=\"color: #0000ff;\">&nbsp;<\/span><\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Pcd driver with multiple devices code implementation part-4 &nbsp; &nbsp; Let&#8217;s continue our discussion on this pcd_driver_init. We almost completed this init function, but we have to fix this a clean up things. First of all, let&#8217;s start from the beginning.&nbsp; &nbsp; So, if here, the alloc_chrdev_region fails, then goto out. And the next [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8909,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[18],"class_list":["post-8906","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-linux-device-driver-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pcd driver with multiple devices code implementation part-4<\/title>\n<meta name=\"description\" content=\"Pcd driver with multiple devices code implementation part-4. If here, the alloc_chrdev_region fails, then goto out. If class_create fails,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pcd driver with multiple devices code implementation part-4\" \/>\n<meta property=\"og:description\" content=\"Pcd driver with multiple devices code implementation part-4. If here, the alloc_chrdev_region fails, then goto out. If class_create fails,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-08T04:18:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-16T10:29:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"290\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Linux Device Driver Programming Lecture 52| Pcd driver with multiple devices code implementation part-4\",\"datePublished\":\"2022-04-08T04:18:18+00:00\",\"dateModified\":\"2023-01-16T10:29:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/\"},\"wordCount\":907,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-1-2.png\",\"keywords\":[\"Linux Device Driver Programming Tutorial\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/\",\"name\":\"Pcd driver with multiple devices code implementation part-4\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-1-2.png\",\"datePublished\":\"2022-04-08T04:18:18+00:00\",\"dateModified\":\"2023-01-16T10:29:01+00:00\",\"description\":\"Pcd driver with multiple devices code implementation part-4. If here, the alloc_chrdev_region fails, then goto out. If class_create fails,\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-1-2.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-1-2.png\",\"width\":512,\"height\":290,\"caption\":\"Figure 1.if class_create fails\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Device Driver Programming Lecture 52| Pcd driver with multiple devices code implementation part-4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pcd driver with multiple devices code implementation part-4","description":"Pcd driver with multiple devices code implementation part-4. If here, the alloc_chrdev_region fails, then goto out. If class_create fails,","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/","og_locale":"en_US","og_type":"article","og_title":"Pcd driver with multiple devices code implementation part-4","og_description":"Pcd driver with multiple devices code implementation part-4. If here, the alloc_chrdev_region fails, then goto out. If class_create fails,","og_url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-04-08T04:18:18+00:00","article_modified_time":"2023-01-16T10:29:01+00:00","og_image":[{"width":512,"height":290,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Linux Device Driver Programming Lecture 52| Pcd driver with multiple devices code implementation part-4","datePublished":"2022-04-08T04:18:18+00:00","dateModified":"2023-01-16T10:29:01+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/"},"wordCount":907,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2.png","keywords":["Linux Device Driver Programming Tutorial"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/","url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/","name":"Pcd driver with multiple devices code implementation part-4","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2.png","datePublished":"2022-04-08T04:18:18+00:00","dateModified":"2023-01-16T10:29:01+00:00","description":"Pcd driver with multiple devices code implementation part-4. If here, the alloc_chrdev_region fails, then goto out. If class_create fails,","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-2.png","width":512,"height":290,"caption":"Figure 1.if class_create fails"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-52-pcd-driver-with-multiple-devices-code-implementation-part-4\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Device Driver Programming Lecture 52| Pcd driver with multiple devices code implementation part-4"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=8906"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8906\/revisions"}],"predecessor-version":[{"id":12804,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8906\/revisions\/12804"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/8909"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=8906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=8906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=8906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}