From: "Bianca Costa Galvão" <biancalvao@gmail.com>
To: jic23@kernel.org
Cc: "Bianca Costa Galvão" <biancagalvao@usp.br>,
"Júlia Calixto Rosa" <juliacalixtorosa@usp.br>,
linux-iio@vger.kernel.org
Subject: [PATCH] iio: magnetometer: mmc35240: refactor volatile and writeable reg functions
Date: Sat, 26 Apr 2025 16:41:32 -0300 [thread overview]
Message-ID: <20250426194135.244774-1-biancalvao@gmail.com> (raw)
From: Bianca Costa Galvão <biancagalvao@usp.br>
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'.
Signed-off-by: Bianca Costa Galvão <biancagalvao@usp.br>
Co-developed-by: Júlia Calixto Rosa <juliacalixtorosa@usp.br>
Signed-off-by: Júlia Calixto Rosa <juliacalixtorosa@usp.br>
---
drivers/iio/magnetometer/mmc35240.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c
index e08a57cd6de2..07f58567e521 100644
--- a/drivers/iio/magnetometer/mmc35240.c
+++ b/drivers/iio/magnetometer/mmc35240.c
@@ -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[] = {
--
2.43.0
next reply other threads:[~2025-04-26 19:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-26 19:41 Bianca Costa Galvão [this message]
2025-05-05 15:19 ` [PATCH] iio: magnetometer: mmc35240: refactor volatile and writeable reg functions Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250426194135.244774-1-biancalvao@gmail.com \
--to=biancalvao@gmail.com \
--cc=biancagalvao@usp.br \
--cc=jic23@kernel.org \
--cc=juliacalixtorosa@usp.br \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox