iio: proximity: sx9324: Convert GENMASK() to use static parameters
PATCH 1/1 iio: proximity: sx9324: Convert GENMASK() to use static parameters
There is no need to use run-time calculated masks in the code. Besides, GENMASK() over non-static parameters might lead compiler to generate much worse code.
--- drivers/iio/proximity/sx9324.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/proximity/sx9324.c +3 -5
@@ -72,8 +72,7 @@#define SX9324_REG_AFE_CTRL6 0x26#define SX9324_REG_AFE_CTRL7 0x27#define SX9324_REG_AFE_PH0 0x28 -#define SX9324_REG_AFE_PH0_PIN_MASK (_pin) \ - GENMASK(2 * (_pin) + 1, 2 * (_pin)) +#define SX9324_REG_AFE_PH0_PIN_MASK GENMASK(1, 0)#define SX9324_REG_AFE_PH1 0x29#define SX9324_REG_AFE_PH2 0x2a
@@ -187,7 +186,7 @@ static ssize_t sx9324_phase_configuration_show(struct iio_dev *indio_dev,return ret;for (i =0 ; i <SX9324_NUM_PINS ; i++) { - pin_idx = (val &SX9324_REG_AFE_PH0_PIN_MASK (i)) >> (2 * i); + pin_idx = (val >> (2 * i)) &SX9324_REG_AFE_PH0_PIN_MASK ; len +=sysfs_emit_at (buf, len,"%s," , sx9324_cs_pin_usage[pin_idx]); }
@@ -877,8 +876,7 @@ static u8 sx9324_parse_phase_prop(struct device *dev,return reg_def->def;for (pin =0 ; pin <SX9324_NUM_PINS ; pin++) - raw |= (pin_defs[pin] << (2 * pin)) & -SX9324_REG_AFE_PH0_PIN_MASK (pin); + raw |= (pin_defs[pin] &SX9324_REG_AFE_PH0_PIN_MASK ) << (2 * pin);return raw; }
Signature · 1 line
2.50.1
Quoted 3 lines · Andy Shevchenko
There is no need to use run-time calculated masks in the code. Besides,
GENMASK()over non-static parameters might lead compiler to generate much worse code.
The new extraction and packing are equivalent to the old per-pin masks for all register values and DT inputs (checked exhaustively), and the patch applies cleanly on top of my pending sx93xx series.
Jonathan Cameron
maintainerQuoted 14 lines · On Tue, 17 Nov 2026 15:35:56 +0100 Andy Shevchenko…
There is no need to use run-time calculated masks in the code. Besides,
GENMASK()over non-static parameters might lead compiler to generate much worse code.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/iio/proximity/sx9324.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/iio/proximity/sx9324.c +0
-0
drivers/iio/proximity/sx9324.c line 75
Quoted 6 lines
drivers/iio/proximity/sx9324.c +1
-2@@ -72,8 +72,7 @@#define SX9324_REG_AFE_CTRL6 0x26#define SX9324_REG_AFE_CTRL7 0x27#define SX9324_REG_AFE_PH0 0x28 -#define SX9324_REG_AFE_PH0_PIN_MASK (_pin) \ - GENMASK(2 * (_pin) + 1, 2 * (_pin)) +#define SX9324_REG_AFE_PH0_PIN_MASK GENMASK(1, 0)
I'm not keen on a mask being defined that doesn't correspond closely to anything on the data sheet and these are not hot paths. The original code is nasty but if we are going to change it I think we needs something cleaner than this.
My first instinct is going for the thing that may well give the worse code gen and use the dynamic field_get() field_prep() calls with the mask still being generated at runtime. Or given it's only 3 entrees just define SX9324_REG_AFE_PHI_PIN0_MASK GENMASK(1, 0) SX9324_REG_AFE_PHI_PIN1_MASK GENMASK(3, 2) SX9324_REG_AFE_PHI_PIN2_MASK GENMASK(5, 4)
and drop the loops that are making this messy.
Quoted 22 lines
drivers/iio/proximity/sx9324.c +2
-3#define SX9324_REG_AFE_PH1 0x29#define SX9324_REG_AFE_PH2 0x2a@@ -187,7 +186,7 @@ static ssize_t sx9324_phase_configuration_show(struct iio_dev *indio_dev,return ret;for (i =0 ; i <SX9324_NUM_PINS ; i++) { - pin_idx = (val &SX9324_REG_AFE_PH0_PIN_MASK (i)) >> (2 * i); + pin_idx = (val >> (2 * i)) &SX9324_REG_AFE_PH0_PIN_MASK ; len +=sysfs_emit_at (buf, len,"%s," , sx9324_cs_pin_usage[pin_idx]); }@@ -877,8 +876,7 @@ static u8 sx9324_parse_phase_prop(struct device *dev,return reg_def->def;for (pin =0 ; pin <SX9324_NUM_PINS ; pin++) - raw |= (pin_defs[pin] << (2 * pin)) & -SX9324_REG_AFE_PH0_PIN_MASK (pin); + raw |= (pin_defs[pin] &SX9324_REG_AFE_PH0_PIN_MASK ) << (2 * pin);return raw; }