]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Cleanup: Address Clang's static analyzer's unused code complaints
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Fri, 14 Oct 2022 20:37:54 +0000 (16:37 -0400)
committerGitHub <noreply@github.com>
Fri, 14 Oct 2022 20:37:54 +0000 (13:37 -0700)
These were categorized as the following:

 * Dead assignment 23
 * Dead increment 4
 * Dead initialization 6
 * Dead nested assignment 18

Most of these are harmless, but since actual issues can hide among them,
we correct them.

That said, there were a few return values that were being ignored that
appeared to merit some correction:

 * `destroy_callback()` in `cmd/zfs/zfs_main.c` ignored the error from
   `destroy_batched()`. We handle it by returning -1 if there is an
   error.

 * `zfs_do_upgrade()` in `cmd/zfs/zfs_main.c` ignored the error from
   `zfs_for_each()`. We handle it by doing a binary OR of the error
   value from the subsequent `zfs_for_each()` call to the existing
   value. This is how errors are mostly handled inside `zfs_for_each()`.
   The error value here is passed to exit from the zfs command, so doing
   a binary or on it is better than what we did previously.

 * `get_zap_prop()` in `module/zfs/zcp_get.c` ignored the error from
   `dsl_prop_get_ds()` when the property is not of type string. We
   return an error when it does. There is a small concern that the
   `zfs_get_temporary_prop()` call would handle things, but in the case
   that it does not, we would be pushing an uninitialized numval onto
   the lua stack. It is expected that `dsl_prop_get_ds()` will succeed
   anytime that `zfs_get_temporary_prop()` does, so that not giving it a
   chance to fix things is not a problem.

 * `draid_merge_impl()` in `tests/zfs-tests/cmd/draid.c` used
   `nvlist_add_nvlist()` twice in ways in which errors are expected to
   be impossible, so we switch to `fnvlist_add_nvlist()`.

A few notable ones did not merit use of the return value, so we
suppressed it with `(void)`:

 * `write_free_diffs()` in `lib/libzfs/libzfs_diff.c` ignored the error
   value from `describe_free()`. A look through the commit history
   revealed that this was intentional.

 * `arc_evict_hdr()` in `module/zfs/arc.c` did not need to use the
   returned handle from `arc_hdr_realloc()` because it is already
   referenced in lists.

 * `spa_vdev_detach()` in `module/zfs/spa.c` has a comment explicitly
   saying not to use the error from `vdev_label_init()` because whatever
   causes the error could be the reason why a detach is being done.

Unfortunately, I am not presently able to analyze the kernel modules
with Clang's static analyzer, so I could have missed some cases of this.
In cases where reports were present in code that is duplicated between
Linux and FreeBSD, I made a conscious effort to fix the FreeBSD version
too.

After this commit is merged, regressions like dee8934 should become
extremely obvious with Clang's static analyzer since a regression would
appear in the results as the only instance of unused code. That assumes
that Coverity does not catch the issue first.

My local branch with fixes from all of my outstanding non-draft pull
requests shows 118 reports from Clang's static anlayzer after this
patch. That is down by 51 from 169.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Cedric Berger <cedric@precidata.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13986

32 files changed:
cmd/raidz_test/raidz_test.c
cmd/zfs/zfs_main.c
lib/libefi/rdwr_efi.c
lib/libzfs/libzfs_dataset.c
lib/libzfs/libzfs_diff.c
lib/libzfs/libzfs_pool.c
lib/libzfs/libzfs_sendrecv.c
lib/libzfs/libzfs_util.c
lib/libzutil/os/linux/zutil_device_path_os.c
module/icp/algs/blake3/blake3.c
module/icp/algs/modes/ccm.c
module/icp/algs/modes/ctr.c
module/icp/algs/modes/gcm.c
module/lua/ldo.c
module/os/freebsd/zfs/zfs_znode.c
module/os/freebsd/zfs/zio_crypt.c
module/os/linux/zfs/zfs_znode.c
module/os/linux/zfs/zio_crypt.c
module/zfs/arc.c
module/zfs/dbuf.c
module/zfs/dsl_bookmark.c
module/zfs/dsl_dataset.c
module/zfs/dsl_pool.c
module/zfs/mmp.c
module/zfs/spa.c
module/zfs/vdev.c
module/zfs/zcp_get.c
tests/zfs-tests/cmd/btree_test.c
tests/zfs-tests/cmd/ctime.c
tests/zfs-tests/cmd/draid.c
tests/zfs-tests/cmd/mkbusy.c
tests/zfs-tests/cmd/user_ns_exec.c

index 1ece55960d33f751ce62bcc1e89df4cdcca82699..34f3f6f1ccc6bebc132a5e4877e6786fca792d8d 100644 (file)
@@ -146,8 +146,6 @@ static void process_options(int argc, char **argv)
        memcpy(o, &rto_opts_defaults, sizeof (*o));
 
        while ((opt = getopt(argc, argv, "TDBSvha:er:o:d:s:t:")) != -1) {
-               value = 0;
-
                switch (opt) {
                case 'a':
                        value = strtoull(optarg, NULL, 0);
index 7bda3f5292b3bb223f8ff91f58c1490c737d386f..ac51df0f9c104d14530f207568685dbf6cca68af 100644 (file)
@@ -1453,8 +1453,13 @@ destroy_callback(zfs_handle_t *zhp, void *data)
        if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) {
                cb->cb_snap_count++;
                fnvlist_add_boolean(cb->cb_batchedsnaps, name);
-               if (cb->cb_snap_count % 10 == 0 && cb->cb_defer_destroy)
+               if (cb->cb_snap_count % 10 == 0 && cb->cb_defer_destroy) {
                        error = destroy_batched(cb);
+                       if (error != 0) {
+                               zfs_close(zhp);
+                               return (-1);
+                       }
+               }
        } else {
                error = destroy_batched(cb);
                if (error != 0 ||
@@ -2576,7 +2581,7 @@ zfs_do_upgrade(int argc, char **argv)
                cb.cb_foundone = B_FALSE;
                cb.cb_newer = B_TRUE;
 
-               ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM,
+               ret |= zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM,
                    NULL, NULL, 0, upgrade_list_callback, &cb);
 
                if (!cb.cb_foundone && !found) {
index f159a022496c9212a837f1138586976534c96f8c..3501c3ea391cf23a900d4a2e9e1f632162131398 100644 (file)
@@ -423,7 +423,6 @@ efi_alloc_and_read(int fd, struct dk_gpt **vtoc)
                void *tmp;
                length = (int) sizeof (struct dk_gpt) +
                    (int) sizeof (struct dk_part) * (vptr->efi_nparts - 1);
-               nparts = vptr->efi_nparts;
                if ((tmp = realloc(vptr, length)) == NULL) {
                        /* cppcheck-suppress doubleFree */
                        free(vptr);
@@ -565,10 +564,9 @@ int
 efi_rescan(int fd)
 {
        int retry = 10;
-       int error;
 
        /* Notify the kernel a devices partition table has been updated */
-       while ((error = ioctl(fd, BLKRRPART)) != 0) {
+       while (ioctl(fd, BLKRRPART) != 0) {
                if ((--retry == 0) || (errno != EBUSY)) {
                        (void) fprintf(stderr, "the kernel failed to rescan "
                            "the partition table: %d\n", errno);
index 133b3b358831cf46512118cdc06d526c5f0f8b1f..f8a61c64261f42c4caac36735d6acf539a4f8397 100644 (file)
@@ -2006,7 +2006,7 @@ zfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received)
        if ((ret = changelist_prefix(cl)) != 0)
                goto error;
 
-       if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc)) != 0) {
+       if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc) != 0) {
                changelist_free(cl);
                return (zfs_standard_error(hdl, errno, errbuf));
        } else {
index 80588a860c184c06a75622442f01da949c3cbb37..84e140ede665424eee984cac7bb7a9d778ec8aa5 100644 (file)
@@ -377,7 +377,7 @@ write_free_diffs(FILE *fp, differ_info_t *di, dmu_diff_record_t *dr)
                        if (zc.zc_obj > dr->ddr_last) {
                                break;
                        }
-                       err = describe_free(fp, di, zc.zc_obj, fobjname,
+                       (void) describe_free(fp, di, zc.zc_obj, fobjname,
                            MAXPATHLEN);
                } else if (errno == ESRCH) {
                        break;
index b9806dc30dacd221979f2443018a5e9a141b3798..c6f31d785b89b6cfece0b02e855e38b5e6e69c76 100644 (file)
@@ -2214,7 +2214,6 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
                            ((policy.zlp_rewind & ZPOOL_TRY_REWIND) != 0), nv);
                }
                nvlist_free(nv);
-               return (0);
        }
 
        return (ret);
index bf93ac9bac187187904ab6125ad9a93a5031d240..3e9f637774248b05f478da5850498cfd885b4d23 100644 (file)
@@ -2117,9 +2117,9 @@ send_prelim_records(zfs_handle_t *zhp, const char *from, int fd,
                        fnvlist_add_boolean(hdrnv, "raw");
                }
 
-               if ((err = gather_nvlist(zhp->zfs_hdl, tofs,
+               if (gather_nvlist(zhp->zfs_hdl, tofs,
                    from, tosnap, recursive, raw, doall, replicate, skipmissing,
-                   verbose, backup, holds, props, &fss, fsavlp)) != 0) {
+                   verbose, backup, holds, props, &fss, fsavlp) != 0) {
                        return (zfs_error(zhp->zfs_hdl, EZFS_BADBACKUP,
                            errbuf));
                }
index 28dd4f426a9620f42097876df54273579f3c67c0..b4679dbb36fdcb5b0f5d46c8ae81201bcf65103f 100644 (file)
@@ -1249,7 +1249,7 @@ zcmd_read_dst_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, nvlist_t **nvlp)
 static void
 zprop_print_headers(zprop_get_cbdata_t *cbp, zfs_type_t type)
 {
-       zprop_list_t *pl = cbp->cb_proplist;
+       zprop_list_t *pl;
        int i;
        char *title;
        size_t len;
index 05dbb39954fab31f7f9382e8da66ee1cc3a97fff..900d5e5bacd20c79924b7bca0ccdec0236d1b859 100644 (file)
@@ -428,7 +428,6 @@ dm_get_underlying_path(const char *dm_name)
        char *tmp = NULL;
        char *path = NULL;
        char *dev_str;
-       int size;
        char *first_path = NULL;
        char *enclosure_path;
 
@@ -450,7 +449,7 @@ dm_get_underlying_path(const char *dm_name)
        else
                dev_str = tmp;
 
-       if ((size = asprintf(&tmp, "/sys/block/%s/slaves/", dev_str)) == -1) {
+       if (asprintf(&tmp, "/sys/block/%s/slaves/", dev_str) == -1) {
                tmp = NULL;
                goto end;
        }
@@ -479,8 +478,7 @@ dm_get_underlying_path(const char *dm_name)
                        if (!enclosure_path)
                                continue;
 
-                       if ((size = asprintf(
-                           &path, "/dev/%s", ep->d_name)) == -1)
+                       if (asprintf(&path, "/dev/%s", ep->d_name) == -1)
                                path = NULL;
                        free(enclosure_path);
                        break;
@@ -499,7 +497,7 @@ end:
                 * enclosure devices.  Throw up out hands and return the first
                 * underlying path.
                 */
-               if ((size = asprintf(&path, "/dev/%s", first_path)) == -1)
+               if (asprintf(&path, "/dev/%s", first_path) == -1)
                        path = NULL;
        }
 
index 5f70185988204535daf2c3d71be583500abeaa0b..604e05847ee6cb983f6397196a742a875250688a 100644 (file)
@@ -189,9 +189,7 @@ static void chunk_state_update(const blake3_ops_t *ops,
                input_len -= BLAKE3_BLOCK_LEN;
        }
 
-       size_t take = chunk_state_fill_buf(ctx, input, input_len);
-       input += take;
-       input_len -= take;
+       chunk_state_fill_buf(ctx, input, input_len);
 }
 
 static output_t chunk_state_output(const blake3_chunk_state_t *ctx)
index ed5498dafaa1a487677f7f72a3f82b5b68421be1..4a8bb9bbc2c8edeb2d789b76e4d13cf9ef23845c 100644 (file)
@@ -67,7 +67,6 @@ ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
                return (CRYPTO_SUCCESS);
        }
 
-       lastp = (uint8_t *)ctx->ccm_cb;
        crypto_init_ptrs(out, &iov_or_mp, &offset);
 
        mac_buf = (uint8_t *)ctx->ccm_mac_buf;
index c116ba3662bada8a34073feaf27f5598cec59995..db6b1c71d5cd231dca79d7a5cff08ed848c34dab 100644 (file)
@@ -60,7 +60,6 @@ ctr_mode_contiguous_blocks(ctr_ctx_t *ctx, char *data, size_t length,
                return (CRYPTO_SUCCESS);
        }
 
-       lastp = (uint8_t *)ctx->ctr_cb;
        crypto_init_ptrs(out, &iov_or_mp, &offset);
 
        do {
index ca328d54a7e62d8181b5f22a5b563365a54618f2..16ef14b8ccaf7335f0cd07ecb66a8d5b12afa329 100644 (file)
@@ -118,7 +118,6 @@ gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
                return (CRYPTO_SUCCESS);
        }
 
-       lastp = (uint8_t *)ctx->gcm_cb;
        crypto_init_ptrs(out, &iov_or_mp, &offset);
 
        gops = gcm_impl_get_ops();
index 24677596de12e6c9477df21042ff6d0933bfb2a7..6bef80514ce2b8f13e979104c4d7a3f0bec3cf4c 100644 (file)
@@ -452,7 +452,7 @@ int luaD_poscall (lua_State *L, StkId firstResult) {
   }
   res = ci->func;  /* res == final position of 1st result */
   wanted = ci->nresults;
-  L->ci = ci = ci->previous;  /* back to caller */
+  L->ci = ci->previous;  /* back to caller */
   /* move results to correct place */
   for (i = wanted; i != 0 && firstResult < L->top; i--)
     setobjs2s(L, res++, firstResult++);
index 6345e9e69d303405a7615fd173f0fe5e4bad93ef..192aa748fc1310094b307206e84f20fbe1e3efce 100644 (file)
@@ -1949,7 +1949,6 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
        } else if (error != ENOENT) {
                return (error);
        }
-       error = 0;
 
        for (;;) {
                uint64_t pobj;
index 0410ddd65a5cac09a69806709bded666e34d6d30..c5e745f7d1960e5698edc73b99bebc60f004646f 100644 (file)
@@ -1735,7 +1735,6 @@ zio_do_crypt_data(boolean_t encrypt, zio_crypt_key_t *key,
                goto error;
        if (locked) {
                rw_exit(&key->zk_salt_lock);
-               locked = B_FALSE;
        }
 
        if (authbuf != NULL)
index 73c21b6c00a8cfd02385546c8d09772ba9998216..a97955f4020a5dc9a1929d90a79dce01f1adadee 100644 (file)
@@ -2136,7 +2136,6 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
        } else if (error != ENOENT) {
                return (error);
        }
-       error = 0;
 
        for (;;) {
                uint64_t pobj = 0;
index 2bc1482e91ec0296e19fbc57213938f28fa4b437..6f2bf7ed75699c1b7760256ab51383f5660f1aba 100644 (file)
@@ -1968,7 +1968,6 @@ zio_do_crypt_data(boolean_t encrypt, zio_crypt_key_t *key,
 
        if (locked) {
                rw_exit(&key->zk_salt_lock);
-               locked = B_FALSE;
        }
 
        if (authbuf != NULL)
index 58fb362073139e219284a5a486c279dd694b917a..54cfb4bd3d04c7bde8efc6636d0ed160649ced1a 100644 (file)
@@ -3939,7 +3939,7 @@ arc_evict_hdr(arc_buf_hdr_t *hdr, kmutex_t *hash_lock, uint64_t *real_evicted)
                         * dropping from L1+L2 cached to L2-only,
                         * realloc to remove the L1 header.
                         */
-                       hdr = arc_hdr_realloc(hdr, hdr_full_cache,
+                       (void) arc_hdr_realloc(hdr, hdr_full_cache,
                            hdr_l2only_cache);
                        *real_evicted += HDR_FULL_SIZE - HDR_L2ONLY_SIZE;
                } else {
index 77e6ad23ef89c5dc0e3ffb0c6a3650fed4a8da1d..7982d9702896d4371b0afeff5a721a4bae7c7ad6 100644 (file)
@@ -1549,7 +1549,6 @@ dbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags,
        uint32_t aflags = ARC_FLAG_NOWAIT;
        int err, zio_flags;
 
-       err = zio_flags = 0;
        DB_DNODE_ENTER(db);
        dn = DB_DNODE(db);
        ASSERT(!zfs_refcount_is_zero(&db->db_holds));
index 8ca7ba8957aa09a7d3f37d24e38a17a037853dad..b95c94beff1f628f8b4ab49b9c39c8e2a2650f86 100644 (file)
@@ -229,7 +229,6 @@ dsl_bookmark_create_check_impl(dsl_pool_t *dp,
        switch (error) {
        case ESRCH:
                /* happy path: new bmark doesn't exist, proceed after switch */
-               error = 0;
                break;
        case 0:
                error = SET_ERROR(EEXIST);
index 7a066b786cd0014cac6be560e2be43459bcd7e6d..c7577fc584af6011136b4a39b27e9a177c9b32f2 100644 (file)
@@ -3421,7 +3421,8 @@ dsl_dataset_promote_check(void *arg, dmu_tx_t *tx)
                        conflicting_snaps = B_TRUE;
                } else if (err == ESRCH) {
                        err = 0;
-               } else if (err != 0) {
+               }
+               if (err != 0) {
                        goto out;
                }
        }
index 5d4311ff4557d0d601417a5176c5e0fd43e60a5b..5ca918a87ee192bdebb8563bcadeb527bac89ea6 100644 (file)
@@ -331,7 +331,6 @@ dsl_pool_open(dsl_pool_t *dp)
                        /*
                         * We might not have created the remap bpobj yet.
                         */
-                       err = 0;
                } else {
                        goto out;
                }
index 4f0273f3ed86331282029743ee3669e1281068d1..ef0e01df390f4cecb4aff2c32fbb2814e25b5617 100644 (file)
@@ -550,11 +550,11 @@ mmp_thread(void *arg)
        uint32_t mmp_fail_intervals = MMP_FAIL_INTVS_OK(
            zfs_multihost_fail_intervals);
        hrtime_t mmp_fail_ns = mmp_fail_intervals * mmp_interval;
-       boolean_t last_spa_suspended = suspended;
-       boolean_t last_spa_multihost = multihost;
-       uint64_t last_mmp_interval = mmp_interval;
-       uint32_t last_mmp_fail_intervals = mmp_fail_intervals;
-       hrtime_t last_mmp_fail_ns = mmp_fail_ns;
+       boolean_t last_spa_suspended;
+       boolean_t last_spa_multihost;
+       uint64_t last_mmp_interval;
+       uint32_t last_mmp_fail_intervals;
+       hrtime_t last_mmp_fail_ns;
        callb_cpr_t cpr;
        int skip_wait = 0;
 
index 26df0290c9ff34e8ee95c3b1db74f925ccfad153..0a9f31a8fc851baa95ab8320104091238293e12f 100644 (file)
@@ -6803,8 +6803,8 @@ spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing,
 
        pvd = oldvd->vdev_parent;
 
-       if ((error = spa_config_parse(spa, &newrootvd, nvroot, NULL, 0,
-           VDEV_ALLOC_ATTACH)) != 0)
+       if (spa_config_parse(spa, &newrootvd, nvroot, NULL, 0,
+           VDEV_ALLOC_ATTACH) != 0)
                return (spa_vdev_exit(spa, NULL, txg, EINVAL));
 
        if (newrootvd->vdev_children != 1)
@@ -7160,7 +7160,7 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
         * it may be that the unwritability of the disk is the reason
         * it's being detached!
         */
-       error = vdev_label_init(vd, 0, VDEV_LABEL_REMOVE);
+       (void) vdev_label_init(vd, 0, VDEV_LABEL_REMOVE);
 
        /*
         * Remove vd from its parent and compact the parent's children.
index 7d22a66c7819ee570855612e48465451085d69d6..8c62112de71bb9f96110d87c3633f2beec0b5f68 100644 (file)
@@ -6078,7 +6078,6 @@ vdev_prop_get(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
                        strval = NULL;
                        zprop_source_t src = ZPROP_SRC_DEFAULT;
                        propname = za.za_name;
-                       prop = vdev_name_to_prop(propname);
 
                        switch (za.za_integer_length) {
                        case 8:
index cd17374eb4223f86cafe32b99c0535fd341b0b0a..f28266b8095fb3e4620c33d67e322f276045665d 100644 (file)
@@ -467,7 +467,8 @@ get_zap_prop(lua_State *state, dsl_dataset_t *ds, zfs_prop_t zfs_prop)
        } else {
                error = dsl_prop_get_ds(ds, prop_name, sizeof (numval),
                    1, &numval, setpoint);
-
+               if (error != 0)
+                       goto out;
 #ifdef _KERNEL
                /* Fill in temporary value for prop, if applicable */
                (void) zfs_get_temporary_prop(ds, zfs_prop, &numval, setpoint);
@@ -489,6 +490,7 @@ get_zap_prop(lua_State *state, dsl_dataset_t *ds, zfs_prop_t zfs_prop)
                                (void) lua_pushnumber(state, numval);
                }
        }
+out:
        kmem_free(strval, ZAP_MAXVALUELEN);
        if (error == 0)
                get_prop_src(state, setpoint, zfs_prop);
index ab8967b22b226a4605c738dd915aebce7d676887..fb9de9c7778763a9a31aadd9becc9b23d4f3dcd7 100644 (file)
@@ -220,7 +220,6 @@ insert_find_remove(zfs_btree_t *bt, char *why)
 static int
 drain_tree(zfs_btree_t *bt, char *why)
 {
-       uint64_t *p;
        avl_tree_t avl;
        int i = 0;
        int_node_t *node;
@@ -232,11 +231,8 @@ drain_tree(zfs_btree_t *bt, char *why)
 
        /* Fill both trees with the same data */
        for (i = 0; i < 64 * 1024; i++) {
-               void *ret;
-
                u_longlong_t randval = random();
-               if ((p = (uint64_t *)zfs_btree_find(bt, &randval, &bt_idx)) !=
-                   NULL) {
+               if (zfs_btree_find(bt, &randval, &bt_idx) != NULL) {
                        continue;
                }
                zfs_btree_add_idx(bt, &randval, &bt_idx);
@@ -248,7 +244,7 @@ drain_tree(zfs_btree_t *bt, char *why)
                }
 
                node->data = randval;
-               if ((ret = avl_find(&avl, node, &avl_idx)) != NULL) {
+               if (avl_find(&avl, node, &avl_idx) != NULL) {
                        (void) snprintf(why, BUFSIZE,
                            "Found in avl: %llu\n", randval);
                        return (1);
@@ -372,9 +368,7 @@ stress_tree(zfs_btree_t *bt, char *why)
 
        if (stress_only) {
                zfs_btree_index_t *idx = NULL;
-               uint64_t *rv;
-
-               while ((rv = zfs_btree_destroy_nodes(bt, &idx)) != NULL)
+               while (zfs_btree_destroy_nodes(bt, &idx) != NULL)
                        ;
                zfs_btree_verify(bt);
        }
@@ -389,15 +383,15 @@ stress_tree(zfs_btree_t *bt, char *why)
 static int
 insert_duplicate(zfs_btree_t *bt)
 {
-       uint64_t *p, i = 23456;
+       uint64_t i = 23456;
        zfs_btree_index_t bt_idx = {0};
 
-       if ((p = (uint64_t *)zfs_btree_find(bt, &i, &bt_idx)) != NULL) {
+       if (zfs_btree_find(bt, &i, &bt_idx) != NULL) {
                fprintf(stderr, "Found value in empty tree.\n");
                return (0);
        }
        zfs_btree_add_idx(bt, &i, &bt_idx);
-       if ((p = (uint64_t *)zfs_btree_find(bt, &i, &bt_idx)) == NULL) {
+       if (zfs_btree_find(bt, &i, &bt_idx) == NULL) {
                fprintf(stderr, "Did not find expected value.\n");
                return (0);
        }
@@ -415,10 +409,10 @@ insert_duplicate(zfs_btree_t *bt)
 static int
 remove_missing(zfs_btree_t *bt)
 {
-       uint64_t *p, i = 23456;
+       uint64_t i = 23456;
        zfs_btree_index_t bt_idx = {0};
 
-       if ((p = (uint64_t *)zfs_btree_find(bt, &i, &bt_idx)) != NULL) {
+       if (zfs_btree_find(bt, &i, &bt_idx) != NULL) {
                fprintf(stderr, "Found value in empty tree.\n");
                return (0);
        }
@@ -499,10 +493,6 @@ main(int argc, char *argv[])
                        break;
                }
        }
-       argc -= optind;
-       argv += optind;
-       optind = 1;
-
 
        if (seed == 0) {
                (void) gettimeofday(&tp, NULL);
@@ -536,7 +526,6 @@ main(int argc, char *argv[])
        btree_test_t *test = &test_table[0];
        while (test->name) {
                int retval;
-               uint64_t *rv;
                char why[BUFSIZE] = {0};
                zfs_btree_index_t *idx = NULL;
 
@@ -554,7 +543,7 @@ main(int argc, char *argv[])
                }
 
                /* Remove all the elements and re-verify the tree */
-               while ((rv = zfs_btree_destroy_nodes(&bt, &idx)) != NULL)
+               while (zfs_btree_destroy_nodes(&bt, &idx) != NULL)
                        ;
                zfs_btree_verify(&bt);
 
index f0f3d526eb3e9f80721dbc894d565d4cc863151e..0f5d81aea6136cece6e0d32d3f681e759397d96d 100644 (file)
@@ -327,7 +327,6 @@ main(void)
        if (access(tfile, F_OK) == 0) {
                (void) unlink(tfile);
        }
-       ret = 0;
        if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
                (void) fprintf(stderr, "open(%s) failed: %d\n", tfile, errno);
                return (1);
index 46d7b4dcc69dab1dd50ba328bffc00c949f3f303..3e5ff59f7399a13633c2f70946136fb767862e3b 100644 (file)
@@ -1285,12 +1285,11 @@ draid_merge_impl(nvlist_t *allcfgs, const char *srcfilename, int *mergedp)
 
                                if (nv_worst_ratio < allcfg_worst_ratio) {
                                        fnvlist_remove(allcfgs, key);
-                                       error = nvlist_add_nvlist(allcfgs,
-                                           key, cfg);
+                                       fnvlist_add_nvlist(allcfgs, key, cfg);
                                        merged++;
                                }
                        } else if (error == ENOENT) {
-                               error = nvlist_add_nvlist(allcfgs, key, cfg);
+                               fnvlist_add_nvlist(allcfgs, key, cfg);
                                merged++;
                        } else {
                                return (error);
index cc4a6cfcb98c834907b6f043eca6446638ccc48b..78860381d880259f511685b511329b4533271135 100644 (file)
@@ -148,14 +148,10 @@ main(int argc, char *argv[])
                }
 
        if (!isdir) {
-               int     fd;
-
-               if ((fd = open(fpath, O_CREAT | O_RDWR, 0600)) < 0)
+               if (open(fpath, O_CREAT | O_RDWR, 0600) < 0)
                        fail("open");
        } else {
-               DIR     *dp;
-
-               if ((dp = opendir(fpath)) == NULL)
+               if (opendir(fpath) == NULL)
                        fail("opendir");
        }
        free(fpath);
index 86593622399e80923f1e321cd260e56e79ae7d38..d781301473a9c3f5220880c73bdf8038af310e5e 100644 (file)
@@ -97,7 +97,6 @@ set_idmap(pid_t pid, const char *file)
 
        mapfd = open(path, O_WRONLY);
        if (mapfd < 0) {
-               result = errno;
                perror("open");
                return (errno);
        }