diff mbox series

[v3,10/21] gpio: add function check_dir_flags

Message ID 20200113103515.20879-11-patrick.delaunay@st.com
State Accepted
Commit 4292fb16bff1af883b98517b73ea8f7cbfee948f
Headers show
Series dm: add support of new binding in gpio and pincontrol | expand

Commit Message

Patrick Delaunay Jan. 13, 2020, 10:35 a.m. UTC
Add a dir flags validity check with a new function
check_dir_flags.

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags


Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Simon Glass Jan. 30, 2020, 2:18 a.m. UTC | #1
On Mon, 13 Jan 2020 at 03:35, Patrick Delaunay <patrick.delaunay at st.com> wrote:
>
> Add a dir flags validity check with a new function
> check_dir_flags.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
> ---
>
> This patch was part of v2 08/14
> = gpio: add ops for configuration with dir flags
>
>
> Changes in v3:
> - Split the previous patch [PATCH v2 08/14] to help review
>
> Changes in v2: None
>
>  drivers/gpio/gpio-uclass.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)

Reviewed-by: Simon Glass <sjg at chromium.org>
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 94e90cb8ac..62462dffa5 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -510,12 +510,36 @@  int dm_gpio_set_value(const struct gpio_desc *desc, int value)
 	return 0;
 }
 
+/* check dir flags invalid configuration */
+static int check_dir_flags(ulong flags)
+{
+	if ((flags & GPIOD_IS_OUT) && (flags & GPIOD_IS_IN)) {
+		log_debug("%s: flags 0x%lx has GPIOD_IS_OUT and GPIOD_IS_IN\n",
+			  __func__, flags);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 {
 	struct udevice *dev = desc->dev;
 	struct dm_gpio_ops *ops = gpio_get_ops(dev);
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 	int ret = 0;
 
+	ret = check_dir_flags(flags);
+	if (ret) {
+		dev_dbg(dev,
+			"%s error: set_dir_flags for gpio %s%d has invalid dir flags 0x%lx\n",
+			desc->dev->name,
+			uc_priv->bank_name ? uc_priv->bank_name : "",
+			desc->offset, flags);
+
+		return ret;
+	}
+
 	if (flags & GPIOD_IS_OUT) {
 		int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;