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 2: Conditional freeing (if already not freed)
	if (cdev->watched_lines != NULL) {
	    bitmap_free(cdev->watched_lines);
	    cdev->watched_lines = NULL; 
	} 

	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);
	kfree(cdev);

	return 0;
}
