* [PATCH] i2c: i2c-mux: Simplify boolean assignment in i2c_mux_alloc
@ 2025-08-24 18:14 I Viswanath
2025-08-25 1:30 ` Akhilesh Patil
0 siblings, 1 reply; 3+ messages in thread
From: I Viswanath @ 2025-08-24 18:14 UTC (permalink / raw)
To: peda; +Cc: wsa+renesas, linux-i2c, skhan, linux-kernel-mentees, I Viswanath
Refactor boolean field assignments of the form `if (a) b = true` to `b = a`
in i2c_mux_alloc
Signed-off-by: I Viswanath <viswanathiyyappan@gmail.com>
---
drivers/i2c/i2c-mux.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 4d8690981a55..abf63758856b 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -241,12 +241,9 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
muxc->parent = parent;
muxc->dev = dev;
- if (flags & I2C_MUX_LOCKED)
- muxc->mux_locked = true;
- if (flags & I2C_MUX_ARBITRATOR)
- muxc->arbitrator = true;
- if (flags & I2C_MUX_GATE)
- muxc->gate = true;
+ muxc->mux_locked = flags & I2C_MUX_LOCKED;
+ muxc->arbitrator = flags & I2C_MUX_ARBITRATOR;
+ muxc->gate = flags & I2C_MUX_GATE;
muxc->select = select;
muxc->deselect = deselect;
muxc->max_adapters = max_adapters;
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: i2c-mux: Simplify boolean assignment in i2c_mux_alloc
2025-08-24 18:14 [PATCH] i2c: i2c-mux: Simplify boolean assignment in i2c_mux_alloc I Viswanath
@ 2025-08-25 1:30 ` Akhilesh Patil
2025-08-25 3:14 ` [PATCH v2] " I Viswanath
0 siblings, 1 reply; 3+ messages in thread
From: Akhilesh Patil @ 2025-08-25 1:30 UTC (permalink / raw)
To: I Viswanath; +Cc: peda, wsa+renesas, linux-i2c, skhan, linux-kernel-mentees
On Sun, Aug 24, 2025 at 11:44:16PM +0530, I Viswanath wrote:
> Refactor boolean field assignments of the form `if (a) b = true` to `b = a`
> in i2c_mux_alloc
>
> Signed-off-by: I Viswanath <viswanathiyyappan@gmail.com>
> ---
> drivers/i2c/i2c-mux.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index 4d8690981a55..abf63758856b 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -241,12 +241,9 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
>
> muxc->parent = parent;
> muxc->dev = dev;
> - if (flags & I2C_MUX_LOCKED)
> - muxc->mux_locked = true;
> - if (flags & I2C_MUX_ARBITRATOR)
> - muxc->arbitrator = true;
> - if (flags & I2C_MUX_GATE)
> - muxc->gate = true;
> + muxc->mux_locked = flags & I2C_MUX_LOCKED;
> + muxc->arbitrator = flags & I2C_MUX_ARBITRATOR;
> + muxc->gate = flags & I2C_MUX_GATE;
Although it looks correct after checking that mux_locked, arbitrator
and gate are 1 bit bitfields. I think below with more explicitm, would be nice.
muxc->mux_locked = !!(flags & I2C_MUX_LOCKED);
muxc->arbitrator = !!(flags & I2C_MUX_ARBITRATOR);
muxc->gate = !!(flags & I2C_MUX_GATE);
Regards,
Akhilesh
> muxc->select = select;
> muxc->deselect = deselect;
> muxc->max_adapters = max_adapters;
> --
> 2.50.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] i2c: i2c-mux: Simplify boolean assignment in i2c_mux_alloc
2025-08-25 1:30 ` Akhilesh Patil
@ 2025-08-25 3:14 ` I Viswanath
0 siblings, 0 replies; 3+ messages in thread
From: I Viswanath @ 2025-08-25 3:14 UTC (permalink / raw)
To: akhilesh
Cc: peda, wsa+renesas, linux-i2c, skhan, linux-kernel-mentees,
I Viswanath
Refactor boolean field assignments of the form `if (a) b = true` to `b = a`
in i2c_mux_alloc
Signed-off-by: I Viswanath <viswanathiyyappan@gmail.com>
---
v2:
- Converted the assigned expressions to 1 bit values before assignment to make
the bitfield assignment more explict according to Akhilesh Patil's suggestion.
drivers/i2c/i2c-mux.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 4d8690981a55..d59644e50f14 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -241,12 +241,9 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
muxc->parent = parent;
muxc->dev = dev;
- if (flags & I2C_MUX_LOCKED)
- muxc->mux_locked = true;
- if (flags & I2C_MUX_ARBITRATOR)
- muxc->arbitrator = true;
- if (flags & I2C_MUX_GATE)
- muxc->gate = true;
+ muxc->mux_locked = !!(flags & I2C_MUX_LOCKED);
+ muxc->arbitrator = !!(flags & I2C_MUX_ARBITRATOR);
+ muxc->gate = !!(flags & I2C_MUX_GATE);
muxc->select = select;
muxc->deselect = deselect;
muxc->max_adapters = max_adapters;
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-25 3:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-24 18:14 [PATCH] i2c: i2c-mux: Simplify boolean assignment in i2c_mux_alloc I Viswanath
2025-08-25 1:30 ` Akhilesh Patil
2025-08-25 3:14 ` [PATCH v2] " I Viswanath
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).