[PATCH v4 12/13] fsi: i2cr: Replace open-coded parity calculation with parity_odd()

Kuan-Wei Chiu
2025-05-15T09:20:19Z

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/fsi/fsi-master-i2cr.c | 20 +++-----------------
1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/drivers/fsi/fsi-master-i2cr.c b/drivers/fsi/fsi-master-i2cr.c
index 40f1f4d231e5..692d73e892e3 100644
--- a/drivers/fsi/fsi-master-i2cr.c
+++ b/drivers/fsi/fsi-master-i2cr.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) IBM Corporation 2023 */

+#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/fsi.h>
#include <linux/i2c.h>
@@ -38,27 +39,12 @@ static const u8 i2cr_cfam[] = {

static bool i2cr_check_parity32(u32 v, bool parity)
{
- u32 i;
-
- for (i = 0; i < 32; ++i) {
- if (v & (1u << i))
- parity = !parity;
- }
-
- return parity;
+ return parity != parity_odd(v);
}

static bool i2cr_check_parity64(u64 v)
{
- u32 i;
- bool parity = I2CR_INITIAL_PARITY;
-
- for (i = 0; i < 64; ++i) {
- if (v & (1llu << i))
- parity = !parity;
- }
-
- return parity;
+ return parity_odd(v) != I2CR_INITIAL_PARITY;
}

static u32 i2cr_get_command(u32 address, bool parity)
--
2.34.1