Skip to content

Commit

Permalink
Fix unchecked return values and unused return values
Browse files Browse the repository at this point in the history
Coverity complained about unchecked return values and unused values that
turned out to be unused return values.

Different approaches were used to handle the different cases of
unchecked return values:

* cmd/zdb/zdb.c: VERIFY0 was used since the existing code had no error
  handling.

* cmd/zed/agents/zfs_retire.c: We silently return since this is a void
  function and other nvlist lookup failures already silently return.

* cmd/zpool_influxdb/zpool_influxdb.c: `(void) fnvlist_lookup_*()` was
  used since there is no error handling for the return from
  `get_vdev_desc()`.

* cmd/ztest.c: VERIFY0 was used since we want failures if something goes
  wrong in ztest.

* module/zfs/dsl_dir.c: We dismiss the return value with `(void)`
  because there is no guarantee that the zap entry will always be there.
  For example, old pools imported readonly would not have it and we do
  not want to fail here because of that.

* module/zfs/zfs_fm.c: `(void) fnvlist_lookup_*()` was used since the
  allocations sleep and thus can never fail.

* module/zfs/zvol.c: We dismiss the return value with `(void)` because
  we do not need it. This matches what is already done in the analogous
  `zfs_replay_write2()`.

As for unused return values, they were all in places where there was
error handling, so logic was added to handle the return values.

Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
  • Loading branch information
ryao committed Sep 19, 2022
1 parent 48cf170 commit 25de744
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 20 deletions.
8 changes: 5 additions & 3 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4418,9 +4418,9 @@ dump_l2arc_log_blocks(int fd, l2arc_dev_hdr_phys_t l2dhdr,
default:
abd = abd_alloc_for_io(asize, B_TRUE);
abd_copy_from_buf_off(abd, &this_lb, 0, asize);
zio_decompress_data(L2BLK_GET_COMPRESS(
VERIFY0(zio_decompress_data(L2BLK_GET_COMPRESS(
(&lbps[0])->lbp_prop), abd, &this_lb,
asize, sizeof (this_lb), NULL);
asize, sizeof (this_lb), NULL));
abd_free(abd);
break;
}
Expand Down Expand Up @@ -7586,7 +7586,7 @@ dump_mos_leaks(spa_t *spa)
} else {
dmu_object_info_t doi;
const char *name;
dmu_object_info(mos, object, &doi);
VERIFY0(dmu_object_info(mos, object, &doi));
if (doi.doi_type & DMU_OT_NEWTYPE) {
dmu_object_byteswap_t bswap =
DMU_OT_BYTESWAP(doi.doi_type);
Expand Down Expand Up @@ -8698,6 +8698,8 @@ main(int argc, char **argv)
usage();
dump_opt['v'] = verbose;
error = dump_path(argv[0], argv[1], &object);
if (error != 0)
fatal("internal error: %s", strerror(error));
}

if (dump_opt['X'] || dump_opt['F'])
Expand Down
5 changes: 4 additions & 1 deletion cmd/zed/agents/zfs_retire.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ zfs_retire_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl,

fmd_hdl_debug(hdl, "zfs_retire_recv: '%s'", class);

nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE, &state);
if (nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE,
&state) != 0) {
return;
}

/*
* If this is a resource notifying us of device removal then simply
Expand Down
6 changes: 3 additions & 3 deletions cmd/zpool_influxdb/zpool_influxdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ get_vdev_desc(nvlist_t *nvroot, const char *parent_name)
char *vdev_type = (char *)"unknown";
uint64_t vdev_id = UINT64_MAX;
char *vdev_path = NULL;
nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE, &vdev_type);
nvlist_lookup_uint64(nvroot, ZPOOL_CONFIG_ID, &vdev_id);
nvlist_lookup_string(nvroot, ZPOOL_CONFIG_PATH, &vdev_path);
vdev_type = fnvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE);
vdev_id = fnvlist_lookup_uint64(nvroot, ZPOOL_CONFIG_ID);
vdev_path = fnvlist_lookup_string(nvroot, ZPOOL_CONFIG_PATH);

if (parent_name == NULL) {
s = escape_string(vdev_type);
Expand Down
2 changes: 1 addition & 1 deletion cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
dmu_write(os, lr->lr_foid, offset, length, data, tx);
} else {
memcpy(abuf->b_data, data, length);
dmu_assign_arcbuf_by_dbuf(db, offset, abuf, tx);
VERIFY0(dmu_assign_arcbuf_by_dbuf(db, offset, abuf, tx));
}

(void) ztest_log_write(zd, tx, lr);
Expand Down
5 changes: 3 additions & 2 deletions lib/libzfsbootenv/lzbe_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ lzbe_set_boot_device(const char *pool, lzbe_flags_t flag, const char *device)
/* version is mandatory */
fnvlist_add_uint64(nv, BOOTENV_VERSION, VB_NVLIST);

rv = 0;
/*
* If device name is empty, remove boot device configuration.
*/
Expand All @@ -95,8 +96,8 @@ lzbe_set_boot_device(const char *pool, lzbe_flags_t flag, const char *device)
rv = ENOMEM;
}
}

rv = zpool_set_bootenv(zphdl, nv);
if (rv == 0)
rv = zpool_set_bootenv(zphdl, nv);
if (rv != 0)
fprintf(stderr, "%s\n", libzfs_error_description(hdl));

Expand Down
2 changes: 2 additions & 0 deletions module/zfs/dmu_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,8 @@ receive_object(struct receive_writer_arg *rwa, struct drr_object *drro,
if (err == 0) {
err = receive_handle_existing_object(rwa, drro, &doi, data,
&object_to_hold, &new_blksz);
if (err != 0)
return (err);
} else if (err == EEXIST) {
/*
* The object requested is currently an interior slot of a
Expand Down
5 changes: 4 additions & 1 deletion module/zfs/dsl_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, const void *tag,
dsl_dataset_phys(ds)->ds_prev_snap_obj,
ds, &ds->ds_prev);
}
if (err != 0)
goto after_dsl_bookmark_fini;
err = dsl_bookmark_init_ds(ds);
} else {
if (zfs_flags & ZFS_DEBUG_SNAPNAMES)
Expand Down Expand Up @@ -688,11 +690,11 @@ dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, const void *tag,
winner = dmu_buf_set_user_ie(dbuf, &ds->ds_dbu);

if (err != 0 || winner != NULL) {
bplist_destroy(&ds->ds_pending_deadlist);
dsl_deadlist_close(&ds->ds_deadlist);
if (dsl_deadlist_is_open(&ds->ds_remap_deadlist))
dsl_deadlist_close(&ds->ds_remap_deadlist);
dsl_bookmark_fini_ds(ds);
after_dsl_bookmark_fini:
if (ds->ds_prev)
dsl_dataset_rele(ds->ds_prev, ds);
dsl_dir_rele(ds->ds_dir, ds);
Expand All @@ -703,6 +705,7 @@ dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, const void *tag,

list_destroy(&ds->ds_prop_cbs);
list_destroy(&ds->ds_sendstreams);
bplist_destroy(&ds->ds_pending_deadlist);
mutex_destroy(&ds->ds_lock);
mutex_destroy(&ds->ds_opening_lock);
mutex_destroy(&ds->ds_sendstream_lock);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,

if (dsl_dir_is_zapified(dd)) {
inode_timespec_t t = {0};
zap_lookup(dp->dp_meta_objset, ddobj,
(void) zap_lookup(dp->dp_meta_objset, ddobj,
DD_FIELD_SNAPSHOTS_CHANGED,
sizeof (uint64_t),
sizeof (inode_timespec_t) / sizeof (uint64_t),
Expand Down
12 changes: 6 additions & 6 deletions module/zfs/zfs_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,17 +1389,17 @@ zfs_post_state_change(spa_t *spa, vdev_t *vd, uint64_t laststate)
aux = fm_nvlist_create(NULL);
if (vd && aux) {
if (vd->vdev_physpath) {
(void) nvlist_add_string(aux,
(void) fnvlist_add_string(aux,
FM_EREPORT_PAYLOAD_ZFS_VDEV_PHYSPATH,
vd->vdev_physpath);
}
if (vd->vdev_enc_sysfs_path) {
(void) nvlist_add_string(aux,
(void) fnvlist_add_string(aux,
FM_EREPORT_PAYLOAD_ZFS_VDEV_ENC_SYSFS_PATH,
vd->vdev_enc_sysfs_path);
}

(void) nvlist_add_uint64(aux,
(void) fnvlist_add_uint64(aux,
FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE, laststate);
}

Expand Down Expand Up @@ -1496,12 +1496,12 @@ zfs_ereport_zvol_post(const char *subclass, const char *name,
return;

aux = fm_nvlist_create(NULL);
nvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_DEVICE_NAME, dev_name);
nvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_RAW_DEVICE_NAME,
(void) fnvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_DEVICE_NAME, dev_name);
(void) fnvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_RAW_DEVICE_NAME,
raw_name);
r = strchr(name, '/');
if (r && r[1])
nvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_VOLUME, &r[1]);
(void) fnvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_VOLUME, &r[1]);

zfs_post_common(spa, NULL, FM_RSRC_CLASS, subclass, aux);
fm_nvlist_destroy(aux, FM_NVA_FREE);
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/zvol.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ zvol_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)
if (error != 0) {
dmu_tx_abort(tx);
} else {
zil_replaying(zv->zv_zilog, tx);
(void) zil_replaying(zv->zv_zilog, tx);
dmu_tx_commit(tx);
error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, offset,
length);
Expand Down Expand Up @@ -475,7 +475,7 @@ zvol_replay_write(void *arg1, void *arg2, boolean_t byteswap)
dmu_tx_abort(tx);
} else {
dmu_write(os, ZVOL_OBJ, offset, length, data, tx);
zil_replaying(zv->zv_zilog, tx);
(void) zil_replaying(zv->zv_zilog, tx);
dmu_tx_commit(tx);
}

Expand Down

0 comments on commit 25de744

Please sign in to comment.