Commit 33f0d9d9 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'gpio-fixes-for-v5.12-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio fix from Bartosz Golaszewski:
 "A single fix for an older problem with the sysfs interface: do not
  allow exporting GPIO lines which were marked invalid by the driver"

* tag 'gpio-fixes-for-v5.12-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux:
  gpio: sysfs: Obey valid_mask
parents e7e3a53b 23cf00dd
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -458,6 +458,8 @@ static ssize_t export_store(struct class *class,
	long			gpio;
	struct gpio_desc	*desc;
	int			status;
	struct gpio_chip	*gc;
	int			offset;

	status = kstrtol(buf, 0, &gpio);
	if (status < 0)
@@ -469,6 +471,12 @@ static ssize_t export_store(struct class *class,
		pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
		return -EINVAL;
	}
	gc = desc->gdev->chip;
	offset = gpio_chip_hwgpio(desc);
	if (!gpiochip_line_is_valid(gc, offset)) {
		pr_warn("%s: GPIO %ld masked\n", __func__, gpio);
		return -EINVAL;
	}

	/* No extra locking here; FLAG_SYSFS just signifies that the
	 * request and export were done by on behalf of userspace, so