Skip to contentSkip to conversation

soc: qcom: use assign_bit() where applicable

PATCH Applied Peng Fan (OSS) 4 participants 4 messages Sep 18 – Sep 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: qcom: use assign_bit() where applicable

From: Peng Fan <[email protected]>

Convert open-coded if/else with set_bit/clear_bit and their non-atomic __set_bit/__clear_bit variants to the assign_bit/__assign_bit API.

Done with Coccinelle semantic patch:

    // set_bit -> clear_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        set_bit(bit, addr);
    -else
    -        clear_bit(bit, addr);
    +assign_bit(bit, addr, cond);

    // clear_bit -> set_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        clear_bit(bit, addr);
    -else
    -        set_bit(bit, addr);
    +assign_bit(bit, addr, !cond);
---
 drivers/soc/qcom/smp2p.c | 10 ++--------
 drivers/soc/qcom/smsm.c  | 16 ++++------------
 2 files changed, 6 insertions(+), 20 deletions(-)
drivers/soc/qcom/smp2p.c +2 -8
index 3104e31f91c9..01b8580c9f27 100644
@@ -411,15 +411,9 @@ static int smp2p_set_irq_type(struct irq_data *irqd, unsigned int type)
 	if (!(type & IRQ_TYPE_EDGE_BOTH))
 		return -EINVAL;
 
-	if (type & IRQ_TYPE_EDGE_RISING)
-		set_bit(irq, entry->irq_rising);
-	else
-		clear_bit(irq, entry->irq_rising);
+	assign_bit(irq, entry->irq_rising, type & IRQ_TYPE_EDGE_RISING);
 
-	if (type & IRQ_TYPE_EDGE_FALLING)
-		set_bit(irq, entry->irq_falling);
-	else
-		clear_bit(irq, entry->irq_falling);
+	assign_bit(irq, entry->irq_falling, type & IRQ_TYPE_EDGE_FALLING);
 
 	return 0;
 }
drivers/soc/qcom/smsm.c +4 -12
index ac3c85a2597a..bb487bf6bf03 100644
@@ -277,10 +277,8 @@ static void smsm_unmask_irq(struct irq_data *irqd)
 	u32 val;
 
 	/* Make sure our last cached state is up-to-date */
-	if (readl(entry->remote_state) & BIT(irq))
-		set_bit(irq, &entry->last_value);
-	else
-		clear_bit(irq, &entry->last_value);
+	assign_bit(irq, &entry->last_value,
+		   readl(entry->remote_state) & BIT(irq));
 
 	set_bit(irq, entry->irq_enabled);
 
@@ -304,15 +302,9 @@ static int smsm_set_irq_type(struct irq_data *irqd, unsigned int type)
 	if (!(type & IRQ_TYPE_EDGE_BOTH))
 		return -EINVAL;
 
-	if (type & IRQ_TYPE_EDGE_RISING)
-		set_bit(irq, entry->irq_rising);
-	else
-		clear_bit(irq, entry->irq_rising);
+	assign_bit(irq, entry->irq_rising, type & IRQ_TYPE_EDGE_RISING);
 
-	if (type & IRQ_TYPE_EDGE_FALLING)
-		set_bit(irq, entry->irq_falling);
-	else
-		clear_bit(irq, entry->irq_falling);
+	assign_bit(irq, entry->irq_falling, type & IRQ_TYPE_EDGE_FALLING);
 
 	return 0;
 }
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peng Fan (OSS)
Quoted 31 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

Convert open-coded if/else with set_bit/clear_bit and their non-atomic __set_bit/__clear_bit variants to the assign_bit/__assign_bit API.

Done with Coccinelle semantic patch:

    // set_bit -> clear_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        set_bit(bit, addr);
    -else
    -        clear_bit(bit, addr);
    +assign_bit(bit, addr, cond);

    // clear_bit -> set_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        clear_bit(bit, addr);
    -else
    -        set_bit(bit, addr);
    +assign_bit(bit, addr, !cond);
Quoted 1 line
maintainer Applied
#3 lore raw
In reply to Peng Fan (OSS)

From: Bjorn Andersson <[email protected]>

Quoted 8 lines · Peng Fan (OSS)

Convert open-coded if/else with set_bit/clear_bit and their non-atomic __set_bit/__clear_bit variants to the assign_bit/__assign_bit API.

Done with Coccinelle semantic patch:

    // set_bit -> clear_bit => assign_bit

[...]

Applied, thanks!

[1/1] soc: qcom: use assign_bit() where applicable

      commit: 0feb7b39ba2bfe0bc4ab9abc84b55aa79e676133

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>