Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rfkill: Fix incorrect check to avoid NULL pointer dereference

In rfkill_register, the struct rfkill pointer is first derefernced
and then checked for NULL. This patch removes the BUG_ON and returns
an error to the caller in case rfkill is NULL.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Link: https://lore.kernel.org/r/20191215153409.21696-1-pakki001@umn.edu
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Aditya Pakki and committed by
Johannes Berg
6fc232db 911bde0f

+5 -2
+5 -2
net/rfkill/core.c
··· 1002 1002 int __must_check rfkill_register(struct rfkill *rfkill) 1003 1003 { 1004 1004 static unsigned long rfkill_no; 1005 - struct device *dev = &rfkill->dev; 1005 + struct device *dev; 1006 1006 int error; 1007 1007 1008 - BUG_ON(!rfkill); 1008 + if (!rfkill) 1009 + return -EINVAL; 1010 + 1011 + dev = &rfkill->dev; 1009 1012 1010 1013 mutex_lock(&rfkill_global_mutex); 1011 1014