From 5504873b36ca11a8c4f8c7e3a0e9128c68db866d Mon Sep 17 00:00:00 2001 From: Frederick Dilger Date: Mon, 6 Jan 2025 13:54:58 -0700 Subject: [PATCH] LU-17501 libcfs: fix ncpt check for cpt patterns Coverty Scan found the following: *** CID 454272: Control flow issues (DEADCODE) /lnet/lnet/lib-cpt.c: 1114 in cfs_cpt_table_create_pattern() 1108 } else if (!ncpt) { /* scan for bracket at start of partition */ 1109 bracket = str; 1110 while ((bracket = strchr(bracket, '['))) { 1111 bracket++; 1112 ncpt++; 1113 } CID 454272: Control flow issues (DEADCODE) Execution cannot reach the expression "ncpt > num_node_state(N _ONLINE)" inside this statement: "if ((!ncpt && !exclude) || ...". 1114 if ((!ncpt && !exclude) || 1115 (node && ncpt > num_online_nodes()) || 1116 (!node && ncpt > num_online_cpus())) { 1117 CERROR("Invalid pattern '%s', or too many partitions %dn", 1118 pattern_dup, ncpt); 1119 rc = -EINVAL; The issue was that these checks were inside of the "else if (!ncpt)" conditional block when they should have been outside. CoverityID: 454272 ("Control flow issues") Fixes: 111f5836ec ("LU-17501 libcfs: allow CPT exclude list for cores") Signed-off-by: Frederick Dilger Change-Id: I4befcbdc5d8e63a3783ba09416a61a7c80135635 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57659 Reviewed-by: Andreas Dilger Reviewed-by: Serguei Smirnov Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lnet/lnet/lib-cpt.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lnet/lnet/lib-cpt.c b/lnet/lnet/lib-cpt.c index e9c06cc..71c2b42 100644 --- a/lnet/lnet/lib-cpt.c +++ b/lnet/lnet/lib-cpt.c @@ -1111,14 +1111,16 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) bracket++; ncpt++; } - if ((!ncpt && !exclude) || - (node && ncpt > num_online_nodes()) || - (!node && ncpt > num_online_cpus())) { - CERROR("Invalid pattern '%s', or too many partitions %d\n", - pattern_dup, ncpt); - rc = -EINVAL; - goto err_free_str; - } + } + + if ((!ncpt && !exclude) || + (node && ncpt > num_online_nodes()) || + (!node && ncpt > num_online_cpus())) { + CERROR("Invalid pattern '%s', or too many partitions %d\n", + + pattern_dup, ncpt); + rc = -EINVAL; + goto err_free_str; } cptab = cfs_cpt_table_alloc(ncpt); -- 1.8.3.1