Patch "hwmon: (pmbus) Check PEC support before reading other registers" has been added to the 5.18-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    hwmon: (pmbus) Check PEC support before reading other registers

to the 5.18-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     hwmon-pmbus-check-pec-support-before-reading-other-r.patch
and it can be found in the queue-5.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit fde32f064433763dffa65b2019dc3953bb6a264a
Author: Adam Wujek <dev_public@xxxxxxxx>
Date:   Thu May 19 23:34:01 2022 +0000

    hwmon: (pmbus) Check PEC support before reading other registers
    
    [ Upstream commit d1baf7a3a3177d46a7149858beddb88a9eca7a54 ]
    
    Make sure that the support of PEC is determined before the read of other
    registers. Otherwise the validation of PEC can trigger an error on the read
    of STATUS_BYTE or STATUS_WORD registers.
    
    The problematic scenario is the following. A device with enabled PEC
    support is up and running and a kernel driver is loaded.
    Then the driver is unloaded (or device unbound), the HW device
    is reconfigured externally (e.g. by i2cset) to advertise itself as not
    supporting PEC. Without the move of the code, at the second load of
    the driver (or bind) the STATUS_BYTE or STATUS_WORD register is always
    read with PEC enabled, which is likely to cause a read error resulting
    with fail of a driver load (or bind).
    
    Signed-off-by: Adam Wujek <dev_public@xxxxxxxx>
    Link: https://lore.kernel.org/r/20220519233334.438621-1-dev_public@xxxxxxxx
    Fixes: 75d2b2b06bd84 ("hwmon: (pmbus) disable PEC if not enabled")
    Fixes: 4e5418f787ec5 ("hwmon: (pmbus_core) Check adapter PEC support")
    [groeck: Added Fixes: tags, dropped continuation line]
    Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 5a1796650f5b..86429bfa4847 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2308,6 +2308,21 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
 	struct device *dev = &client->dev;
 	int page, ret;
 
+	/*
+	 * Figure out if PEC is enabled before accessing any other register.
+	 * Make sure PEC is disabled, will be enabled later if needed.
+	 */
+	client->flags &= ~I2C_CLIENT_PEC;
+
+	/* Enable PEC if the controller and bus supports it */
+	if (!(data->flags & PMBUS_NO_CAPABILITY)) {
+		ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
+		if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK)) {
+			if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_PEC))
+				client->flags |= I2C_CLIENT_PEC;
+		}
+	}
+
 	/*
 	 * Some PMBus chips don't support PMBUS_STATUS_WORD, so try
 	 * to use PMBUS_STATUS_BYTE instead if that is the case.
@@ -2326,19 +2341,6 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
 		data->has_status_word = true;
 	}
 
-	/* Make sure PEC is disabled, will be enabled later if needed */
-	client->flags &= ~I2C_CLIENT_PEC;
-
-	/* Enable PEC if the controller and bus supports it */
-	if (!(data->flags & PMBUS_NO_CAPABILITY)) {
-		ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
-		if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK)) {
-			if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_PEC)) {
-				client->flags |= I2C_CLIENT_PEC;
-			}
-		}
-	}
-
 	/*
 	 * Check if the chip is write protected. If it is, we can not clear
 	 * faults, and we should not try it. Also, in that case, writes into



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux