-/* Warn when drivers omit gpio_request() calls -- legal but ill-advised
- * when setting direction, and otherwise illegal. Until board setup code
- * and drivers use explicit requests everywhere (which won't happen when
- * those calls have no teeth) we can't avoid autorequesting. This nag
- * message should motivate switching to explicit requests... so should
- * the weaker cleanup after faults, compared to gpio_request().
- *
- * NOTE: the autorequest mechanism is going away; at this point it's
- * only "legal" in the sense that (old) code using it won't break yet,
- * but instead only triggers a WARN() stack dump.
- */
-static int gpio_ensure_requested(struct gpio_desc *desc)
-{
- struct gpio_chip *chip = desc->chip;
- unsigned long flags;
- bool request = false;
- int err = 0;
-
- spin_lock_irqsave(&gpio_lock, flags);
-
- if (WARN(test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0,
- "autorequest GPIO-%d\n", desc_to_gpio(desc))) {
- if (!try_module_get(chip->owner)) {
- gpiod_err(desc, "%s: module can't be gotten\n",
- __func__);
- clear_bit(FLAG_REQUESTED, &desc->flags);
- /* lose */
- err = -EIO;
- goto end;
- }
- desc->label = "[auto]";
- /* caller must chip->request() w/o spinlock */
- if (chip->request)
- request = true;
- }
-
-end:
- spin_unlock_irqrestore(&gpio_lock, flags);
-
- if (request) {
- might_sleep_if(chip->can_sleep);
- err = chip->request(chip, gpio_chip_hwgpio(desc));
-
- if (err < 0) {
- gpiod_dbg(desc, "%s: chip request fail, %d\n",
- __func__, err);
- spin_lock_irqsave(&gpio_lock, flags);
-
- desc->label = NULL;
- clear_bit(FLAG_REQUESTED, &desc->flags);
-
- spin_unlock_irqrestore(&gpio_lock, flags);
- }
- }
-
- return err;
-}
-