From: Sasha Levin Date: Sun, 22 Dec 2024 04:32:15 +0000 (-0500) Subject: Fixes for 6.6 X-Git-Tag: v6.1.122~35^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=347cea78e353ea72565435f3f23a0e2f6b3d6bc0;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 6.6 Signed-off-by: Sasha Levin --- diff --git a/queue-6.6/hwmon-tmp513-don-t-use-proxy-headers.patch b/queue-6.6/hwmon-tmp513-don-t-use-proxy-headers.patch new file mode 100644 index 00000000000..af786206d79 --- /dev/null +++ b/queue-6.6/hwmon-tmp513-don-t-use-proxy-headers.patch @@ -0,0 +1,51 @@ +From 5b24bd93223234e56a8f1b6e74dfef3018ddf60b 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 9a180b1030c9..ca665033fe52 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.6/hwmon-tmp513-fix-current-register-value-interpretati.patch b/queue-6.6/hwmon-tmp513-fix-current-register-value-interpretati.patch new file mode 100644 index 00000000000..c653753902d --- /dev/null +++ b/queue-6.6/hwmon-tmp513-fix-current-register-value-interpretati.patch @@ -0,0 +1,53 @@ +From 764386ff79f9f6820c440a162012f4d9c50acbcc 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 549503a56ed0..77dffbee8ebe 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.6/hwmon-tmp513-fix-interpretation-of-values-of-shunt-v.patch b/queue-6.6/hwmon-tmp513-fix-interpretation-of-values-of-shunt-v.patch new file mode 100644 index 00000000000..b390422cd33 --- /dev/null +++ b/queue-6.6/hwmon-tmp513-fix-interpretation-of-values-of-shunt-v.patch @@ -0,0 +1,74 @@ +From 284685c0c6e4d174cacb69503f311d4385f989c9 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 1e50ac680378..549503a56ed0 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.6/hwmon-tmp513-fix-interpretation-of-values-of-tempera.patch b/queue-6.6/hwmon-tmp513-fix-interpretation-of-values-of-tempera.patch new file mode 100644 index 00000000000..e019abd9682 --- /dev/null +++ b/queue-6.6/hwmon-tmp513-fix-interpretation-of-values-of-tempera.patch @@ -0,0 +1,51 @@ +From fb66fcc2bf3fb72a9f8445b620feaf4ccb4535de 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 77dffbee8ebe..070f93226ed6 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.6/hwmon-tmp513-simplify-with-dev_err_probe.patch b/queue-6.6/hwmon-tmp513-simplify-with-dev_err_probe.patch new file mode 100644 index 00000000000..70838ddff4a --- /dev/null +++ b/queue-6.6/hwmon-tmp513-simplify-with-dev_err_probe.patch @@ -0,0 +1,96 @@ +From 362be31affd3827aa067e2c04894c82d25c82e2e 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 ca665033fe52..67b13ac5512c 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; +@@ -727,22 +727,17 @@ static int tmp51x_probe(struct i2c_client *client) + data->id = (uintptr_t)i2c_get_match_data(client); + + 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.6/hwmon-tmp513-use-si-constants-from-units.h.patch b/queue-6.6/hwmon-tmp513-use-si-constants-from-units.h.patch new file mode 100644 index 00000000000..6eb96a242c9 --- /dev/null +++ b/queue-6.6/hwmon-tmp513-use-si-constants-from-units.h.patch @@ -0,0 +1,105 @@ +From 4a409468115f0439a5c043afeecb46013680e34c 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 67b13ac5512c..1e50ac680378 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.6/series b/queue-6.6/series index 4ae069ec0c2..f321f1cb237 100644 --- a/queue-6.6/series +++ b/queue-6.6/series @@ -60,3 +60,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