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: <20240325120952.3019767-2-andriy.shevchenko@linux.intel.com>
Date: Mon, 25 Mar 2024 14:07:42 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Guenter Roeck <linux@...ck-us.net>,
	Patrick Rudolph <patrick.rudolph@...ements.com>,
	linux-hwmon@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: Jean Delvare <jdelvare@...e.com>,
	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: [PATCH v1 1/3] hwmon: (pmbus/mp2975) Replace home made version of __assign_bit()

The newly introduced SWAP() macro is quite generic by naming, but
moreover it's a repetition of the existing __assign_bit().
With this applied, add a missing bits.h (via now required bitops.h).

Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
 drivers/hwmon/pmbus/mp2975.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c
index 953c02a2aeb5..af118087c4ee 100644
--- a/drivers/hwmon/pmbus/mp2975.c
+++ b/drivers/hwmon/pmbus/mp2975.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2020 Nvidia Technologies Ltd.
  */
 
+#include <linux/bitops.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
@@ -396,7 +397,7 @@ static int mp2973_write_word_data(struct i2c_client *client, int page,
 				  int reg, u16 word)
 {
 	u8 target, mask;
-	int ret;
+	long ret;
 
 	if (reg != PMBUS_SMBALERT_MASK)
 		return -ENODATA;
@@ -415,7 +416,6 @@ static int mp2973_write_word_data(struct i2c_client *client, int page,
  * Set/Clear 'bit' in 'ret' based on condition followed by define for each bit in SMBALERT_MASK.
  * Also bit 2 & 15 are reserved.
  */
-#define SWAP(val, mask, cond, bit) (((mask) & (cond)) ? ((val) & ~BIT(bit)) : ((val) | BIT(bit)))
 
 #define MP2973_TEMP_OT		0
 #define MP2973_VIN_UVLO		1
@@ -434,36 +434,35 @@ static int mp2973_write_word_data(struct i2c_client *client, int page,
 
 	switch (target) {
 	case PMBUS_STATUS_CML:
-		ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_DATA, MP2973_INVALID_DATA);
-		ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_COMMAND,  MP2973_INVALID_COMMAND);
-		ret = SWAP(ret, mask, PB_CML_FAULT_OTHER_COMM, MP2973_OTHER_COMM);
-		ret = SWAP(ret, mask, PB_CML_FAULT_PACKET_ERROR, MP2973_PACKET_ERROR);
+		__assign_bit(MP2973_INVALID_DATA, &ret, !(mask & PB_CML_FAULT_INVALID_DATA));
+		__assign_bit(MP2973_INVALID_COMMAND, &ret, !(mask & PB_CML_FAULT_INVALID_COMMAND));
+		__assign_bit(MP2973_OTHER_COMM, &ret, !(mask & PB_CML_FAULT_OTHER_COMM));
+		__assign_bit(MP2973_PACKET_ERROR, &ret, !(mask & PB_CML_FAULT_PACKET_ERROR));
 		break;
 	case PMBUS_STATUS_VOUT:
-		ret = SWAP(ret, mask, PB_VOLTAGE_UV_FAULT, MP2973_VOLTAGE_UV);
-		ret = SWAP(ret, mask, PB_VOLTAGE_OV_FAULT, MP2973_VOLTAGE_OV);
+		__assign_bit(MP2973_VOLTAGE_UV, &ret, !(mask & PB_VOLTAGE_UV_FAULT));
+		__assign_bit(MP2973_VOLTAGE_OV, &ret, !(mask & PB_VOLTAGE_OV_FAULT));
 		break;
 	case PMBUS_STATUS_IOUT:
-		ret = SWAP(ret, mask, PB_IOUT_OC_FAULT, MP2973_IOUT_OC);
-		ret = SWAP(ret, mask, PB_IOUT_OC_LV_FAULT, MP2973_IOUT_OC_LV);
+		__assign_bit(MP2973_IOUT_OC, &ret, !(mask & PB_IOUT_OC_FAULT));
+		__assign_bit(MP2973_IOUT_OC_LV, &ret, !(mask & PB_IOUT_OC_LV_FAULT));
 		break;
 	case PMBUS_STATUS_TEMPERATURE:
-		ret = SWAP(ret, mask, PB_TEMP_OT_FAULT, MP2973_TEMP_OT);
+		__assign_bit(MP2973_TEMP_OT, &ret, !(mask & PB_TEMP_OT_FAULT));
 		break;
 	/*
 	 * Map remaining bits to MFR specific to let the PMBUS core mask
 	 * those bits by default.
 	 */
 	case PMBUS_STATUS_MFR_SPECIFIC:
-		ret = SWAP(ret, mask, BIT(1), MP2973_VIN_UVLO);
-		ret = SWAP(ret, mask, BIT(3), MP2973_VIN_OVP);
-		ret = SWAP(ret, mask, BIT(4), MP2973_MTP_FAULT);
-		ret = SWAP(ret, mask, BIT(6), MP2973_MTP_BLK_TRIG);
+		__assign_bit(MP2973_VIN_UVLO, &ret, !(mask & BIT(1)));
+		__assign_bit(MP2973_VIN_OVP, &ret, !(mask & BIT(3)));
+		__assign_bit(MP2973_MTP_FAULT, &ret, !(mask & BIT(4)));
+		__assign_bit(MP2973_MTP_BLK_TRIG, &ret, !(mask & BIT(6)));
 		break;
 	default:
 		return 0;
 	}
-#undef SWAP
 
 	return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret);
 }
-- 
2.43.0.rc1.1.gbec44491f096


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ