Skip to contentSkip to conversation

iio: magnetometer: mmc35240: unify reg-access predicates

PATCH In review Bianca 3 participants 4 messages May 26, 2025 – Jun 18, 2025 1 message not in the archive IIO

lore
Share & tools
lore

Bianca

author
#0 lore raw

PATCH v2 1/1 iio: magnetometer: mmc35240: unify reg-access predicates

From: Bianca Costa Galvão <[email protected]>

Refactor the two complementary helper functions mmc35240_is_volatile_reg() and mmc35240_is_writeable_reg() by implementing the volatile predicate as the logical negation of the writeable predicate. This removes the duplicate bit-mask checks and makes the intent clearer.

Changes since v1:
- Removed the obsolete mmc35240_reg_check() helper.
- Wrapped commit message and body to 75 columns.
- Fixed indentation in mmc35240_is_writeable_reg() to use tabs.

---
 drivers/iio/magnetometer/mmc35240.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/iio/magnetometer/mmc35240.c +8 -6
index 07f58567e521..6cfb89295802 100644
@@ -418,14 +418,16 @@ 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)
 {
-	return mmc35240_reg_check(reg);
+	switch (reg) {
+	case MMC35240_REG_CTRL0:
+	case MMC35240_REG_CTRL1:
+		return true;
+	default:
+    	return false;
+	}
 }
 
 static bool mmc35240_is_readable_reg(struct device *dev, unsigned int reg)
@@ -447,7 +449,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)
 {
-	return !mmc35240_reg_check(reg);
+	return !mmc35240_is_writeable_reg(dev, reg);
 }
 
 static const struct reg_default mmc35240_reg_defaults[] = {
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 32 lines · On Mon, 26 May 2025 09:03:30 -0300 Bianca <[email protected]> wrote:

From: Bianca Costa Galvão <[email protected]>

Refactor the two complementary helper functions mmc35240_is_volatile_reg() and mmc35240_is_writeable_reg() by implementing the volatile predicate as the logical negation of the writeable predicate. This removes the duplicate bit-mask checks and makes the intent clearer.

Changes since v1:
- Removed the obsolete mmc35240_reg_check() helper.
- Wrapped commit message and body to 75 columns.
- Fixed indentation in mmc35240_is_writeable_reg() to use tabs.

---
 drivers/iio/magnetometer/mmc35240.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/iio/magnetometer/mmc35240.c +0 -4
index 07f58567e521..6cfb89295802 100644
@@ -418,14 +418,16 @@ 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;
-}

drivers/iio/magnetometer/mmc35240.c static const struct iio_info mmc35240_info = { · line 429

Quoted 10 lines
drivers/iio/magnetometer/mmc35240.c +6 -1
 
 static bool mmc35240_is_writeable_reg(struct device *dev, unsigned int reg)
 {
-	return mmc35240_reg_check(reg);
+	switch (reg) {
+	case MMC35240_REG_CTRL0:
+	case MMC35240_REG_CTRL1:
+		return true;
+	default:
+    	return false;

Indent is incorrect. This should be two tabs in but it is in spaces. Please run scripts/checkpatch.pl over your patches before sending.

Quoted 13 lines
drivers/iio/magnetometer/mmc35240.c +2 -1
+	}
 }
 
 static bool mmc35240_is_readable_reg(struct device *dev, unsigned int reg)
@@ -447,7 +449,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)
 {
-	return !mmc35240_reg_check(reg);
+	return !mmc35240_is_writeable_reg(dev, reg);
 }
 
 static const struct reg_default mmc35240_reg_defaults[] = {
#2 lore raw
In reply to Bianca

Hello Bianca, Júlia,

Some comments in addition to what Jonathan mentioned.
Though, unless I'm missing anything, I'd say there may be no reason for a v3. Please, see comments below.

Quoted 8 lines · Bianca

From: Bianca Costa Galvão <[email protected]>

Refactor the two complementary helper functions mmc35240_is_volatile_reg() and mmc35240_is_writeable_reg() by implementing the volatile predicate as the logical negation of the writeable predicate. This removes the duplicate bit-mask checks and makes the intent clearer.

Quoted 4 lines

Changes since v1:
- Removed the obsolete mmc35240_reg_check() helper.
- Wrapped commit message and body to 75 columns.
- Fixed indentation in mmc35240_is_writeable_reg() to use tabs.

The change log looks good, but it should come after the "---". As it is, the change log would appear in the commit logs if the patch is applied, and we don't want change logs in commit descriptions.

Quoted 2 lines

checkpacth also points a sender/sign-off mismatch. There should be a way to fix that with some git format-patch or git send-email flag.

Quoted 3 lines

---

This is the place where the change log is expected to be.

drivers/iio/magnetometer/mmc35240.c static const struct iio_info mmc35240_info = { · line 421

Quoted 12 lines
 drivers/iio/magnetometer/mmc35240.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/iio/magnetometer/mmc35240.c +0 -1
index 07f58567e521..6cfb89295802 100644
@@ -418,14 +418,16 @@ static const struct iio_info mmc35240_info = {
 	.attrs		= &mmc35240_attribute_group,
 };
 
-static bool mmc35240_reg_check(unsigned int reg)

Couldn't find any mmc35240_reg_check() in current IIO testing branch. Was that leftover from out of tree commit? Am I missing anything? Please, avoid such things. This patch just fails to apply to IIO testing.

Quoted 18 lines
drivers/iio/magnetometer/mmc35240.c +7 -4
-{
-	return reg == MMC35240_REG_CTRL0 || reg == MMC35240_REG_CTRL1;
-}
 
 static bool mmc35240_is_writeable_reg(struct device *dev, unsigned int reg)
 {
-	return mmc35240_reg_check(reg);
+	switch (reg) {
+	case MMC35240_REG_CTRL0:
+	case MMC35240_REG_CTRL1:
+		return true;
+	default:
+    	return false;
+	}
 }
 
 static bool mmc35240_is_readable_reg(struct device *dev, unsigned int reg)

drivers/iio/magnetometer/mmc35240.c static bool mmc35240_is_readable_reg(struct device *dev, unsigned int reg) · line 452

Quoted 5 lines
drivers/iio/magnetometer/mmc35240.c +1 -1
@@ -447,7 +449,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)
 {
-	return !mmc35240_reg_check(reg);
+	return !mmc35240_is_writeable_reg(dev, reg);

I think this logic doesn't really apply to this sensor.
There is a product ID register (MMC35240_REG_ID) that seems to be read-only and not volatile. I think this patch doesn't make much sense.

With best regards,
Marcelo

A message that is not in the archive (sent off-list or not yet received): CA+eNY9r9fP50uoMKO_s_Dn3QPY4xy0Hdp_Q7+tX80FdXgx1Scw@mail.gmail.com

#4 lore raw
Quoted 4 lines

*4. Volatile vs. writeable logic*
Rather than inverting is_writeable, would you recommend instead
enumerating explicitly only the registers that truly change—for example, status and data registers—while leaving everything else non‑volatile?

Looks like that's already done at mmc35240_is_volatile_reg(). Since there are fewer non-volatile registers, it's more concise to enumerate those.

Quoted 4 lines

Do you think it’s worthwhile to implement that explicit approach here? If these adjustments look good, I will incorporate them and send PATCH v3 later today. Please let me know if you have any further suggestions or questions.

Maybe you could do
static bool mmc35240_is_writeable_reg(struct device *dev, unsigned int reg)

{
	return !mmc35240_is_volatile_reg(...);
}

or the other way around. Although, such patches might not worth it since the proposed improvement is very small (and questionable) while the upstreaming process still requires some effort.

Otherwise, I don't have any improvement suggestion for this driver.

As general (not necessarily good) tip, I'd suggest to look at possible uses of FIELD_PREP and FIELD_GET (see include/linux/bitfield.h). Those tend to improve code robustness and readability. I don't have any specific suggestion, though.

Best regards,
Marcelo