* [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions
@ 2025-05-15 8:13 Alexandru Soponar
2025-05-15 8:13 ` [PATCH 01/16] hwmon: w83795: Fix type incompatibility with non-macro find_closest Alexandru Soponar
` (16 more replies)
0 siblings, 17 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
This patch series converts the find_closest() and find_closest_descending() macros
into proper library functions. The conversion moves these utilities from macro
implementations in util_macros.h to standard C functions in lib/find_closest.c.
The first 15 patches modify individual callers across hwmon, iio, leds, regulator,
and watchdog subsystems to ensure they work correctly with the new function-based
implementation. This maintains compatibility while allowing the final conversion.
The final patch implements the actual refactoring by moving the code to
lib/find_closest.c. This approach was chosen based on discussions between
Andrew Morton and Alexandru Ardelean[1], who suggested that a non-inline
implementation would be appropriate given the size of the functions.
The refactoring avoids of macro expansion-related issues and proper function
prototypes with well-defined parameter types.
Links:
[1] https://lore.kernel.org/lkml/20241105145406.554365-1-aardelean@baylibre.com/
Alexandru Soponar (16):
hwmon: w83795: Fix type incompatibility with non-macro find_closest
hwmon: emc1403: Fix type incompatibility with non-macro find_closest
hwmon: ina3221: Fix type incompatibility with non-macro find_closest
hwmon: lm95234: Fix type incompatibility with non-macro find_closest
hwmon: max1619: Fix type incompatibility with non-macro find_closest
hwmon: lm75: Fix type incompatibility with non-macro find_closest
hwmon: ltc4282: Fix type incompatibility with non-macro find_closest
hwmon: max6639: Fix type incompatibility with non-macro find_closest
hwmon: max20740: Fix type incompatibility with non-macro find_closest
iio: ad7606: Fix type incompatibility with non-macro find_closest
iio: mcp3564: Fix type incompatibility with non-macro find_closest
iio: max44009: Fix type incompatibility with non-macro find_closest
leds: eds-mt6370-rgb: Fix type incompatibility with find_closest()
regulator: max77857: Fix type incompatibility with find_closest()
watchdog: simatic-ipc-wdt: Fix type incompatibility with
find_closest()
lib: move find_closest() and find_closest_descending() to lib
functions
drivers/hwmon/emc1403.c | 2 +-
drivers/hwmon/ina3221.c | 8 +--
drivers/hwmon/lm75.c | 42 +++++++--------
drivers/hwmon/lm95234.c | 2 +-
drivers/hwmon/ltc4282.c | 2 +-
drivers/hwmon/max1619.c | 2 +-
drivers/hwmon/max6639.c | 2 +-
drivers/hwmon/pmbus/max20730.c | 4 +-
drivers/hwmon/w83795.c | 2 +-
drivers/iio/adc/ad7606.c | 8 +--
drivers/iio/adc/mcp3564.c | 2 +-
drivers/iio/light/max44009.c | 2 +-
drivers/leds/rgb/leds-mt6370-rgb.c | 9 ++--
drivers/regulator/max77857-regulator.c | 2 +-
drivers/watchdog/simatic-ipc-wdt.c | 2 +-
include/linux/find_closest.h | 13 +++++
include/linux/util_macros.h | 61 +---------------------
lib/Makefile | 2 +-
lib/find_closest.c | 71 ++++++++++++++++++++++++++
19 files changed, 132 insertions(+), 106 deletions(-)
create mode 100644 include/linux/find_closest.h
create mode 100644 lib/find_closest.c
--
2.49.0
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 01/16] hwmon: w83795: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 02/16] hwmon: emc1403: " Alexandru Soponar
` (15 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The pwm_freq_cksel0 array was previously declared as u16 but used with
find_closest_descending(). Now that find_closest_descending() is
implemented as a function with 'int' parameters instead of a macro,
passing unsigned arrays causes type incompatibility errors. This patch
changes the array type from u16 to int to match the function's signature
and prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/w83795.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 5174db69db5e..1b63bd540f6c 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -273,7 +273,7 @@ static inline s8 temp_to_reg(long val, s8 min, s8 max)
return clamp_val(val / 1000, min, max);
}
-static const u16 pwm_freq_cksel0[16] = {
+static const int pwm_freq_cksel0[16] = {
1024, 512, 341, 256, 205, 171, 146, 128,
85, 64, 32, 16, 8, 4, 2, 1
};
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 02/16] hwmon: emc1403: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
2025-05-15 8:13 ` [PATCH 01/16] hwmon: w83795: Fix type incompatibility with non-macro find_closest Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 03/16] hwmon: ina3221: " Alexandru Soponar
` (14 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The ina3221_conv_time array was previously declared as u16 but used with
find_closest_descending(). With find_closest_descending() now implemented
as a function taking 'int' parameters instead of a macro, passing unsigned
arrays causes type incompatibility errors. Change the array type from u16
to int to ensure compatibility with the new function signature.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/emc1403.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index eca33220d34a..41590b44b162 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -517,7 +517,7 @@ static int emc1403_temp_write(struct thermal_data *data, u32 attr, int channel,
}
/* Lookup table for temperature conversion times in msec */
-static const u16 ina3221_conv_time[] = {
+static const int ina3221_conv_time[] = {
16000, 8000, 4000, 2000, 1000, 500, 250, 125, 62, 31, 16
};
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 03/16] hwmon: ina3221: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
2025-05-15 8:13 ` [PATCH 01/16] hwmon: w83795: Fix type incompatibility with non-macro find_closest Alexandru Soponar
2025-05-15 8:13 ` [PATCH 02/16] hwmon: emc1403: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 04/16] hwmon: lm95234: " Alexandru Soponar
` (13 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The ina3221_conv_time array was previously declared as u16 but used with
find_closest(). With find_closest() now implemented as a function taking
signed int parameters instead of a macro, passing unsigned arrays causes
type incompatibility errors. This patch changes the array type from
u16 to int to ensure compatibility with the function signature and
prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/ina3221.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index 1bf479a0f793..482ab8e53d5c 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -178,7 +178,7 @@ static inline int ina3221_summation_shunt_resistor(struct ina3221_data *ina)
}
/* Lookup table for Bus and Shunt conversion times in usec */
-static const u16 ina3221_conv_time[] = {
+static const int ina3221_conv_time[] = {
140, 204, 332, 588, 1100, 2116, 4156, 8244,
};
@@ -192,7 +192,7 @@ static inline u32 ina3221_interval_ms_to_conv_time(u16 config, int interval)
{
u32 channels = hweight16(config & INA3221_CONFIG_CHs_EN_MASK);
u32 samples_idx = INA3221_CONFIG_AVG(config);
- u32 samples = ina3221_avg_samples[samples_idx];
+ int samples = ina3221_avg_samples[samples_idx];
/* Bisect the result to Bus and Shunt conversion times */
return DIV_ROUND_CLOSEST(interval * 1000 / 2, channels * samples);
@@ -204,8 +204,8 @@ static inline u32 ina3221_reg_to_interval_us(u16 config)
u32 channels = hweight16(config & INA3221_CONFIG_CHs_EN_MASK);
u32 vbus_ct_idx = INA3221_CONFIG_VBUS_CT(config);
u32 vsh_ct_idx = INA3221_CONFIG_VSH_CT(config);
- u32 vbus_ct = ina3221_conv_time[vbus_ct_idx];
- u32 vsh_ct = ina3221_conv_time[vsh_ct_idx];
+ int vbus_ct = ina3221_conv_time[vbus_ct_idx];
+ int vsh_ct = ina3221_conv_time[vsh_ct_idx];
/* Calculate total conversion time */
return channels * (vbus_ct + vsh_ct);
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 04/16] hwmon: lm95234: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (2 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 03/16] hwmon: ina3221: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 05/16] hwmon: max1619: " Alexandru Soponar
` (12 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The update_intervals array was previously declared as u16 but used with
find_closest(). With find_closest() now implemented as a function taking
signed int parameters instead of a macro, passing unsigned arrays causes
type incompatibility errors. This patch changes the array type from
u16 to int to ensure compatibility with the function signature and
prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/lm95234.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
index 7da6c8f07332..e808fd7d5587 100644
--- a/drivers/hwmon/lm95234.c
+++ b/drivers/hwmon/lm95234.c
@@ -240,7 +240,7 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va
return 0;
}
-static u16 update_intervals[] = { 143, 364, 1000, 2500 };
+static int update_intervals[] = { 143, 364, 1000, 2500 };
static int lm95234_chip_write(struct device *dev, u32 attr, long val)
{
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 05/16] hwmon: max1619: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (3 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 04/16] hwmon: lm95234: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 06/16] hwmon: lm75: " Alexandru Soponar
` (11 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The update_intervals array was previously declared as u16 but used with
find_closest_descending(). With find_closest_descending() now implemented
as a function taking signed int parameters instead of a macro, passing
unsigned arrays causes type incompatibility errors. This patch changes
the array type from u16 to int to ensure compatibility with the function
signature and prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/max1619.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 9b6d03cff4df..0bd9fbb2517c 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -103,7 +103,7 @@ static int max1619_temp_read(struct regmap *regmap, u32 attr, int channel, long
return 0;
}
-static u16 update_intervals[] = { 16000, 8000, 4000, 2000, 1000, 500, 250, 125 };
+static int update_intervals[] = { 16000, 8000, 4000, 2000, 1000, 500, 250, 125 };
static int max1619_chip_read(struct regmap *regmap, u32 attr, long *val)
{
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 06/16] hwmon: lm75: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (4 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 05/16] hwmon: max1619: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 07/16] hwmon: ltc4282: " Alexandru Soponar
` (10 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The default_sample_time and sample_times members of lm75_params were
previously declared as unsigned int but used withfind_closest(). With
find_closest() now implemented as a function taking signed int parameters
instead of a macro, passing unsigned arrays causes type incompatibility
errors. This patch changes the types from unsigned int and unsigned int*
to int respectively int* to ensure compatibility with the function
signature and prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/lm75.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index d95a3c6c245c..5c835ee189d4 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -89,9 +89,9 @@ struct lm75_params {
u8 default_resolution;
u8 resolution_limits;
const u8 *resolutions;
- unsigned int default_sample_time;
+ int default_sample_time;
u8 num_sample_times;
- const unsigned int *sample_times;
+ const int *sample_times;
bool alarm;
};
@@ -110,7 +110,7 @@ struct lm75_data {
struct regmap *regmap;
u16 orig_conf;
u8 resolution; /* In bits, 9 to 16 */
- unsigned int sample_time; /* In ms */
+ int sample_time; /* In ms */
enum lm75_type kind;
const struct lm75_params *params;
u8 reg_buf[1];
@@ -139,7 +139,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 125,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 125, 250, 1000, 4000 },
+ .sample_times = (int []){ 125, 250, 1000, 4000 },
.alarm = true,
},
[at30ts74] = {
@@ -147,7 +147,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 200,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 25, 50, 100, 200 },
+ .sample_times = (int []){ 25, 50, 100, 200 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[ds1775] = {
@@ -156,7 +156,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 11,
.default_sample_time = 500,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 125, 250, 500, 1000 },
+ .sample_times = (int []){ 125, 250, 500, 1000 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[ds75] = {
@@ -165,7 +165,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 11,
.default_sample_time = 600,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 150, 300, 600, 1200 },
+ .sample_times = (int []){ 150, 300, 600, 1200 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[stds75] = {
@@ -174,7 +174,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 11,
.default_sample_time = 600,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 150, 300, 600, 1200 },
+ .sample_times = (int []){ 150, 300, 600, 1200 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[stlm75] = {
@@ -186,7 +186,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 200,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 25, 50, 100, 200 },
+ .sample_times = (int []){ 25, 50, 100, 200 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[g751] = {
@@ -227,13 +227,13 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 55,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .sample_times = (int []){ 28, 55, 110, 220 },
},
[pct2075] = {
.default_resolution = 11,
.default_sample_time = MSEC_PER_SEC / 10,
.num_sample_times = 31,
- .sample_times = (unsigned int []){ 100, 200, 300, 400, 500, 600,
+ .sample_times = (int []){ 100, 200, 300, 400, 500, 600,
700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700,
1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700,
2800, 2900, 3000, 3100 },
@@ -245,7 +245,7 @@ static const struct lm75_params device_params[] = {
.resolution_limits = 9,
.default_sample_time = 240,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 30, 60, 120, 240 },
+ .sample_times = (int []){ 30, 60, 120, 240 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[tmp100] = {
@@ -254,7 +254,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 320,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 40, 80, 160, 320 },
+ .sample_times = (int []){ 40, 80, 160, 320 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[tmp101] = {
@@ -263,7 +263,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 320,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 40, 80, 160, 320 },
+ .sample_times = (int []){ 40, 80, 160, 320 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[tmp105] = {
@@ -272,7 +272,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 220,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .sample_times = (int []){ 28, 55, 110, 220 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[tmp112] = {
@@ -282,7 +282,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 125,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 125, 250, 1000, 4000 },
+ .sample_times = (int []){ 125, 250, 1000, 4000 },
.alarm = true,
},
[tmp175] = {
@@ -291,7 +291,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 220,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .sample_times = (int []){ 28, 55, 110, 220 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[tmp275] = {
@@ -300,7 +300,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 220,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .sample_times = (int []){ 28, 55, 110, 220 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[tmp75] = {
@@ -309,14 +309,14 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 220,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .sample_times = (int []){ 28, 55, 110, 220 },
.resolutions = (u8 []) {9, 10, 11, 12 },
},
[tmp75b] = { /* not one-shot mode, Conversion rate 37Hz */
.clr_mask = 1 << 7 | 3 << 5,
.default_resolution = 12,
.default_sample_time = MSEC_PER_SEC / 37,
- .sample_times = (unsigned int []){ MSEC_PER_SEC / 37,
+ .sample_times = (int []){ MSEC_PER_SEC / 37,
MSEC_PER_SEC / 18,
MSEC_PER_SEC / 9, MSEC_PER_SEC / 4 },
.num_sample_times = 4,
@@ -331,7 +331,7 @@ static const struct lm75_params device_params[] = {
.default_resolution = 12,
.default_sample_time = 28,
.num_sample_times = 4,
- .sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .sample_times = (int []){ 28, 55, 110, 220 },
}
};
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 07/16] hwmon: ltc4282: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (5 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 06/16] hwmon: lm75: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 08/16] hwmon: max6639: " Alexandru Soponar
` (9 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The ltc4282_out_rates array was previously declared as unsigned int but
used with find_closest(). With find_closest() now implemented as a function
taking signed int parameters instead of a macro, passing unsigned arrays
causes type incompatibility errors. This patch changes the array type from
unsigned int to int to ensure compatibility with the function signature and
prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/ltc4282.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/ltc4282.c b/drivers/hwmon/ltc4282.c
index 4f608a3790fb..1908a998feb1 100644
--- a/drivers/hwmon/ltc4282.c
+++ b/drivers/hwmon/ltc4282.c
@@ -173,7 +173,7 @@ static int ltc4282_set_rate(struct clk_hw *hw,
* Note the 15HZ conversion rate assumes 12bit ADC which is what we are
* supporting for now.
*/
-static const unsigned int ltc4282_out_rates[] = {
+static const int ltc4282_out_rates[] = {
LTC4282_CLKOUT_CNV, LTC4282_CLKOUT_SYSTEM
};
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 08/16] hwmon: max6639: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (6 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 07/16] hwmon: ltc4282: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 09/16] hwmon: max20740: " Alexandru Soponar
` (8 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The freq_table array was previously declared as unsigned int but used
with find_closest(). With find_closest() now implemented as a function
taking signed int parameters instead of a macro, passing unsigned arrays
causes type incompatibility errors. This patch changes the array type from
unsigned int to int to ensure compatibility with the function signature and
prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/max6639.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index 32b4d54b2076..b6942b406880 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -63,7 +63,7 @@ static const unsigned short normal_i2c[] = { 0x2c, 0x2e, 0x2f, I2C_CLIENT_END };
static const int rpm_ranges[] = { 2000, 4000, 8000, 16000 };
/* Supported PWM frequency */
-static const unsigned int freq_table[] = { 20, 33, 50, 100, 5000, 8333, 12500,
+static const int freq_table[] = { 20, 33, 50, 100, 5000, 8333, 12500,
25000 };
#define FAN_FROM_REG(val, rpm_range) ((val) == 0 || (val) == 255 ? \
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 09/16] hwmon: max20740: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (7 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 08/16] hwmon: max6639: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 10/16] iio: ad7606: " Alexandru Soponar
` (7 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The max_current array was previously declared as u32 but used with
find_closest(). With find_closest() now implemented as a function taking
signed int parameters instead of a macro, passing unsigned arrays causes
type incompatibility errors. This patch changes the array type from u32
to int to ensure compatibility with the function signature and prevent
compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/hwmon/pmbus/max20730.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pmbus/max20730.c b/drivers/hwmon/pmbus/max20730.c
index 95869d198ecf..0e8d292e9ff4 100644
--- a/drivers/hwmon/pmbus/max20730.c
+++ b/drivers/hwmon/pmbus/max20730.c
@@ -436,7 +436,7 @@ static long direct_to_val(u16 w, enum pmbus_sensor_classes class,
return d;
}
-static u32 max_current[][5] = {
+static int max_current[][5] = {
[max20710] = { 6200, 8000, 9700, 11600 },
[max20730] = { 13000, 16600, 20100, 23600 },
[max20734] = { 21000, 27000, 32000, 38000 },
@@ -449,7 +449,7 @@ static int max20730_read_word_data(struct i2c_client *client, int page,
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
const struct max20730_data *data = to_max20730_data(info);
int ret = 0;
- u32 max_c;
+ int max_c;
switch (reg) {
case PMBUS_OT_FAULT_LIMIT:
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 10/16] iio: ad7606: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (8 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 09/16] hwmon: max20740: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 17:13 ` Jonathan Cameron
2025-05-15 8:13 ` [PATCH 11/16] iio: mcp3564: " Alexandru Soponar
` (6 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The ad7606_oversampling_avail and ad7616_oversampling_avail arrays were
previously declared as unsigned int but used with find_closest(). With
find_closest() now implemented as a function taking signed int parameters
instead of a macro, passing unsigned arrays causes type incompatibility
errors. This patch changes the arrays type from unsigned int to int to
ensure compatibility with the function signature and prevent compilation
errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/iio/adc/ad7606.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index d8e3c7a43678..41b477ea386d 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -81,11 +81,11 @@ static const unsigned int ad7609_hw_scale_avail[2][2] = {
{ 0, 152588 }, { 0, 305176 }
};
-static const unsigned int ad7606_oversampling_avail[7] = {
+static const int ad7606_oversampling_avail[7] = {
1, 2, 4, 8, 16, 32, 64,
};
-static const unsigned int ad7616_oversampling_avail[8] = {
+static const int ad7616_oversampling_avail[8] = {
1, 2, 4, 8, 16, 32, 64, 128,
};
@@ -835,7 +835,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
long mask)
{
struct ad7606_state *st = iio_priv(indio_dev);
- unsigned int scale_avail_uv[AD760X_MAX_SCALES];
+ int scale_avail_uv[AD760X_MAX_SCALES];
struct ad7606_chan_scale *cs;
int i, ret, ch = 0;
@@ -884,7 +884,7 @@ static ssize_t ad7606_oversampling_ratio_avail(struct device *dev,
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ad7606_state *st = iio_priv(indio_dev);
- const unsigned int *vals = st->oversampling_avail;
+ const int *vals = st->oversampling_avail;
unsigned int i;
size_t len = 0;
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 11/16] iio: mcp3564: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (9 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 10/16] iio: ad7606: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 17:14 ` Jonathan Cameron
2025-05-19 8:09 ` Marius.Cristea
2025-05-15 8:13 ` [PATCH 12/16] iio: max44009: " Alexandru Soponar
` (5 subsequent siblings)
16 siblings, 2 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The mcp3564_oversampling_avail array was previously declared as unsigned
int but used with find_closest(). With find_closest() now implemented as
a function taking signed int parameters instead of a macro, passing
unsigned arrays causes type incompatibility errors. This patch changes the
arrays type from unsigned int to int to ensure compatibility with the
function signature and prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/iio/adc/mcp3564.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c
index a68f1cd6883e..01efc77f710a 100644
--- a/drivers/iio/adc/mcp3564.c
+++ b/drivers/iio/adc/mcp3564.c
@@ -253,7 +253,7 @@ enum mcp3564_oversampling {
MCP3564_OVERSAMPLING_RATIO_98304
};
-static const unsigned int mcp3564_oversampling_avail[] = {
+static const int mcp3564_oversampling_avail[] = {
[MCP3564_OVERSAMPLING_RATIO_32] = 32,
[MCP3564_OVERSAMPLING_RATIO_64] = 64,
[MCP3564_OVERSAMPLING_RATIO_128] = 128,
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 12/16] iio: max44009: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (10 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 11/16] iio: mcp3564: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 17:14 ` Jonathan Cameron
2025-05-15 8:13 ` [PATCH 13/16] leds: eds-mt6370-rgb: Fix type incompatibility with find_closest() Alexandru Soponar
` (4 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The max44009_int_time_ns_array array was previously declared as u32 but
used with find_closest(). With find_closest() now implemented as a
function taking signed int parameters instead of a macro, passing unsigned
arrays causes type incompatibility errors. This patch changes the arrays
type from u32 to int to ensure compatibility with the function signature
and prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/iio/light/max44009.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/light/max44009.c b/drivers/iio/light/max44009.c
index 8cd7f5664e5b..d274224fc210 100644
--- a/drivers/iio/light/max44009.c
+++ b/drivers/iio/light/max44009.c
@@ -55,7 +55,7 @@
/* The fixed-point fractional multiplier for de-scaling threshold values */
#define MAX44009_FRACT_MULT 1000000
-static const u32 max44009_int_time_ns_array[] = {
+static const int max44009_int_time_ns_array[] = {
800000000,
400000000,
200000000,
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 13/16] leds: eds-mt6370-rgb: Fix type incompatibility with find_closest()
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (11 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 12/16] iio: max44009: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-22 14:33 ` Lee Jones
2025-05-15 8:13 ` [PATCH 14/16] regulator: max77857: " Alexandru Soponar
` (3 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The common_tfreqs and mt6372_tfreqs arrays were previously declared as
unsigned int but used with find_closest(), which now takes signed int
parameters. Change these arrays from unsigned int to int to maintain type
compatibility with the find_closest() function signature and prevent
compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/leds/rgb/leds-mt6370-rgb.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/leds/rgb/leds-mt6370-rgb.c b/drivers/leds/rgb/leds-mt6370-rgb.c
index ebd3ba878dd5..6ce11432dd96 100644
--- a/drivers/leds/rgb/leds-mt6370-rgb.c
+++ b/drivers/leds/rgb/leds-mt6370-rgb.c
@@ -135,7 +135,7 @@ struct mt6370_led {
};
struct mt6370_pdata {
- const unsigned int *tfreq;
+ const int *tfreq;
unsigned int tfreq_len;
u16 reg_rgb1_tr;
s16 reg_rgb_chrind_tr;
@@ -212,11 +212,11 @@ static const struct linear_range mt6372_led_ranges[R_MAX_RANGES] = {
[R_LED_TOFF] = { 250, 0, 15, 500 },
};
-static const unsigned int common_tfreqs[] = {
+static const int common_tfreqs[] = {
10000, 5000, 2000, 1000, 500, 200, 5, 1,
};
-static const unsigned int mt6372_tfreqs[] = {
+static const int mt6372_tfreqs[] = {
8000, 4000, 2000, 1000, 500, 250, 8, 4,
};
@@ -304,7 +304,8 @@ static int mt6370_set_led_freq(struct mt6370_priv *priv, unsigned int led_no, un
const struct mt6370_pdata *pdata = priv->pdata;
enum mt6370_led_field sel_field;
unsigned int tfreq_len = pdata->tfreq_len;
- unsigned int tsum, sel;
+ unsigned int sel;
+ int tsum;
tsum = ton + toff;
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 14/16] regulator: max77857: Fix type incompatibility with find_closest()
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (12 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 13/16] leds: eds-mt6370-rgb: Fix type incompatibility with find_closest() Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 15/16] watchdog: simatic-ipc-wdt: " Alexandru Soponar
` (2 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The max77857_switch_freq array was previously declared as unsigned int
but used with find_closest(), which takes signed int parameters. Change
this array from unsigned int to int to maintain type compatibility with
the find_closest() function signature and prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/regulator/max77857-regulator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/regulator/max77857-regulator.c b/drivers/regulator/max77857-regulator.c
index 1216cc3a6f72..5e64f5510601 100644
--- a/drivers/regulator/max77857-regulator.c
+++ b/drivers/regulator/max77857-regulator.c
@@ -289,7 +289,7 @@ static struct linear_range max77857_lin_ranges[] = {
REGULATOR_LINEAR_RANGE(4485000, 0x3D, 0xCC, 73500)
};
-static const unsigned int max77857_switch_freq[] = {
+static const int max77857_switch_freq[] = {
1200000, 1500000, 1800000, 2100000
};
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 15/16] watchdog: simatic-ipc-wdt: Fix type incompatibility with find_closest()
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (13 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 14/16] regulator: max77857: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-15 8:13 ` [PATCH 16/16] lib: move find_closest() and find_closest_descending() to lib functions Alexandru Soponar
2025-05-19 15:44 ` [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros " Guenter Roeck
16 siblings, 0 replies; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
The wd_timeout_table array was previously declared as unsigned int
but used with find_closest(), which takes signed int parameters. Change
this array from unsigned int to int to maintain type compatibility with
the find_closest() function signature and prevent compilation errors.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
drivers/watchdog/simatic-ipc-wdt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/watchdog/simatic-ipc-wdt.c b/drivers/watchdog/simatic-ipc-wdt.c
index 1e91f0a560ff..36c68d2ed409 100644
--- a/drivers/watchdog/simatic-ipc-wdt.c
+++ b/drivers/watchdog/simatic-ipc-wdt.c
@@ -59,7 +59,7 @@ static struct resource io_resource_trigger =
static struct resource mem_resource =
DEFINE_RES_MEM_NAMED(0, 0, "WD_RESET_BASE_ADR");
-static u32 wd_timeout_table[] = {2, 4, 6, 8, 16, 32, 48, 64 };
+static int wd_timeout_table[] = {2, 4, 6, 8, 16, 32, 48, 64 };
static void __iomem *wd_reset_base_addr;
static int wd_start(struct watchdog_device *wdd)
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 16/16] lib: move find_closest() and find_closest_descending() to lib functions
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (14 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 15/16] watchdog: simatic-ipc-wdt: " Alexandru Soponar
@ 2025-05-15 8:13 ` Alexandru Soponar
2025-05-19 16:35 ` David Lechner
2025-05-19 15:44 ` [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros " Guenter Roeck
16 siblings, 1 reply; 24+ messages in thread
From: Alexandru Soponar @ 2025-05-15 8:13 UTC (permalink / raw)
To: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact, Alexandru Soponar
Move the utility macros find_closest() and find_closest_descending()
from inline macros to proper library functions in lib/.
Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
---
include/linux/find_closest.h | 13 +++++++
include/linux/util_macros.h | 61 +------------------------------
lib/Makefile | 2 +-
lib/find_closest.c | 71 ++++++++++++++++++++++++++++++++++++
4 files changed, 86 insertions(+), 61 deletions(-)
create mode 100644 include/linux/find_closest.h
create mode 100644 lib/find_closest.c
diff --git a/include/linux/find_closest.h b/include/linux/find_closest.h
new file mode 100644
index 000000000000..28a5c4d0c768
--- /dev/null
+++ b/include/linux/find_closest.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Find closest element functions
+ */
+#ifndef _LINUX_FIND_CLOSEST_H_
+#define _LINUX_FIND_CLOSEST_H_
+
+#include <linux/types.h>
+
+unsigned int find_closest(int x, const int *a, unsigned int as);
+unsigned int find_closest_descending(int x, const int *a, unsigned int as);
+
+#endif /* _LINUX_FIND_CLOSEST_H_ */
diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h
index 825487fb66fa..478d4821f2d1 100644
--- a/include/linux/util_macros.h
+++ b/include/linux/util_macros.h
@@ -3,66 +3,7 @@
#define _LINUX_HELPER_MACROS_H_
#include <linux/math.h>
-
-/**
- * find_closest - locate the closest element in a sorted array
- * @x: The reference value.
- * @a: The array in which to look for the closest element. Must be sorted
- * in ascending order.
- * @as: Size of 'a'.
- *
- * Returns the index of the element closest to 'x'.
- * Note: If using an array of negative numbers (or mixed positive numbers),
- * then be sure that 'x' is of a signed-type to get good results.
- */
-#define find_closest(x, a, as) \
-({ \
- typeof(as) __fc_i, __fc_as = (as) - 1; \
- long __fc_mid_x, __fc_x = (x); \
- long __fc_left, __fc_right; \
- typeof(*a) const *__fc_a = (a); \
- for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \
- __fc_mid_x = (__fc_a[__fc_i] + __fc_a[__fc_i + 1]) / 2; \
- if (__fc_x <= __fc_mid_x) { \
- __fc_left = __fc_x - __fc_a[__fc_i]; \
- __fc_right = __fc_a[__fc_i + 1] - __fc_x; \
- if (__fc_right < __fc_left) \
- __fc_i++; \
- break; \
- } \
- } \
- (__fc_i); \
-})
-
-/**
- * find_closest_descending - locate the closest element in a sorted array
- * @x: The reference value.
- * @a: The array in which to look for the closest element. Must be sorted
- * in descending order.
- * @as: Size of 'a'.
- *
- * Similar to find_closest() but 'a' is expected to be sorted in descending
- * order. The iteration is done in reverse order, so that the comparison
- * of '__fc_right' & '__fc_left' also works for unsigned numbers.
- */
-#define find_closest_descending(x, a, as) \
-({ \
- typeof(as) __fc_i, __fc_as = (as) - 1; \
- long __fc_mid_x, __fc_x = (x); \
- long __fc_left, __fc_right; \
- typeof(*a) const *__fc_a = (a); \
- for (__fc_i = __fc_as; __fc_i >= 1; __fc_i--) { \
- __fc_mid_x = (__fc_a[__fc_i] + __fc_a[__fc_i - 1]) / 2; \
- if (__fc_x <= __fc_mid_x) { \
- __fc_left = __fc_x - __fc_a[__fc_i]; \
- __fc_right = __fc_a[__fc_i - 1] - __fc_x; \
- if (__fc_right < __fc_left) \
- __fc_i--; \
- break; \
- } \
- } \
- (__fc_i); \
-})
+#include <linux/find_closest.h>
/**
* is_insidevar - check if the @ptr points inside the @var memory range.
diff --git a/lib/Makefile b/lib/Makefile
index f1c6e9d76a7c..e8e738c9ced8 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -35,7 +35,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
is_single_threaded.o plist.o decompress.o kobject_uevent.o \
earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
nmi_backtrace.o win_minmax.o memcat_p.o \
- buildid.o objpool.o iomem_copy.o
+ buildid.o objpool.o iomem_copy.o find_closest.o
lib-$(CONFIG_UNION_FIND) += union_find.o
lib-$(CONFIG_PRINTK) += dump_stack.o
diff --git a/lib/find_closest.c b/lib/find_closest.c
new file mode 100644
index 000000000000..d481625cae9d
--- /dev/null
+++ b/lib/find_closest.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Find closest element functions
+ *
+ * Based on previous util_macros.h implementation
+ */
+
+#include <linux/find_closest.h>
+#include <linux/module.h>
+
+/**
+ * find_closest - locate the closest element in a sorted array
+ * @x: The reference value.
+ * @a: The array in which to look for the closest element. Must be sorted
+ * in ascending order.
+ * @as: Size of 'a'.
+ *
+ * Returns the index of the element closest to 'x'.
+ */
+unsigned int find_closest(int x, const int *a, unsigned int as)
+{
+ unsigned int array_size = as - 1;
+ int mid_x, left, right;
+ unsigned int i;
+
+ for (i = 0; i < array_size; i++) {
+ mid_x = (a[i] + a[i + 1]) / 2;
+ if (x <= mid_x) {
+ left = x - a[i];
+ right = a[i + 1] - x;
+ if (right < left)
+ i++;
+ break;
+ }
+ }
+
+ return i;
+}
+EXPORT_SYMBOL_GPL(find_closest);
+
+/**
+ * find_closest_descending - locate the closest element in a sorted array
+ * @x: The reference value.
+ * @a: The array in which to look for the closest element. Must be sorted
+ * in descending order.
+ * @as: Size of 'a'.
+ *
+ * Similar to find_closest() but 'a' is expected to be sorted in descending
+ * order. The iteration is done in reverse order, so that the comparison
+ * of 'right' & 'left' also works for unsigned numbers.
+ */
+unsigned int find_closest_descending(int x, const int *a, unsigned int as)
+{
+ unsigned int array_size = as - 1;
+ int mid_x, left, right;
+ unsigned int i;
+
+ for (i = array_size; i >= 1; i--) {
+ mid_x = (a[i] + a[i - 1]) / 2;
+ if (x <= mid_x) {
+ left = x - a[i];
+ right = a[i - 1] - x;
+ if (right < left)
+ i--;
+ break;
+ }
+ }
+
+ return i;
+}
+EXPORT_SYMBOL_GPL(find_closest_descending);
--
2.49.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH 10/16] iio: ad7606: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 ` [PATCH 10/16] iio: ad7606: " Alexandru Soponar
@ 2025-05-15 17:13 ` Jonathan Cameron
0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2025-05-15 17:13 UTC (permalink / raw)
To: Alexandru Soponar
Cc: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog,
jdelvare, linux, pavel, lee, baocheng.su, wim, tobias.schaffner,
angelogioacchino.delregno, benedikt.niedermayr, matthias.bgg,
aardelean, contact
On Thu, 15 May 2025 11:13:26 +0300
Alexandru Soponar <asoponar@taladin.ro> wrote:
> The ad7606_oversampling_avail and ad7616_oversampling_avail arrays were
> previously declared as unsigned int but used with find_closest(). With
> find_closest() now implemented as a function taking signed int parameters
> instead of a macro, passing unsigned arrays causes type incompatibility
> errors. This patch changes the arrays type from unsigned int to int to
> ensure compatibility with the function signature and prevent compilation
> errors.
>
> Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
Assuming overall approach is fine, this change is fine wrt to ranges
etc.
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/iio/adc/ad7606.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index d8e3c7a43678..41b477ea386d 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -81,11 +81,11 @@ static const unsigned int ad7609_hw_scale_avail[2][2] = {
> { 0, 152588 }, { 0, 305176 }
> };
>
> -static const unsigned int ad7606_oversampling_avail[7] = {
> +static const int ad7606_oversampling_avail[7] = {
> 1, 2, 4, 8, 16, 32, 64,
> };
>
> -static const unsigned int ad7616_oversampling_avail[8] = {
> +static const int ad7616_oversampling_avail[8] = {
> 1, 2, 4, 8, 16, 32, 64, 128,
> };
>
> @@ -835,7 +835,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
> long mask)
> {
> struct ad7606_state *st = iio_priv(indio_dev);
> - unsigned int scale_avail_uv[AD760X_MAX_SCALES];
> + int scale_avail_uv[AD760X_MAX_SCALES];
> struct ad7606_chan_scale *cs;
> int i, ret, ch = 0;
>
> @@ -884,7 +884,7 @@ static ssize_t ad7606_oversampling_ratio_avail(struct device *dev,
> {
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct ad7606_state *st = iio_priv(indio_dev);
> - const unsigned int *vals = st->oversampling_avail;
> + const int *vals = st->oversampling_avail;
> unsigned int i;
> size_t len = 0;
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 11/16] iio: mcp3564: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 ` [PATCH 11/16] iio: mcp3564: " Alexandru Soponar
@ 2025-05-15 17:14 ` Jonathan Cameron
2025-05-19 8:09 ` Marius.Cristea
1 sibling, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2025-05-15 17:14 UTC (permalink / raw)
To: Alexandru Soponar
Cc: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog,
jdelvare, linux, pavel, lee, baocheng.su, wim, tobias.schaffner,
angelogioacchino.delregno, benedikt.niedermayr, matthias.bgg,
aardelean, contact
On Thu, 15 May 2025 11:13:27 +0300
Alexandru Soponar <asoponar@taladin.ro> wrote:
> The mcp3564_oversampling_avail array was previously declared as unsigned
> int but used with find_closest(). With find_closest() now implemented as
> a function taking signed int parameters instead of a macro, passing
> unsigned arrays causes type incompatibility errors. This patch changes the
> arrays type from unsigned int to int to ensure compatibility with the
> function signature and prevent compilation errors.
>
> Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/iio/adc/mcp3564.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c
> index a68f1cd6883e..01efc77f710a 100644
> --- a/drivers/iio/adc/mcp3564.c
> +++ b/drivers/iio/adc/mcp3564.c
> @@ -253,7 +253,7 @@ enum mcp3564_oversampling {
> MCP3564_OVERSAMPLING_RATIO_98304
> };
>
> -static const unsigned int mcp3564_oversampling_avail[] = {
> +static const int mcp3564_oversampling_avail[] = {
> [MCP3564_OVERSAMPLING_RATIO_32] = 32,
> [MCP3564_OVERSAMPLING_RATIO_64] = 64,
> [MCP3564_OVERSAMPLING_RATIO_128] = 128,
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 12/16] iio: max44009: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 ` [PATCH 12/16] iio: max44009: " Alexandru Soponar
@ 2025-05-15 17:14 ` Jonathan Cameron
0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2025-05-15 17:14 UTC (permalink / raw)
To: Alexandru Soponar
Cc: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog,
jdelvare, linux, pavel, lee, baocheng.su, wim, tobias.schaffner,
angelogioacchino.delregno, benedikt.niedermayr, matthias.bgg,
aardelean, contact
On Thu, 15 May 2025 11:13:28 +0300
Alexandru Soponar <asoponar@taladin.ro> wrote:
> The max44009_int_time_ns_array array was previously declared as u32 but
> used with find_closest(). With find_closest() now implemented as a
> function taking signed int parameters instead of a macro, passing unsigned
> arrays causes type incompatibility errors. This patch changes the arrays
> type from u32 to int to ensure compatibility with the function signature
> and prevent compilation errors.
>
> Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/iio/light/max44009.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/light/max44009.c b/drivers/iio/light/max44009.c
> index 8cd7f5664e5b..d274224fc210 100644
> --- a/drivers/iio/light/max44009.c
> +++ b/drivers/iio/light/max44009.c
> @@ -55,7 +55,7 @@
> /* The fixed-point fractional multiplier for de-scaling threshold values */
> #define MAX44009_FRACT_MULT 1000000
>
> -static const u32 max44009_int_time_ns_array[] = {
> +static const int max44009_int_time_ns_array[] = {
> 800000000,
> 400000000,
> 200000000,
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 11/16] iio: mcp3564: Fix type incompatibility with non-macro find_closest
2025-05-15 8:13 ` [PATCH 11/16] iio: mcp3564: " Alexandru Soponar
2025-05-15 17:14 ` Jonathan Cameron
@ 2025-05-19 8:09 ` Marius.Cristea
1 sibling, 0 replies; 24+ messages in thread
From: Marius.Cristea @ 2025-05-19 8:09 UTC (permalink / raw)
To: linux-leds, asoponar, linux-hwmon, linux-kernel, linux-iio,
linux-watchdog
Cc: linux, jdelvare, wim, lee, angelogioacchino.delregno, aardelean,
jic23, pavel, tobias.schaffner, baocheng.su, matthias.bgg,
contact, benedikt.niedermayr
On Thu, 2025-05-15 at 11:13 +0300, Alexandru Soponar wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
>
> The mcp3564_oversampling_avail array was previously declared as
> unsigned
> int but used with find_closest(). With find_closest() now implemented
> as
> a function taking signed int parameters instead of a macro, passing
> unsigned arrays causes type incompatibility errors. This patch
> changes the
> arrays type from unsigned int to int to ensure compatibility with the
> function signature and prevent compilation errors.
>
> Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
Hi Alexandru,
Thank you very much for the patch. The patch is OK.
Reviewed-by: Marius Cristea <marius.cristea@microchip.com>
Thanks,
Marius
> ---
> drivers/iio/adc/mcp3564.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c
> index a68f1cd6883e..01efc77f710a 100644
> --- a/drivers/iio/adc/mcp3564.c
> +++ b/drivers/iio/adc/mcp3564.c
> @@ -253,7 +253,7 @@ enum mcp3564_oversampling {
> MCP3564_OVERSAMPLING_RATIO_98304
> };
>
> -static const unsigned int mcp3564_oversampling_avail[] = {
> +static const int mcp3564_oversampling_avail[] = {
> [MCP3564_OVERSAMPLING_RATIO_32] = 32,
> [MCP3564_OVERSAMPLING_RATIO_64] = 64,
> [MCP3564_OVERSAMPLING_RATIO_128] = 128,
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
` (15 preceding siblings ...)
2025-05-15 8:13 ` [PATCH 16/16] lib: move find_closest() and find_closest_descending() to lib functions Alexandru Soponar
@ 2025-05-19 15:44 ` Guenter Roeck
16 siblings, 0 replies; 24+ messages in thread
From: Guenter Roeck @ 2025-05-19 15:44 UTC (permalink / raw)
To: Alexandru Soponar, linux-kernel, linux-hwmon, linux-iio,
linux-leds, linux-watchdog
Cc: jdelvare, jic23, pavel, lee, baocheng.su, wim, tobias.schaffner,
angelogioacchino.delregno, benedikt.niedermayr, matthias.bgg,
aardelean, contact
On 5/15/25 01:13, Alexandru Soponar wrote:
> This patch series converts the find_closest() and find_closest_descending() macros
> into proper library functions. The conversion moves these utilities from macro
> implementations in util_macros.h to standard C functions in lib/find_closest.c.
>
> The first 15 patches modify individual callers across hwmon, iio, leds, regulator,
> and watchdog subsystems to ensure they work correctly with the new function-based
> implementation. This maintains compatibility while allowing the final conversion.
>
> The final patch implements the actual refactoring by moving the code to
> lib/find_closest.c. This approach was chosen based on discussions between
> Andrew Morton and Alexandru Ardelean[1], who suggested that a non-inline
> implementation would be appropriate given the size of the functions.
>
> The refactoring avoids of macro expansion-related issues and proper function
> prototypes with well-defined parameter types.
>
> Links:
> [1] https://lore.kernel.org/lkml/20241105145406.554365-1-aardelean@baylibre.com/
>
> Alexandru Soponar (16):
> hwmon: w83795: Fix type incompatibility with non-macro find_closest
> hwmon: emc1403: Fix type incompatibility with non-macro find_closest
> hwmon: ina3221: Fix type incompatibility with non-macro find_closest
> hwmon: lm95234: Fix type incompatibility with non-macro find_closest
> hwmon: max1619: Fix type incompatibility with non-macro find_closest
> hwmon: lm75: Fix type incompatibility with non-macro find_closest
> hwmon: ltc4282: Fix type incompatibility with non-macro find_closest
> hwmon: max6639: Fix type incompatibility with non-macro find_closest
> hwmon: max20740: Fix type incompatibility with non-macro find_closest
> iio: ad7606: Fix type incompatibility with non-macro find_closest
> iio: mcp3564: Fix type incompatibility with non-macro find_closest
> iio: max44009: Fix type incompatibility with non-macro find_closest
> leds: eds-mt6370-rgb: Fix type incompatibility with find_closest()
> regulator: max77857: Fix type incompatibility with find_closest()
> watchdog: simatic-ipc-wdt: Fix type incompatibility with
> find_closest()
For the hwmon and watchdog patches:
Acked-by: Guenter Roeck <linux@roeck-us.net>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 16/16] lib: move find_closest() and find_closest_descending() to lib functions
2025-05-15 8:13 ` [PATCH 16/16] lib: move find_closest() and find_closest_descending() to lib functions Alexandru Soponar
@ 2025-05-19 16:35 ` David Lechner
0 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-05-19 16:35 UTC (permalink / raw)
To: Alexandru Soponar, linux-kernel, linux-hwmon, linux-iio,
linux-leds, linux-watchdog
Cc: jdelvare, linux, jic23, pavel, lee, baocheng.su, wim,
tobias.schaffner, angelogioacchino.delregno, benedikt.niedermayr,
matthias.bgg, aardelean, contact
On 5/15/25 3:13 AM, Alexandru Soponar wrote:
> Move the utility macros find_closest() and find_closest_descending()
> from inline macros to proper library functions in lib/.
>
> Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
> ---
> include/linux/find_closest.h | 13 +++++++
> include/linux/util_macros.h | 61 +------------------------------
> lib/Makefile | 2 +-
> lib/find_closest.c | 71 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 86 insertions(+), 61 deletions(-)
> create mode 100644 include/linux/find_closest.h
> create mode 100644 lib/find_closest.c
>
> diff --git a/include/linux/find_closest.h b/include/linux/find_closest.h
> new file mode 100644
> index 000000000000..28a5c4d0c768
> --- /dev/null
> +++ b/include/linux/find_closest.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Find closest element functions
> + */
> +#ifndef _LINUX_FIND_CLOSEST_H_
> +#define _LINUX_FIND_CLOSEST_H_
> +
> +#include <linux/types.h>
Is this header really needed?
> +
> +unsigned int find_closest(int x, const int *a, unsigned int as);
> +unsigned int find_closest_descending(int x, const int *a, unsigned int as);
> +
> +#endif /* _LINUX_FIND_CLOSEST_H_ */
...
> diff --git a/lib/find_closest.c b/lib/find_closest.c
> new file mode 100644
> index 000000000000..d481625cae9d
> --- /dev/null
> +++ b/lib/find_closest.c
> @@ -0,0 +1,71 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Find closest element functions
> + *
> + * Based on previous util_macros.h implementation
> + */
> +
> +#include <linux/find_closest.h>
> +#include <linux/module.h>
> +
> +/**
> + * find_closest - locate the closest element in a sorted array
> + * @x: The reference value.
> + * @a: The array in which to look for the closest element. Must be sorted
> + * in ascending order.
> + * @as: Size of 'a'.
> + *
> + * Returns the index of the element closest to 'x'.
s/Returns/Returns:/
for kernel-doc semantics
> + */
> +unsigned int find_closest(int x, const int *a, unsigned int as)
> +{
> + unsigned int array_size = as - 1;
> + int mid_x, left, right;
> + unsigned int i;
> +
> + for (i = 0; i < array_size; i++) {
> + mid_x = (a[i] + a[i + 1]) / 2;
> + if (x <= mid_x) {
> + left = x - a[i];
> + right = a[i + 1] - x;
> + if (right < left)
> + i++;
> + break;
> + }
> + }
> +
> + return i;
> +}
> +EXPORT_SYMBOL_GPL(find_closest);
> +
> +/**
> + * find_closest_descending - locate the closest element in a sorted array
> + * @x: The reference value.
> + * @a: The array in which to look for the closest element. Must be sorted
> + * in descending order.
> + * @as: Size of 'a'.
> + *
Would repeat the Returns: section here for completeness.
> + * Similar to find_closest() but 'a' is expected to be sorted in descending
> + * order.
This seems redundant since @a already says this.
> The iteration is done in reverse order, so that the comparison> + * of 'right' & 'left' also works for unsigned numbers.
This seems like an implementation detail so would be better as a comment inside
the function. Although, since @a is always signed, is this comment actually
still applicable?
> + */
> +unsigned int find_closest_descending(int x, const int *a, unsigned int as)
> +{
> + unsigned int array_size = as - 1;
> + int mid_x, left, right;
> + unsigned int i;
> +
> + for (i = array_size; i >= 1; i--) {
> + mid_x = (a[i] + a[i - 1]) / 2;
> + if (x <= mid_x) {
> + left = x - a[i];
> + right = a[i - 1] - x;
> + if (right < left)
> + i--;
> + break;
> + }
> + }
> +
> + return i;
> +}
> +EXPORT_SYMBOL_GPL(find_closest_descending);
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 13/16] leds: eds-mt6370-rgb: Fix type incompatibility with find_closest()
2025-05-15 8:13 ` [PATCH 13/16] leds: eds-mt6370-rgb: Fix type incompatibility with find_closest() Alexandru Soponar
@ 2025-05-22 14:33 ` Lee Jones
0 siblings, 0 replies; 24+ messages in thread
From: Lee Jones @ 2025-05-22 14:33 UTC (permalink / raw)
To: Alexandru Soponar
Cc: linux-kernel, linux-hwmon, linux-iio, linux-leds, linux-watchdog,
jdelvare, linux, jic23, pavel, baocheng.su, wim, tobias.schaffner,
angelogioacchino.delregno, benedikt.niedermayr, matthias.bgg,
aardelean, contact
On Thu, 15 May 2025, Alexandru Soponar wrote:
> The common_tfreqs and mt6372_tfreqs arrays were previously declared as
> unsigned int but used with find_closest(), which now takes signed int
> parameters. Change these arrays from unsigned int to int to maintain type
> compatibility with the find_closest() function signature and prevent
> compilation errors.
>
> Signed-off-by: Alexandru Soponar <asoponar@taladin.ro>
> ---
> drivers/leds/rgb/leds-mt6370-rgb.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
Acked-by: Lee Jones <lee@kernel.org>
> diff --git a/drivers/leds/rgb/leds-mt6370-rgb.c b/drivers/leds/rgb/leds-mt6370-rgb.c
> index ebd3ba878dd5..6ce11432dd96 100644
> --- a/drivers/leds/rgb/leds-mt6370-rgb.c
> +++ b/drivers/leds/rgb/leds-mt6370-rgb.c
> @@ -135,7 +135,7 @@ struct mt6370_led {
> };
>
> struct mt6370_pdata {
> - const unsigned int *tfreq;
> + const int *tfreq;
> unsigned int tfreq_len;
> u16 reg_rgb1_tr;
> s16 reg_rgb_chrind_tr;
> @@ -212,11 +212,11 @@ static const struct linear_range mt6372_led_ranges[R_MAX_RANGES] = {
> [R_LED_TOFF] = { 250, 0, 15, 500 },
> };
>
> -static const unsigned int common_tfreqs[] = {
> +static const int common_tfreqs[] = {
> 10000, 5000, 2000, 1000, 500, 200, 5, 1,
> };
>
> -static const unsigned int mt6372_tfreqs[] = {
> +static const int mt6372_tfreqs[] = {
> 8000, 4000, 2000, 1000, 500, 250, 8, 4,
> };
>
> @@ -304,7 +304,8 @@ static int mt6370_set_led_freq(struct mt6370_priv *priv, unsigned int led_no, un
> const struct mt6370_pdata *pdata = priv->pdata;
> enum mt6370_led_field sel_field;
> unsigned int tfreq_len = pdata->tfreq_len;
> - unsigned int tsum, sel;
> + unsigned int sel;
> + int tsum;
>
> tsum = ton + toff;
>
> --
> 2.49.0
>
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2025-05-22 14:33 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-15 8:13 [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros to lib functions Alexandru Soponar
2025-05-15 8:13 ` [PATCH 01/16] hwmon: w83795: Fix type incompatibility with non-macro find_closest Alexandru Soponar
2025-05-15 8:13 ` [PATCH 02/16] hwmon: emc1403: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 03/16] hwmon: ina3221: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 04/16] hwmon: lm95234: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 05/16] hwmon: max1619: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 06/16] hwmon: lm75: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 07/16] hwmon: ltc4282: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 08/16] hwmon: max6639: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 09/16] hwmon: max20740: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 10/16] iio: ad7606: " Alexandru Soponar
2025-05-15 17:13 ` Jonathan Cameron
2025-05-15 8:13 ` [PATCH 11/16] iio: mcp3564: " Alexandru Soponar
2025-05-15 17:14 ` Jonathan Cameron
2025-05-19 8:09 ` Marius.Cristea
2025-05-15 8:13 ` [PATCH 12/16] iio: max44009: " Alexandru Soponar
2025-05-15 17:14 ` Jonathan Cameron
2025-05-15 8:13 ` [PATCH 13/16] leds: eds-mt6370-rgb: Fix type incompatibility with find_closest() Alexandru Soponar
2025-05-22 14:33 ` Lee Jones
2025-05-15 8:13 ` [PATCH 14/16] regulator: max77857: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 15/16] watchdog: simatic-ipc-wdt: " Alexandru Soponar
2025-05-15 8:13 ` [PATCH 16/16] lib: move find_closest() and find_closest_descending() to lib functions Alexandru Soponar
2025-05-19 16:35 ` David Lechner
2025-05-19 15:44 ` [PATCH 0/16] lib: Refactor find_closest() and find_closest_descending() from macros " Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).