Whamcloud - gitweb
LU-17501 libcfs: fix ncpt check for cpt patterns 59/57659/4
authorFrederick Dilger <fdilger@whamcloud.com>
Mon, 6 Jan 2025 20:54:58 +0000 (13:54 -0700)
committerOleg Drokin <green@whamcloud.com>
Sun, 2 Feb 2025 06:29:34 +0000 (06:29 +0000)
commit5504873b36ca11a8c4f8c7e3a0e9128c68db866d
treed3f948a17ea9d7dcc1ead0696b95c779c210053c
parent5bf6be3f9a7ad475ff3d7d8255ee54f95c7832b2
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 <fdilger@whamcloud.com>
Change-Id: I4befcbdc5d8e63a3783ba09416a61a7c80135635
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57659
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lnet/lnet/lib-cpt.c