From nobody Mon Nov 25 22:37:46 2024 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ACB818B460; Thu, 24 Oct 2024 07:58:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729756717; cv=none; b=PPtupfdZfHpp+D0QSVJF/sqHPzs9rf5/KFDjj2Fd841dBucGExzZVT28h8aU1lkcK9VzFHyR4BKgPfVMsoystwEBb6tDIU9ZomJps4WF5wxpLR8MR7GEC9bvZuxKOSMObro+giwRURNhGN+RirmpnvwRY4oiqdS456WuzjoUmXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729756717; c=relaxed/simple; bh=Lw0Zc5q+pDKjabrqXu5Q21yUyG+4ml0jrzQg1pf4+mU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Jtioq8o2nO6iYj1yQBjxw3y5Whovlqb2LmhXQcnjH39qOQEX3J6VcyWwxAyO/qMriV7MNYMPCZ2XhN1em4lc6aV13bmjwS9YZwiSTEeoUf0v8ieUbj1bJRUi/rcNE5Es1chyX+h1Lw9w9IzRridqyhv5Lv8Saz7RDAGqvMyG5cY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4XYyw93Jhpz1ynM5; Thu, 24 Oct 2024 15:58:33 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id 00CF91400CB; Thu, 24 Oct 2024 15:58:26 +0800 (CST) Received: from lihuafei.huawei.com (10.90.53.74) by kwepemf500004.china.huawei.com (7.202.181.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 24 Oct 2024 15:58:25 +0800 From: Li Huafei To: CC: , , , , , , Subject: [PATCH v2] fgraph: Fix missing unlock in register_ftrace_graph() Date: Thu, 24 Oct 2024 23:59:17 +0800 Message-ID: <20241024155917.1019580-1-lihuafei1@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemf500004.china.huawei.com (7.202.181.242) Content-Type: text/plain; charset="utf-8" Use guard(mutex)() to acquire and automatically release ftrace_lock, fixing the issue of not unlocking when calling cpuhp_setup_state() fails. Fixes smatch warning: kernel/trace/fgraph.c:1317 register_ftrace_graph() warn: inconsistent retur= ns '&ftrace_lock'. Fixes: 2c02f7375e65 ("fgraph: Use CPU hotplug mechanism to initialize idle = shadow stacks") Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202410220121.wxg0olfd-lkp@intel.com/ Suggested-by: Steven Rostedt Signed-off-by: Li Huafei Acked-by: Masami Hiramatsu (Google) --- Changes in v2: - Use guard() to acquire and automatically release ftrace_lock. --- kernel/trace/fgraph.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 41e7a15dcb50..cd1c2946018c 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -1252,7 +1252,7 @@ int register_ftrace_graph(struct fgraph_ops *gops) int ret =3D 0; int i =3D -1; =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 if (!fgraph_initialized) { ret =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "fgraph_idle_init", @@ -1273,10 +1273,8 @@ int register_ftrace_graph(struct fgraph_ops *gops) } =20 i =3D fgraph_lru_alloc_index(); - if (i < 0 || WARN_ON_ONCE(fgraph_array[i] !=3D &fgraph_stub)) { - ret =3D -ENOSPC; - goto out; - } + if (i < 0 || WARN_ON_ONCE(fgraph_array[i] !=3D &fgraph_stub)) + return -ENOSPC; gops->idx =3D i; =20 ftrace_graph_active++; @@ -1313,8 +1311,6 @@ int register_ftrace_graph(struct fgraph_ops *gops) gops->saved_func =3D NULL; fgraph_lru_release_index(i); } -out: - mutex_unlock(&ftrace_lock); return ret; } =20 --=20 2.25.1