c
// Add a mutex to the gpio_chardev_data struct
struct gpio_chardev_data {
  // ...
  struct mutex watched_lines_mutex;
};

// Initialize the mutex
mutex_init(&cdev->watched_lines_mutex);

// Lock the mutex before freeing memory
6  mutex_lock(&cdev->watched_lines_mutex);
7  if (cdev->watched_lines != NULL) {
8    bitmap_free(cdev->watched_lines);
9  }
10 mutex_unlock(&cdev->watched_lines_mutex);
