lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210824164801.28896-7-lakshmi.sowjanya.d@intel.com>
Date:   Tue, 24 Aug 2021 22:17:47 +0530
From:   lakshmi.sowjanya.d@...el.com
To:     linus.walleij@...aro.org
Cc:     linux-gpio@...r.kernel.org, bgolaszewski@...libre.com,
        linux-kernel@...r.kernel.org, mgross@...ux.intel.com,
        andriy.shevchenko@...ux.intel.com, tamal.saha@...el.com,
        bala.senthil@...el.com, lakshmi.sowjanya.d@...el.com
Subject: [RFC PATCH v1 06/20] gpio: Add set_input and polling interface to GPIO lib code

From: Lakshmi Sowjanya D <lakshmi.sowjanya.d@...el.com>

Some Intel Timed I/O devices do not implement IRQ functionality. Augment
read() interface to allow polling.

Move input setup functionality to a separate function simplifying
linereq_create() to add output code in subsequent commit.

Co-developed-by: Christopher Hall <christopher.s.hall@...el.com>
Signed-off-by: Christopher Hall <christopher.s.hall@...el.com>
Signed-off-by: Tamal Saha <tamal.saha@...el.com>
Signed-off-by: Lakshmi Sowjanya D <lakshmi.sowjanya.d@...el.com>
Reviewed-by: Mark Gross <mgross@...ux.intel.com>
---
 drivers/gpio/gpiolib-cdev.c | 52 +++++++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 4741bf34750b..cb6b9155884c 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1331,6 +1331,52 @@ static const struct file_operations line_fileops = {
 #endif
 };
 
+static int setup_input(struct linereq *lr, struct gpio_v2_line_config *lc,
+		       u32 line_no, unsigned int offset, u32 lflags)
+{
+	int err, ret;
+
+	/* Only one bias flag can be set. */
+	if (((lflags & GPIO_V2_LINE_FLAG_BIAS_DISABLED) &&
+	     (lflags & (GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN |
+			GPIO_V2_LINE_FLAG_BIAS_PULL_UP))) ||
+	    ((lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN) &&
+	     (lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP)))
+		return -EINVAL;
+
+	if (lflags & GPIO_V2_LINE_FLAG_ACTIVE_LOW)
+		set_bit(FLAG_ACTIVE_LOW, &lr->lines[line_no].desc->flags);
+	if (lflags & GPIO_V2_LINE_FLAG_BIAS_DISABLED)
+		set_bit(FLAG_BIAS_DISABLE, &lr->lines[line_no].desc->flags);
+	if (lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN)
+		set_bit(FLAG_PULL_DOWN, &lr->lines[line_no].desc->flags);
+	if (lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP)
+		set_bit(FLAG_PULL_UP, &lr->lines[line_no].desc->flags);
+
+	err = gpiod_direction_input(lr->lines[line_no].desc);
+	if (err)
+		return err;
+
+	ret = edge_detector_setup(&lr->lines[line_no], lc, line_no,
+				  lflags & GPIO_V2_LINE_EDGE_FLAGS);
+	if (ret < 0) {
+		if (ret != -ENXIO) {
+			if (lr->gdev->chip->setup_poll &&
+			    lr->gdev->chip->setup_poll(lr->gdev->chip, offset,
+						       &lflags) == 0 &&
+			    lr->gdev->chip->do_poll)
+				ret = 0;
+			else
+				return -ENODEV;
+		} else {
+			return -ENODEV;
+		}
+	}
+
+	lr->lines[line_no].eflags = lflags;
+	return ret;
+}
+
 static int linereq_create(struct gpio_device *gdev, void __user *ip)
 {
 	struct gpio_v2_line_request ulr;
@@ -1423,12 +1469,8 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
 			if (ret)
 				goto out_free_linereq;
 		} else if (flags & GPIO_V2_LINE_FLAG_INPUT) {
-			ret = gpiod_direction_input(desc);
-			if (ret)
-				goto out_free_linereq;
+			ret = setup_input(lr, lc, i, offset, flags);
 
-			ret = edge_detector_setup(&lr->lines[i], lc, i,
-					flags & GPIO_V2_LINE_EDGE_FLAGS);
 			if (ret)
 				goto out_free_linereq;
 		}
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ