From 141dcf381b68e19b3c3285b5ec8a529bd13aa6d7 Mon Sep 17 00:00:00 2001 From: Pranavi Somisetty Date: Sat, 22 May 2021 11:21:23 -0600 Subject: [PATCH] net: macb: Fix wake device without assigned IP address Fix kernel crash when system is suspended with GEM as wake device and there's no IP address assigned to the GEM interface. When system is suspended with GEM as wake device and there's no IP address assigned to it, kernel crashes with a null pointer exception as shown below. This patch adds a null pointer check and returns error when there's no IP address assigned. Error log: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000030 Mem abort info: ESR = 0x96000004 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 user pgtable: 4k pages, 48-bit VAs, pgdp=00000008081d4000 [0000000000000030] pgd=0000000000000000, p4d=0000000000000000 Internal error: Oops: 96000004 [#1] SMP Modules linked in: zocl(O) [last unloaded: zocl] CPU: 1 PID: 769 Comm: sh Tainted: G O 5.10.0-xilinx-v2020.2 #1 Hardware name: ZynqMP ZCU102 Rev1.0 (DT) pstate: 60000085 (nZCv daIf -PAN -UAO -TCO BTYPE=--) pc : macb_suspend+0x1d4/0x344 lr : macb_suspend+0x1b0/0x344 sp : ffff8000119b3b20 x29: ffff8000119b3b20 x28: ffff000800872500 x27: 0000000000000002 x26: ffff00080622db00 x25: 0000000000000000 x24: ffff000800384010 x23: 00000000000008f8 x22: ffff00080622c000 x21: 0000000000000002 x20: ffff00080622cad0 x19: ffff00080622c840 x18: 0000000000000030 x17: 000000000000000b x16: 000000000000000b x15: ffff000800872918 x14: ffffffffffffffff x13: ffff8000113b3de0 x12: 0000000000000540 x11: 00000000000001c0 x10: ffff8000113dfde0 x9 : 00000000fffff800 x8 : ffff8000113b3de0 x7 : 0000000000000000 x6 : 0000000000000000 x5 : 0000000000000130 x4 : ffff800010822290 x3 : ffff800010822290 x2 : 0000000000000000 x1 : 00000000000000b8 x0 : ffff00080622c840 Call trace: macb_suspend+0x1d4/0x344 __device_suspend+0x100/0x41c dpm_suspend+0x108/0x1cc dpm_suspend_start+0x7c/0xa0 suspend_devices_and_enter+0x138/0x55c pm_suspend+0x1e4/0x290 state_store+0x8c/0x110 kobj_attr_store+0x1c/0x30 sysfs_kf_write+0x48/0x60 kernfs_fop_write+0xfc/0x21c vfs_write+0xf0/0x2b0 ksys_write+0x6c/0x100 __arm64_sys_write+0x20/0x30 el0_svc_common.constprop.0+0x94/0x1c0 do_el0_svc+0x44/0xb0 el0_svc+0x14/0x20 el0_sync_handler+0x1a4/0x1b0 el0_sync+0x174/0x180 Code: f9400e63 52801701 f9415c42 f9400842 (b9403042) ---[ end trace 0be3f330841cc22a ]--- Signed-off-by: Pranavi Somisetty Acked-by: Harini Katakam State: pending --- drivers/net/ethernet/cadence/macb_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 040b73681d6579..d5ceef463fb967 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -4714,6 +4714,10 @@ static int __maybe_unused macb_suspend(struct device *dev) return 0; if (device_may_wakeup(&bp->dev->dev)) { + if (!bp->dev->ip_ptr->ifa_list) { + netdev_err(netdev, "IP address not assigned\n"); + return -EOPNOTSUPP; + } spin_lock_irqsave(&bp->lock, flags); ctrl = macb_readl(bp, NCR); ctrl &= ~(MACB_BIT(TE) | MACB_BIT(RE));