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: <CAOiHx==y-4Jjckr-KnwdmJhi=TR9_wzcHvNo8GAeUmJ43Y_bHw@mail.gmail.com>
Date: Fri, 28 Nov 2025 20:30:43 +0100
From: Jonas Gorski <jonas.gorski@...il.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Prajna Rajendra Kumar <prajna.rajendrakumar@...rochip.com>, Mark Brown <broonie@...nel.org>, 
	linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 2/2] spi: microchip-core: use XOR instead of ANDNOT to
 simplify the logic

On Fri, Nov 28, 2025 at 7:56 PM Andy Shevchenko
<andriy.shevchenko@...ux.intel.com> wrote:
>
> Use XOR instead of ANDNOT to simplify the logic. The current approach
> with (foo & BAR & ~baz) is harder to process than more usual pattern
> for the comparing misconfiguration using ((foo ^ baz) & BAR) which
> can be read as "find all different bits between foo and baz that are
> related to BAR (mask)". Besides that it makes binary code shorter.
>
> Function                                     old     new   delta
> mchp_corespi_setup                           103      99      -4
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> ---
>  drivers/spi/spi-microchip-core-spi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c
> index 98bf0e6cd00e..2f4b21ad56a7 100644
> --- a/drivers/spi/spi-microchip-core-spi.c
> +++ b/drivers/spi/spi-microchip-core-spi.c
> @@ -161,7 +161,7 @@ static int mchp_corespi_setup(struct spi_device *spi)
>                 return -EOPNOTSUPP;
>         }
>
> -       if (spi->mode & SPI_MODE_X_MASK & ~spi->controller->mode_bits) {
> +       if ((spi->mode ^ spi->controller->mode_bits) & SPI_MODE_X_MASK) {

This changes the behavior: if a bit isn't set in spi->mode that is set
in mode_bits, it would have been previously accepted, now it's
refused. E.g. controller has (SPI_CPOL | SPI_CPHA), device only
SPI_CPOL. 0x1 & 0x3 & ~0x3 => 0, vs (0x1 ^ 0x3) & 0x3 => 0x2

If this is the actually intended behavior here, it is a fix and should
carry a Fixes tag (the message below implies that).

>                 dev_err(&spi->dev, "incompatible CPOL/CPHA, must match controller's Motorola mode\n");
>                 return -EINVAL;
>         }

Best regards,
Jonas

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ