c
static int gpio_chrdev_release(struct inode *inode, struct file *file)
{
	struct gpio_chardev_data *cdev = file->private_data;
	struct gpio_device *gdev = cdev->gdev;
    
	// Patch Option 4:  Reorder deallocation (if logically possible)
    // Free cdev after other resources are released
	bitmap_free(cdev->watched_lines); 
	blocking_notifier_chain_unregister(&gdev->device_notifier,
					   &cdev->device_unregistered_nb);
	blocking_notifier_chain_unregister(&gdev->line_state_notifier,
					   &cdev->lineinfo_changed_nb);
	gpio_device_put(gdev);
    // Now it's safer to free cdev, as nothing should be accessing it anymore 
	kfree(cdev); 

	return 0;
}
