From 05e815539f3f161585c13a9ab023341bade2c52f Mon Sep 17 00:00:00 2001 From: Wan Jiabing Date: Mon, 7 Mar 2022 17:41:48 +0800 Subject: [PATCH] cxl/core/port: Fix NULL but dereferenced coccicheck error Fix the following coccicheck warning: ./drivers/cxl/core/port.c:913:21-24: ERROR: port is NULL but dereferenced. The put_device() is only relevent in the is_cxl_root() case. Fixes: 2703c16c75ae ("cxl/core/port: Add switch port enumeration") Signed-off-by: Wan Jiabing Link: https://lore.kernel.org/r/20220307094158.404882-1-wanjiabing@vivo.com Signed-off-by: Dan Williams --- drivers/cxl/core/port.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index c1681248f322..2ab1ba4499b3 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -911,7 +911,10 @@ static void cxl_detach_ep(void *data) break; port = find_cxl_port(dport_dev); - if (!port || is_cxl_root(port)) { + if (!port) + continue; + + if (is_cxl_root(port)) { put_device(&port->dev); continue; } -- 2.11.0