From: Sasha Levin Date: Sun, 22 Dec 2024 04:32:16 +0000 (-0500) Subject: Fixes for 6.1 X-Git-Tag: v6.1.122~35^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d24642a64b3b92f8afd63aabe4fbf5d162b56d85;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 6.1 Signed-off-by: Sasha Levin --- diff --git a/queue-6.1/hwmon-tmp513-don-t-use-proxy-headers.patch b/queue-6.1/hwmon-tmp513-don-t-use-proxy-headers.patch new file mode 100644 index 00000000000..6ba58c7a40d --- /dev/null +++ b/queue-6.1/hwmon-tmp513-don-t-use-proxy-headers.patch @@ -0,0 +1,51 @@ +From 1bb71672c232c95f0fd607ef3e31b7fe77cfe9e4 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 28 Nov 2023 20:06:02 +0200 +Subject: hwmon: (tmp513) Don't use "proxy" headers + +From: Andy Shevchenko + +[ Upstream commit 5d9ad4e0fa7cc27199fdb94beb6ec5f655ba9489 ] + +The driver uses math.h and not util_macros.h. + +All the same for the kernel.h, replace it with what the driver is using. + +Signed-off-by: Andy Shevchenko +Link: https://lore.kernel.org/r/20231128180654.395692-2-andriy.shevchenko@linux.intel.com +Signed-off-by: Guenter Roeck +Stable-dep-of: 74d7e038fd07 ("hwmon: (tmp513) Fix interpretation of values of Shunt Voltage and Limit Registers") +Signed-off-by: Sasha Levin +--- + drivers/hwmon/tmp513.c | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c +index b9a93ee9c236..fe3f1113b64e 100644 +--- a/drivers/hwmon/tmp513.c ++++ b/drivers/hwmon/tmp513.c +@@ -19,15 +19,19 @@ + * the Free Software Foundation; version 2 of the License. + */ + ++#include ++#include ++#include + #include + #include + #include + #include +-#include ++#include + #include ++#include + #include + #include +-#include ++#include + + // Common register definition + #define TMP51X_SHUNT_CONFIG 0x00 +-- +2.39.5 + diff --git a/queue-6.1/hwmon-tmp513-fix-current-register-value-interpretati.patch b/queue-6.1/hwmon-tmp513-fix-current-register-value-interpretati.patch new file mode 100644 index 00000000000..3dbaf1f6b45 --- /dev/null +++ b/queue-6.1/hwmon-tmp513-fix-current-register-value-interpretati.patch @@ -0,0 +1,53 @@ +From 95ce060ad7f6da7fd4f35fe1eb78202d15d8f647 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 16 Dec 2024 20:36:47 +0300 +Subject: hwmon: (tmp513) Fix Current Register value interpretation + +From: Murad Masimov + +[ Upstream commit da1d0e6ba211baf6747db74c07700caddfd8a179 ] + +The value returned by the driver after processing the contents of the +Current Register does not correspond to the TMP512/TMP513 specifications. +A raw register value is converted to a signed integer value by a sign +extension in accordance with the algorithm provided in the specification, +but due to the off-by-one error in the sign bit index, the result is +incorrect. Moreover, negative values will be reported as large positive +due to missing sign extension from u32 to long. + +According to the TMP512 and TMP513 datasheets, the Current Register (07h) +is a 16-bit two's complement integer value. E.g., if regval = 1000 0011 +0000 0000, then the value must be (-32000 * lsb), but the driver will +return (33536 * lsb). + +Fix off-by-one bug, and also cast data->curr_lsb_ua (which is of type u32) +to long to prevent incorrect cast for negative values. + +Found by Linux Verification Center (linuxtesting.org) with SVACE. + +Fixes: 59dfa75e5d82 ("hwmon: Add driver for Texas Instruments TMP512/513 sensor chips.") +Signed-off-by: Murad Masimov +Link: https://lore.kernel.org/r/20241216173648.526-3-m.masimov@maxima.ru +[groeck: Fixed description line length] +Signed-off-by: Guenter Roeck +Signed-off-by: Sasha Levin +--- + drivers/hwmon/tmp513.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c +index 23f7fb7fab8c..4ab06852efd9 100644 +--- a/drivers/hwmon/tmp513.c ++++ b/drivers/hwmon/tmp513.c +@@ -218,7 +218,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos, + break; + case TMP51X_BUS_CURRENT_RESULT: + // Current = (ShuntVoltage * CalibrationRegister) / 4096 +- *val = sign_extend32(regval, 16) * data->curr_lsb_ua; ++ *val = sign_extend32(regval, 15) * (long)data->curr_lsb_ua; + *val = DIV_ROUND_CLOSEST(*val, MILLI); + break; + case TMP51X_LOCAL_TEMP_RESULT: +-- +2.39.5 + diff --git a/queue-6.1/hwmon-tmp513-fix-interpretation-of-values-of-shunt-v.patch b/queue-6.1/hwmon-tmp513-fix-interpretation-of-values-of-shunt-v.patch new file mode 100644 index 00000000000..2e55d0adcd9 --- /dev/null +++ b/queue-6.1/hwmon-tmp513-fix-interpretation-of-values-of-shunt-v.patch @@ -0,0 +1,74 @@ +From 0d19095a24c12bf3727f7796520ed33a8a1dc1fa Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 16 Dec 2024 20:36:46 +0300 +Subject: hwmon: (tmp513) Fix interpretation of values of Shunt Voltage and + Limit Registers + +From: Murad Masimov + +[ Upstream commit 74d7e038fd072635d21e4734e3223378e09168d3 ] + +The values returned by the driver after processing the contents of the +Shunt Voltage Register and the Shunt Limit Registers do not correspond to +the TMP512/TMP513 specifications. A raw register value is converted to a +signed integer value by a sign extension in accordance with the algorithm +provided in the specification, but due to the off-by-one error in the sign +bit index, the result is incorrect. Moreover, the PGA shift calculated with +the tmp51x_get_pga_shift function is relevant only to the Shunt Voltage +Register, but is also applied to the Shunt Limit Registers. + +According to the TMP512 and TMP513 datasheets, the Shunt Voltage Register +(04h) is 13 to 16 bit two's complement integer value, depending on the PGA +setting. The Shunt Positive (0Ch) and Negative (0Dh) Limit Registers are +16-bit two's complement integer values. Below are some examples: + +* Shunt Voltage Register +If PGA = 8, and regval = 1000 0011 0000 0000, then the decimal value must +be -32000, but the value calculated by the driver will be 33536. + +* Shunt Limit Register +If regval = 1000 0011 0000 0000, then the decimal value must be -32000, but +the value calculated by the driver will be 768, if PGA = 1. + +Fix sign bit index, and also correct misleading comment describing the +tmp51x_get_pga_shift function. + +Found by Linux Verification Center (linuxtesting.org) with SVACE. + +Fixes: 59dfa75e5d82 ("hwmon: Add driver for Texas Instruments TMP512/513 sensor chips.") +Signed-off-by: Murad Masimov +Link: https://lore.kernel.org/r/20241216173648.526-2-m.masimov@maxima.ru +[groeck: Fixed description and multi-line alignments] +Signed-off-by: Guenter Roeck +Signed-off-by: Sasha Levin +--- + drivers/hwmon/tmp513.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c +index 589982c92190..23f7fb7fab8c 100644 +--- a/drivers/hwmon/tmp513.c ++++ b/drivers/hwmon/tmp513.c +@@ -178,7 +178,7 @@ struct tmp51x_data { + struct regmap *regmap; + }; + +-// Set the shift based on the gain 8=4, 4=3, 2=2, 1=1 ++// Set the shift based on the gain: 8 -> 1, 4 -> 2, 2 -> 3, 1 -> 4 + static inline u8 tmp51x_get_pga_shift(struct tmp51x_data *data) + { + return 5 - ffs(data->pga_gain); +@@ -200,7 +200,9 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos, + * 2's complement number shifted by one to four depending + * on the pga gain setting. 1lsb = 10uV + */ +- *val = sign_extend32(regval, 17 - tmp51x_get_pga_shift(data)); ++ *val = sign_extend32(regval, ++ reg == TMP51X_SHUNT_CURRENT_RESULT ? ++ 16 - tmp51x_get_pga_shift(data) : 15); + *val = DIV_ROUND_CLOSEST(*val * 10 * MILLI, data->shunt_uohms); + break; + case TMP51X_BUS_VOLTAGE_RESULT: +-- +2.39.5 + diff --git a/queue-6.1/hwmon-tmp513-fix-interpretation-of-values-of-tempera.patch b/queue-6.1/hwmon-tmp513-fix-interpretation-of-values-of-tempera.patch new file mode 100644 index 00000000000..21f8fe7b25e --- /dev/null +++ b/queue-6.1/hwmon-tmp513-fix-interpretation-of-values-of-tempera.patch @@ -0,0 +1,51 @@ +From 1923ff22ab50997c52ed8bd2fc6c6a149a34f705 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 16 Dec 2024 20:36:48 +0300 +Subject: hwmon: (tmp513) Fix interpretation of values of Temperature Result + and Limit Registers + +From: Murad Masimov + +[ Upstream commit dd471e25770e7e632f736b90db1e2080b2171668 ] + +The values returned by the driver after processing the contents of the +Temperature Result and the Temperature Limit Registers do not correspond to +the TMP512/TMP513 specifications. A raw register value is converted to a +signed integer value by a sign extension in accordance with the algorithm +provided in the specification, but due to the off-by-one error in the sign +bit index, the result is incorrect. + +According to the TMP512 and TMP513 datasheets, the Temperature Result (08h +to 0Bh) and Limit (11h to 14h) Registers are 13-bit two's complement +integer values, shifted left by 3 bits. The value is scaled by 0.0625 +degrees Celsius per bit. E.g., if regval = 1 1110 0111 0000 000, the +output should be -25 degrees, but the driver will return +487 degrees. + +Found by Linux Verification Center (linuxtesting.org) with SVACE. + +Fixes: 59dfa75e5d82 ("hwmon: Add driver for Texas Instruments TMP512/513 sensor chips.") +Signed-off-by: Murad Masimov +Link: https://lore.kernel.org/r/20241216173648.526-4-m.masimov@maxima.ru +[groeck: fixed description line length] +Signed-off-by: Guenter Roeck +Signed-off-by: Sasha Levin +--- + drivers/hwmon/tmp513.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c +index 4ab06852efd9..aaba9521ebef 100644 +--- a/drivers/hwmon/tmp513.c ++++ b/drivers/hwmon/tmp513.c +@@ -230,7 +230,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos, + case TMP51X_REMOTE_TEMP_LIMIT_2: + case TMP513_REMOTE_TEMP_LIMIT_3: + // 1lsb = 0.0625 degrees centigrade +- *val = sign_extend32(regval, 16) >> TMP51X_TEMP_SHIFT; ++ *val = sign_extend32(regval, 15) >> TMP51X_TEMP_SHIFT; + *val = DIV_ROUND_CLOSEST(*val * 625, 10); + break; + case TMP51X_N_FACTOR_AND_HYST_1: +-- +2.39.5 + diff --git a/queue-6.1/hwmon-tmp513-simplify-with-dev_err_probe.patch b/queue-6.1/hwmon-tmp513-simplify-with-dev_err_probe.patch new file mode 100644 index 00000000000..d745610bc85 --- /dev/null +++ b/queue-6.1/hwmon-tmp513-simplify-with-dev_err_probe.patch @@ -0,0 +1,96 @@ +From fab0d6c8c165d349884ed8b12e87b1afd10b7d4f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 28 Nov 2023 20:06:03 +0200 +Subject: hwmon: (tmp513) Simplify with dev_err_probe() + +From: Andy Shevchenko + +[ Upstream commit df989762bc4b71068e6adc0c2b5ef6f76b6acf74 ] + +Common pattern of handling deferred probe can be simplified with +dev_err_probe(). Less code and also it prints the error value. + +Signed-off-by: Andy Shevchenko +Link: https://lore.kernel.org/r/20231128180654.395692-3-andriy.shevchenko@linux.intel.com +[groeck: Fixed excessive line length] +Signed-off-by: Guenter Roeck +Stable-dep-of: 74d7e038fd07 ("hwmon: (tmp513) Fix interpretation of values of Shunt Voltage and Limit Registers") +Signed-off-by: Sasha Levin +--- + drivers/hwmon/tmp513.c | 35 +++++++++++++++-------------------- + 1 file changed, 15 insertions(+), 20 deletions(-) + +diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c +index fe3f1113b64e..53525d3a32a0 100644 +--- a/drivers/hwmon/tmp513.c ++++ b/drivers/hwmon/tmp513.c +@@ -632,9 +632,9 @@ static int tmp51x_vbus_range_to_reg(struct device *dev, + } else if (data->vbus_range_uvolt == TMP51X_VBUS_RANGE_16V) { + data->shunt_config &= ~TMP51X_BUS_VOLTAGE_MASK; + } else { +- dev_err(dev, "ti,bus-range-microvolt is invalid: %u\n", +- data->vbus_range_uvolt); +- return -EINVAL; ++ return dev_err_probe(dev, -EINVAL, ++ "ti,bus-range-microvolt is invalid: %u\n", ++ data->vbus_range_uvolt); + } + return 0; + } +@@ -650,8 +650,8 @@ static int tmp51x_pga_gain_to_reg(struct device *dev, struct tmp51x_data *data) + } else if (data->pga_gain == 1) { + data->shunt_config |= CURRENT_SENSE_VOLTAGE_40_MASK; + } else { +- dev_err(dev, "ti,pga-gain is invalid: %u\n", data->pga_gain); +- return -EINVAL; ++ return dev_err_probe(dev, -EINVAL, ++ "ti,pga-gain is invalid: %u\n", data->pga_gain); + } + return 0; + } +@@ -684,9 +684,9 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data) + + // Check if shunt value is compatible with pga-gain + if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) { +- dev_err(dev, "shunt-resistor: %u too big for pga_gain: %u\n", +- data->shunt_uohms, data->pga_gain); +- return -EINVAL; ++ return dev_err_probe(dev, -EINVAL, ++ "shunt-resistor: %u too big for pga_gain: %u\n", ++ data->shunt_uohms, data->pga_gain); + } + + return 0; +@@ -730,22 +730,17 @@ static int tmp51x_probe(struct i2c_client *client) + data->id = i2c_match_id(tmp51x_id, client)->driver_data; + + ret = tmp51x_configure(dev, data); +- if (ret < 0) { +- dev_err(dev, "error configuring the device: %d\n", ret); +- return ret; +- } ++ if (ret < 0) ++ return dev_err_probe(dev, ret, "error configuring the device\n"); + + data->regmap = devm_regmap_init_i2c(client, &tmp51x_regmap_config); +- if (IS_ERR(data->regmap)) { +- dev_err(dev, "failed to allocate register map\n"); +- return PTR_ERR(data->regmap); +- } ++ if (IS_ERR(data->regmap)) ++ return dev_err_probe(dev, PTR_ERR(data->regmap), ++ "failed to allocate register map\n"); + + ret = tmp51x_init(data); +- if (ret < 0) { +- dev_err(dev, "error configuring the device: %d\n", ret); +- return -ENODEV; +- } ++ if (ret < 0) ++ return dev_err_probe(dev, ret, "error configuring the device\n"); + + hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, + data, +-- +2.39.5 + diff --git a/queue-6.1/hwmon-tmp513-use-si-constants-from-units.h.patch b/queue-6.1/hwmon-tmp513-use-si-constants-from-units.h.patch new file mode 100644 index 00000000000..faf39d4879f --- /dev/null +++ b/queue-6.1/hwmon-tmp513-use-si-constants-from-units.h.patch @@ -0,0 +1,105 @@ +From b145d7e6c56a9588d90726d09c177c347bf36b71 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 28 Nov 2023 20:06:04 +0200 +Subject: hwmon: (tmp513) Use SI constants from units.h + +From: Andy Shevchenko + +[ Upstream commit f07f9d2467f4a298d24e186ddee6f69724903067 ] + +MILLI and MICRO may be used in the driver to make code more robust +against possible miscalculations. + +Signed-off-by: Andy Shevchenko +Link: https://lore.kernel.org/r/20231128180654.395692-4-andriy.shevchenko@linux.intel.com +Signed-off-by: Guenter Roeck +Stable-dep-of: 74d7e038fd07 ("hwmon: (tmp513) Fix interpretation of values of Shunt Voltage and Limit Registers") +Signed-off-by: Sasha Levin +--- + drivers/hwmon/tmp513.c | 21 ++++++++++----------- + 1 file changed, 10 insertions(+), 11 deletions(-) + +diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c +index 53525d3a32a0..589982c92190 100644 +--- a/drivers/hwmon/tmp513.c ++++ b/drivers/hwmon/tmp513.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + + // Common register definition + #define TMP51X_SHUNT_CONFIG 0x00 +@@ -104,8 +105,8 @@ + #define TMP51X_REMOTE_TEMP_LIMIT_2_POS 8 + #define TMP513_REMOTE_TEMP_LIMIT_3_POS 7 + +-#define TMP51X_VBUS_RANGE_32V 32000000 +-#define TMP51X_VBUS_RANGE_16V 16000000 ++#define TMP51X_VBUS_RANGE_32V (32 * MICRO) ++#define TMP51X_VBUS_RANGE_16V (16 * MICRO) + + // Max and Min value + #define MAX_BUS_VOLTAGE_32_LIMIT 32764 +@@ -200,7 +201,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos, + * on the pga gain setting. 1lsb = 10uV + */ + *val = sign_extend32(regval, 17 - tmp51x_get_pga_shift(data)); +- *val = DIV_ROUND_CLOSEST(*val * 10000, data->shunt_uohms); ++ *val = DIV_ROUND_CLOSEST(*val * 10 * MILLI, data->shunt_uohms); + break; + case TMP51X_BUS_VOLTAGE_RESULT: + case TMP51X_BUS_VOLTAGE_H_LIMIT: +@@ -216,7 +217,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos, + case TMP51X_BUS_CURRENT_RESULT: + // Current = (ShuntVoltage * CalibrationRegister) / 4096 + *val = sign_extend32(regval, 16) * data->curr_lsb_ua; +- *val = DIV_ROUND_CLOSEST(*val, 1000); ++ *val = DIV_ROUND_CLOSEST(*val, MILLI); + break; + case TMP51X_LOCAL_TEMP_RESULT: + case TMP51X_REMOTE_TEMP_RESULT_1: +@@ -256,7 +257,7 @@ static int tmp51x_set_value(struct tmp51x_data *data, u8 reg, long val) + * The user enter current value and we convert it to + * voltage. 1lsb = 10uV + */ +- val = DIV_ROUND_CLOSEST(val * data->shunt_uohms, 10000); ++ val = DIV_ROUND_CLOSEST(val * data->shunt_uohms, 10 * MILLI); + max_val = U16_MAX >> tmp51x_get_pga_shift(data); + regval = clamp_val(val, -max_val, max_val); + break; +@@ -546,18 +547,16 @@ static int tmp51x_calibrate(struct tmp51x_data *data) + if (data->shunt_uohms == 0) + return regmap_write(data->regmap, TMP51X_SHUNT_CALIBRATION, 0); + +- max_curr_ma = DIV_ROUND_CLOSEST_ULL(vshunt_max * 1000 * 1000, +- data->shunt_uohms); ++ max_curr_ma = DIV_ROUND_CLOSEST_ULL(vshunt_max * MICRO, data->shunt_uohms); + + /* + * Calculate the minimal bit resolution for the current and the power. + * Those values will be used during register interpretation. + */ +- data->curr_lsb_ua = DIV_ROUND_CLOSEST_ULL(max_curr_ma * 1000, 32767); ++ data->curr_lsb_ua = DIV_ROUND_CLOSEST_ULL(max_curr_ma * MILLI, 32767); + data->pwr_lsb_uw = 20 * data->curr_lsb_ua; + +- div = DIV_ROUND_CLOSEST_ULL(data->curr_lsb_ua * data->shunt_uohms, +- 1000 * 1000); ++ div = DIV_ROUND_CLOSEST_ULL(data->curr_lsb_ua * data->shunt_uohms, MICRO); + + return regmap_write(data->regmap, TMP51X_SHUNT_CALIBRATION, + DIV_ROUND_CLOSEST(40960, div)); +@@ -683,7 +682,7 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data) + memcpy(data->nfactor, nfactor, (data->id == tmp513) ? 3 : 2); + + // Check if shunt value is compatible with pga-gain +- if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) { ++ if (data->shunt_uohms > data->pga_gain * 40 * MICRO) { + return dev_err_probe(dev, -EINVAL, + "shunt-resistor: %u too big for pga_gain: %u\n", + data->shunt_uohms, data->pga_gain); +-- +2.39.5 + diff --git a/queue-6.1/series b/queue-6.1/series index 8647b09a2af..15feb5f24a0 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -34,3 +34,9 @@ i915-guc-reset-engine-utilization-buffer-before-regi.patch i915-guc-ensure-busyness-counter-increases-motonical.patch i915-guc-accumulate-active-runtime-on-gt-reset.patch drm-amdgpu-don-t-access-invalid-sched.patch +hwmon-tmp513-don-t-use-proxy-headers.patch +hwmon-tmp513-simplify-with-dev_err_probe.patch +hwmon-tmp513-use-si-constants-from-units.h.patch +hwmon-tmp513-fix-interpretation-of-values-of-shunt-v.patch +hwmon-tmp513-fix-current-register-value-interpretati.patch +hwmon-tmp513-fix-interpretation-of-values-of-tempera.patch