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)
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

index e9c06cc..71c2b42 100644 (file)
@@ -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);