diff mbox series

[-next] rfkill: replace BUG_ON() with WARN_ON() in core.c

Message ID 20221021135738.524370-1-yangyingliang@huawei.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [-next] rfkill: replace BUG_ON() with WARN_ON() in core.c | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 4 maintainers not CCed: kuba@kernel.org pabeni@redhat.com edumazet@google.com davem@davemloft.net
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 73 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yang Yingliang Oct. 21, 2022, 1:57 p.m. UTC
Replace BUG_ON() with WARN_ON() to handle fault more gracefully.

Suggested-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 net/rfkill/core.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Comments

Leon Romanovsky Oct. 23, 2022, 8:16 a.m. UTC | #1
On Fri, Oct 21, 2022 at 09:57:38PM +0800, Yang Yingliang wrote:
> Replace BUG_ON() with WARN_ON() to handle fault more gracefully.
> 
> Suggested-by: Johannes Berg <johannes@sipsolutions.net>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  net/rfkill/core.c | 25 ++++++++++++++++---------
>  1 file changed, 16 insertions(+), 9 deletions(-)

Please add changelog and version numbers when you set your series.

The same comment as https://lore.kernel.org/all/Y1T3a1y/pWdbt2ow@unreal
or you should delete BUG_ONs completely or simply replace them with WARN_ONs.

There is no need in all these if (...).

Thanks
Yang Yingliang Oct. 24, 2022, 1:58 a.m. UTC | #2
On 2022/10/23 16:16, Leon Romanovsky wrote:
> On Fri, Oct 21, 2022 at 09:57:38PM +0800, Yang Yingliang wrote:
>> Replace BUG_ON() with WARN_ON() to handle fault more gracefully.
>>
>> Suggested-by: Johannes Berg <johannes@sipsolutions.net>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   net/rfkill/core.c | 25 ++++++++++++++++---------
>>   1 file changed, 16 insertions(+), 9 deletions(-)
> Please add changelog and version numbers when you set your series.
>
> The same comment as https://lore.kernel.org/all/Y1T3a1y/pWdbt2ow@unreal
The link is unreachable.
> or you should delete BUG_ONs completely or simply replace them with WARN_ONs.
>
> There is no need in all these if (...).
If remove BUG_ONs or not use if (...), it may lead null-ptr-deref, it's 
same as
using BUG_ON(), which leads system crash.

Thanks,
Yang
>
> Thanks
> .
Leon Romanovsky Oct. 24, 2022, 8:32 a.m. UTC | #3
On Mon, Oct 24, 2022 at 09:58:59AM +0800, Yang Yingliang wrote:
> 
> On 2022/10/23 16:16, Leon Romanovsky wrote:
> > On Fri, Oct 21, 2022 at 09:57:38PM +0800, Yang Yingliang wrote:
> > > Replace BUG_ON() with WARN_ON() to handle fault more gracefully.
> > > 
> > > Suggested-by: Johannes Berg <johannes@sipsolutions.net>
> > > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > > ---
> > >   net/rfkill/core.c | 25 ++++++++++++++++---------
> > >   1 file changed, 16 insertions(+), 9 deletions(-)
> > Please add changelog and version numbers when you set your series.
> > 
> > The same comment as https://lore.kernel.org/all/Y1T3a1y/pWdbt2ow@unreal
> The link is unreachable.

Try this https://lore.kernel.org/netdev/Y1T3a1y%2FpWdbt2ow@unreal/

> > or you should delete BUG_ONs completely or simply replace them with WARN_ONs.
> > 
> > There is no need in all these if (...).
> If remove BUG_ONs or not use if (...), it may lead null-ptr-deref, it's same
> as
> using BUG_ON(), which leads system crash.

May or will? Do you have crash report in hand?

This is rfkill API and an expectation is to have valid struct rfkill *rfkill.
Callers shouldn't call to these API functions if they know what rfkill is NULL.

Thanks

> 
> Thanks,
> Yang
> > 
> > Thanks
> > .
diff mbox series

Patch

diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index dac4fdc7488a..4f493e76520d 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -150,7 +150,8 @@  EXPORT_SYMBOL(rfkill_get_led_trigger_name);
 
 void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
 {
-	BUG_ON(!rfkill);
+	if (WARN_ON(!rfkill))
+		return;
 
 	rfkill->ledtrigname = name;
 }
@@ -532,7 +533,8 @@  bool rfkill_set_hw_state_reason(struct rfkill *rfkill,
 	unsigned long flags;
 	bool ret, prev;
 
-	BUG_ON(!rfkill);
+	if (WARN_ON(!rfkill))
+		return blocked;
 
 	if (WARN(reason &
 	    ~(RFKILL_HARD_BLOCK_SIGNAL | RFKILL_HARD_BLOCK_NOT_OWNER),
@@ -581,7 +583,8 @@  bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
 	unsigned long flags;
 	bool prev, hwblock;
 
-	BUG_ON(!rfkill);
+	if (WARN_ON(!rfkill))
+		return blocked;
 
 	spin_lock_irqsave(&rfkill->lock, flags);
 	prev = !!(rfkill->state & RFKILL_BLOCK_SW);
@@ -607,8 +610,8 @@  void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
 {
 	unsigned long flags;
 
-	BUG_ON(!rfkill);
-	BUG_ON(rfkill->registered);
+	if (WARN_ON(!rfkill) || WARN_ON(rfkill->registered))
+		return;
 
 	spin_lock_irqsave(&rfkill->lock, flags);
 	__rfkill_set_sw_state(rfkill, blocked);
@@ -622,7 +625,8 @@  void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
 	unsigned long flags;
 	bool swprev, hwprev;
 
-	BUG_ON(!rfkill);
+	if (WARN_ON(!rfkill))
+		return;
 
 	spin_lock_irqsave(&rfkill->lock, flags);
 
@@ -860,7 +864,8 @@  static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 void rfkill_pause_polling(struct rfkill *rfkill)
 {
-	BUG_ON(!rfkill);
+	if (WARN_ON(!rfkill))
+		return;
 
 	if (!rfkill->ops->poll)
 		return;
@@ -872,7 +877,8 @@  EXPORT_SYMBOL(rfkill_pause_polling);
 
 void rfkill_resume_polling(struct rfkill *rfkill)
 {
-	BUG_ON(!rfkill);
+	if (WARN_ON(!rfkill))
+		return;
 
 	if (!rfkill->ops->poll)
 		return;
@@ -1115,7 +1121,8 @@  EXPORT_SYMBOL(rfkill_register);
 
 void rfkill_unregister(struct rfkill *rfkill)
 {
-	BUG_ON(!rfkill);
+	if (WARN_ON(!rfkill))
+		return;
 
 	if (rfkill->ops->poll)
 		cancel_delayed_work_sync(&rfkill->poll_work);