diff mbox series

[v1] net: rfkill: Correct value returned for invalid parameter

Message ID 1718287476-28227-1-git-send-email-quic_zijuhu@quicinc.com (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series [v1] net: rfkill: Correct value returned for invalid parameter | expand

Commit Message

quic_zijuhu June 13, 2024, 2:04 p.m. UTC
Kernel API rfkill_set_hw_state_reason() does not return current combined
block state when its parameter @reason is invalid, that is wrong according
to its comments, fixed by correcting value returned.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
previous discussion link:
https://lore.kernel.org/all/1717771212-30723-2-git-send-email-quic_zijuhu@quicinc.com/

 net/rfkill/core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index c3feb4f49d09..1f3082526658 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -543,13 +543,14 @@  bool rfkill_set_hw_state_reason(struct rfkill *rfkill,
 {
 	unsigned long flags;
 	bool ret, prev;
+	const unsigned long reason_mask = RFKILL_HARD_BLOCK_SIGNAL |
+		RFKILL_HARD_BLOCK_NOT_OWNER;
 
 	BUG_ON(!rfkill);
 
-	if (WARN(reason &
-	    ~(RFKILL_HARD_BLOCK_SIGNAL | RFKILL_HARD_BLOCK_NOT_OWNER),
-	    "hw_state reason not supported: 0x%lx", reason))
-		return blocked;
+	if (WARN(reason & ~reason_mask,
+		 "hw_state reason not supported: 0x%lx", reason))
+		return rfkill_blocked(rfkill);
 
 	spin_lock_irqsave(&rfkill->lock, flags);
 	prev = !!(rfkill->hard_block_reasons & reason);