iio: magnetometer: mmc35240: refactor volatile and writeable reg functions
PATCH 1/1 iio: magnetometer: mmc35240: refactor volatile and writeable reg functions
From: Bianca Costa Galvão <[email protected]>
Refactor 'mmc35240_is_volatile_reg' and 'mmc35240_is_writeable_reg' as they share similar logic, returning the inverse of each other.
Introduce a new helper function 'mmc35240_reg_check' to generalize this behavior, which is then used by both 'mmc35240_is_volatile_reg' and 'mmc35240_is_writeable_reg'.
--- drivers/iio/magnetometer/mmc35240.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
drivers/iio/magnetometer/mmc35240.c +7 -14
@@ -418,15 +418,14 @@ static const struct iio_info mmc35240_info = { .attrs = &mmc35240_attribute_group, }; +static bool mmc35240_reg_check (unsigned int reg) +{ +return reg ==MMC35240_REG_CTRL0 || reg ==MMC35240_REG_CTRL1 ; +} +static bool mmc35240_is_writeable_reg (struct device *dev,unsigned int reg) { -switch (reg) { -case MMC35240_REG_CTRL0 : -case MMC35240_REG_CTRL1 : -return true; -default : -return false; - } +return mmc35240_reg_check (reg); }static bool mmc35240_is_readable_reg (struct device *dev,unsigned int reg)
@@ -448,13 +447,7 @@ static bool mmc35240_is_readable_reg(struct device *dev, unsigned int reg)static bool mmc35240_is_volatile_reg (struct device *dev,unsigned int reg) { -switch (reg) { -case MMC35240_REG_CTRL0 : -case MMC35240_REG_CTRL1 : -return false; -default : -return true; - } +return !mmc35240_reg_check (reg); }static const struct reg_default mmc35240_reg_defaults[] = {
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerQuoted 5 lines · On Sat, 26 Apr 2025 16:41:32 -0300 Bianca Costa Galvão <[email protected]>…
From: Bianca Costa Galvão <[email protected]>
Refactor '
mmc35240_is_volatile_reg' and 'mmc35240_is_writeable_reg' as they share similar logic, returning the inverse of each other.
Quoted 7 lines
Introduce a new helper function '
mmc35240_reg_check' to generalize this behavior, which is then used by both 'mmc35240_is_volatile_reg' and 'mmc35240_is_writeable_reg'.Signed-off-by Bianca Costa Galvão <[email protected]>Co-developed-by Júlia Calixto Rosa <[email protected]>Signed-off-by Júlia Calixto Rosa <[email protected]>
Hi Bianca, Júlia
The patch is mostly fine but I think the naming as_reg_check() is not helpful as it doesn't indicate anything specific is being checked. I think ti would be cleaner to leave _is_writeable_reg() alone and them make the implementation of _is_volatile_reg()
return !mmc35240_is_writeable_reg(dev, reg);
Which will effectively document that all non writeable registers are volatile.
Jonathan
Quoted 45 lines
--- drivers/iio/magnetometer/mmc35240.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)drivers/iio/magnetometer/mmc35240.c +7
-14@@ -418,15 +418,14 @@ static const struct iio_info mmc35240_info = { .attrs = &mmc35240_attribute_group, }; +static bool mmc35240_reg_check (unsigned int reg) +{ +return reg ==MMC35240_REG_CTRL0 || reg ==MMC35240_REG_CTRL1 ; +} +static bool mmc35240_is_writeable_reg (struct device *dev,unsigned int reg) { -switch (reg) { -case MMC35240_REG_CTRL0 : -case MMC35240_REG_CTRL1 : -return true; -default : -return false; - } +return mmc35240_reg_check (reg); }static bool mmc35240_is_readable_reg (struct device *dev,unsigned int reg)@@ -448,13 +447,7 @@ static bool mmc35240_is_readable_reg(struct device *dev, unsigned int reg)static bool mmc35240_is_volatile_reg (struct device *dev,unsigned int reg) { -switch (reg) { -case MMC35240_REG_CTRL0 : -case MMC35240_REG_CTRL1 : -return false; -default : -return true; - } +return !mmc35240_reg_check (reg); }static const struct reg_default mmc35240_reg_defaults[] = {