Re: [PATCH v4 05/13] serial: max3100: Replace open-coded parity calculation with parity_odd()

Yury Norov
2025-05-15T09:20:25Z

On Wed, Apr 09, 2025 at 11:43:48PM +0800, Kuan-Wei Chiu wrote:
> Refactor parity calculations to use the standard parity_odd() helper.
> This change eliminates redundant implementations.
>
> Co-developed-by: Yu-Chun Lin <eleanor15x@gmail.com>
> Signed-off-by: Yu-Chun Lin <eleanor15x@gmail.com>
> Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
> ---
> drivers/tty/serial/max3100.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
> index f2dd83692b2c..36ed41eef7b1 100644
> --- a/drivers/tty/serial/max3100.c
> +++ b/drivers/tty/serial/max3100.c
> @@ -16,6 +16,7 @@
> /* 4 MAX3100s should be enough for everyone */
> #define MAX_MAX3100 4
>
> +#include <linux/bitops.h>
> #include <linux/container_of.h>
> #include <linux/delay.h>
> #include <linux/device.h>
> @@ -133,7 +134,7 @@ static int max3100_do_parity(struct max3100_port *s, u16 c)
> else
> c &= 0xff;
>
> - parity = parity ^ (hweight8(c) & 1);
> + parity = parity ^ parity_odd(c);

This can be simplified for more unless I misunderstand something...

From: Yury Norov <yury.norov@gmail.com>
Date: Wed Apr 9 13:22:04 2025 -0400

serial: max3100: Replace open-coded parity

diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index f2dd83692b2c..07d332b8e87d 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -121,20 +121,12 @@ static DEFINE_MUTEX(max3100s_lock); /* race on probe */

static int max3100_do_parity(struct max3100_port *s, u16 c)
{
- int parity;
-
- if (s->parity & MAX3100_PARITY_ODD)
- parity = 1;
- else
- parity = 0;
-
if (s->parity & MAX3100_7BIT)
c &= 0x7f;
else
c &= 0xff;

- parity = parity ^ (hweight8(c) & 1);
- return parity;
+ return s->parity & MAX3100_PARITY_ODD ? !parity(c) : parity(c);
}

static int max3100_check_parity(struct max3100_port *s, u16 c)