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] [day] [month] [year] [list]
Message-ID: <aN7hxUz7TGG38Hv_@stanley.mountain>
Date: Thu, 2 Oct 2025 23:34:13 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Mary Strodl <mstrodl@....rit.edu>
Cc: linux-kernel@...r.kernel.org, tzungbi@...nel.org,
	linus.walleij@...aro.org, brgl@...ev.pl, linux-gpio@...r.kernel.org
Subject: Re: [PATCH v3 3/4] gpio: mpsse: add quirk support

On Thu, Oct 02, 2025 at 02:11:35PM -0400, Mary Strodl wrote:
> Builds out a facility for specifying compatible lines directions and
> labels for MPSSE-based devices.
> 
> * dir_in/out are bitmask of lines that can go in/out. 0 means
>   compatible, 1 means incompatible. This is convenient, because it means
>   if the struct is zeroed out, it supports all pins.

What?  No, please make 1 be supported and 0 be not supported.  This
really weirded me out when I read the code.  If it were just 1 for
true and 0 for false a lot of comments regarding dir_in/out could be
removed because the code would be straight forward.

You can easily set everything to 1 by assigning -1 or using memset().

> * names is an array of line names which will be exposed to userspace.
> 
> Also changes the chip label format to include some more useful
> information about the device to help identify it from userspace.
> 
> Signed-off-by: Mary Strodl <mstrodl@....rit.edu>
> ---
>  drivers/gpio/gpio-mpsse.c | 109 ++++++++++++++++++++++++++++++++++++--
>  1 file changed, 106 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-mpsse.c b/drivers/gpio/gpio-mpsse.c
> index 6ec940f6b371..c2a344488a23 100644
> --- a/drivers/gpio/gpio-mpsse.c
> +++ b/drivers/gpio/gpio-mpsse.c
> @@ -29,6 +29,9 @@ struct mpsse_priv {
>  	u8 gpio_outputs[2];	     /* Output states for GPIOs [L, H] */
>  	u8 gpio_dir[2];		     /* Directions for GPIOs [L, H] */
>  
> +	unsigned long dir_in;        /* Bitmask of valid input pins  */
> +	unsigned long dir_out;       /* Bitmask of valid output pins */
> +
>  	u8 *bulk_in_buf;	     /* Extra recv buffer to grab status bytes */
>  
>  	struct usb_endpoint_descriptor *bulk_in;
> @@ -54,6 +57,14 @@ struct bulk_desc {
>  	int timeout;
>  };
>  
> +#define MPSSE_NGPIO 16
> +
> +struct mpsse_quirk {
> +	const char   *names[MPSSE_NGPIO]; /* Pin names, if applicable     */
> +	unsigned long dir_in;             /* Bitmask of valid input pins  */
> +	unsigned long dir_out;            /* Bitmask of valid output pins */
> +};
> +
>  static const struct usb_device_id gpio_mpsse_table[] = {
>  	{ USB_DEVICE(0x0c52, 0xa064) },   /* SeaLevel Systems, Inc. */
>  	{ }                               /* Terminating entry */
> @@ -171,6 +182,32 @@ static int gpio_mpsse_get_bank(struct mpsse_priv *priv, u8 bank)
>  	return buf;
>  }
>  
> +static int mpsse_ensure_supported(struct gpio_chip *chip,
> +				  unsigned long *mask, int direction)

Just pass mask not a pointer to mask.  It would be different if
you were going to allow more than 32 bits to be set, then we would
need to pass a pointer and use set_bit() etc...

> +{
> +	unsigned long supported, unsupported;
> +	char *type = "input";
> +	struct mpsse_priv *priv = gpiochip_get_data(chip);
> +
> +	supported = priv->dir_in;
> +	if (direction == GPIO_LINE_DIRECTION_OUT) {
> +		supported = priv->dir_out;
> +		type = "output";
> +	}
> +
> +	/* An invalid bit was in the provided mask */
> +	unsupported = *mask & supported;
> +	if (unsupported) {
> +		dev_err(&priv->udev->dev,
> +			"mpsse: GPIO %d doesn't support %s\n",
> +			(int)find_first_bit(&unsupported, sizeof(unsupported) * 8),

Use %lu instead of %d and get rid of the unnecessary cast.

> +			type);
> +		return -EOPNOTSUPP;
> +	}
> +
> +	return 0;
> +}

regards,
dan carpenter


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ