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: <CAD++jLmFAKhhjtQQ1GHrV+RBa8MBtw9q=OdbVx2Vnoji6-ESqA@mail.gmail.com>
Date: Tue, 27 Jan 2026 10:46:01 +0100
From: Linus Walleij <linusw@...nel.org>
To: Jie Li <lj29312931@...il.com>
Cc: wsa@...nel.org, linus.walleij@...aro.org, linux-i2c@...r.kernel.org, 
	linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org, 
	Jie Li <jie.i.li@...ia.com>
Subject: Re: [PATCH v2 1/2] gpiolib: add gpiod_is_single_ended() helper

On Sun, Jan 25, 2026 at 8:51 PM Jie Li <lj29312931@...il.com> wrote:

> The direction of a single-ended (open-drain or open-source) GPIO line
> cannot always be reliably determined by reading hardware registers.
> In true open-drain implementations, the "high" state is achieved by
> entering a high-impedance mode, which many hardware controllers report
> as "input" even if the software intends to use it as an output.
>
> This creates issues for consumer drivers (like I2C) that rely on
> gpiod_get_direction() to decide if a line can be driven.
>
> Introduce gpiod_is_single_ended() to allow consumers to check the
> software configuration (GPIO_FLAG_OPEN_DRAIN/GPIO_FLAG_OPEN_SOURCE) of
> a descriptor. This provides a robust way to identify lines that are
> capable of being driven, regardless of their instantaneous hardware state.
>
> Signed-off-by: Jie Li <jie.i.li@...ia.com>

This makes sense!

> +/**
> + * gpiod_is_single_ended - check if the GPIO is configured as single-ended
> + * @desc: the GPIO descriptor to check
> + *
> + * Returns true if the GPIO is configured as either Open Drain or Open Source.
> + * In these modes, the direction of the line cannot always be reliably
> + * determined by reading hardware registers, as the "off" state (High-Z)
> + * is physically indistinguishable from an input state.
> + */
> +int gpiod_is_single_ended(struct gpio_desc *desc)

Switch to bool
bool gpiod_is_single_ended(struct gpio_desc *desc)

> +{
> +       if (!desc)
> +               return 0;

return false;

> +
> +       if (test_bit(GPIOD_FLAG_OPEN_DRAIN, &desc->flags) ||
> +               test_bit(GPIOD_FLAG_OPEN_SOURCE, &desc->flags))
> +               return 1;

return true;

> +
> +       return 0;

return false;


> +static inline int gpiod_is_single_ended(struct gpio_desc *desc)
> +{
> +       return 0;
> +}

bool

return false;

Yours,
Linus Walleij

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ