Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbff8884 authored by Matti Vaittinen's avatar Matti Vaittinen Committed by Greg Kroah-Hartman
Browse files

gpio: sysfs: Obey valid_mask



[ Upstream commit 23cf00ddd2e1aacf1873e43f5e0c519c120daf7a ]

Do not allow exporting GPIOs which are set invalid
by the driver's valid mask.

Fixes: 726cb3ba ("gpiolib: Support 'gpio-reserved-ranges' property")
Signed-off-by: default avatarMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 8525c748
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -462,6 +462,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)
@@ -473,6 +475,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