All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: viperboard: implement .get_direction()
@ 2026-12-05 16:52 YuanZhe Liu
  2026-12-05 17:03 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-12-05 16:52 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, stable, Bin Yu, Cheng Wen

The GPIO core warns in gpiochip_get_direction() when a user reads the
direction of an exported line and the chip does not provide the
.get_direction() callback:

  WARNING: CPU: 0 PID: 3996 at drivers/gpio/gpiolib.c:431
  gpiochip_get_direction
  gpiod_get_direction
  direction_show
  dev_attr_show
  sysfs_kf_seq_show

Reading the direction of an exported line is a normal operation, so it
must not emit a warning.

The viperboard driver already tracks the direction of every line in the
gpioa_out and gpiob_out bitmaps and its get() callbacks use them to tell
input from output lines. Report the tracked direction through
.get_direction() for both chips.

Fixes: 471e998c0e31 ("gpiolib: remove redundant callback check")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
 drivers/gpio/gpio-viperboard.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c
index b8d6dff5b663..432071a25383 100644
--- a/drivers/gpio/gpio-viperboard.c
+++ b/drivers/gpio/gpio-viperboard.c
@@ -252,6 +252,15 @@ static int vprbrd_gpioa_direction_output(struct gpio_chip *chip,
 	return 0;
 }
 
+static int vprbrd_gpioa_get_direction(struct gpio_chip *chip,
+				      unsigned int offset)
+{
+	struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
+
+	return (gpio->gpioa_out & (1 << offset)) ? GPIO_LINE_DIRECTION_OUT :
+						 GPIO_LINE_DIRECTION_IN;
+}
+
 /* ----- end of gpio a chip ---------------------------------------------- */
 
 /* ----- begin of gipo b chip -------------------------------------------- */
@@ -388,6 +397,15 @@ static int vprbrd_gpiob_direction_output(struct gpio_chip *chip,
 	return vprbrd_gpiob_set(chip, offset, value);
 }
 
+static int vprbrd_gpiob_get_direction(struct gpio_chip *chip,
+				      unsigned int offset)
+{
+	struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
+
+	return (gpio->gpiob_out & (1 << offset)) ? GPIO_LINE_DIRECTION_OUT :
+						 GPIO_LINE_DIRECTION_IN;
+}
+
 /* ----- end of gpio b chip ---------------------------------------------- */
 
 static int vprbrd_gpio_probe(struct platform_device *pdev)
@@ -412,6 +430,7 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
 	vb_gpio->gpioa.get = vprbrd_gpioa_get;
 	vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input;
 	vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output;
+	vb_gpio->gpioa.get_direction = vprbrd_gpioa_get_direction;
 
 	ret = devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpioa, vb_gpio);
 	if (ret < 0)
@@ -428,6 +447,7 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
 	vb_gpio->gpiob.get = vprbrd_gpiob_get;
 	vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input;
 	vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output;
+	vb_gpio->gpiob.get_direction = vprbrd_gpiob_get_direction;
 
 	return devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpiob, vb_gpio);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05 17:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 16:52 [PATCH] gpio: viperboard: implement .get_direction() YuanZhe Liu
2026-12-05 17:03 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.