Skip to content

Commit d5285ca

Browse files
grwilsonChristopher Siden
authored andcommitted
3522 zfs module should not allow uninitialized variables
Reviewed by: Sebastien Roy <seb@delphix.com> Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Approved by: Garrett D'Amore <garrett@damore.org>
1 parent 7535ae1 commit d5285ca

File tree

20 files changed

+60
-44
lines changed

20 files changed

+60
-44
lines changed

usr/src/uts/common/fs/zfs/arc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, arc_done_func_t *done,
27842784
const zbookmark_t *zb)
27852785
{
27862786
arc_buf_hdr_t *hdr;
2787-
arc_buf_t *buf;
2787+
arc_buf_t *buf = NULL;
27882788
kmutex_t *hash_lock;
27892789
zio_t *rzio;
27902790
uint64_t guid = spa_load_guid(spa);
@@ -2866,7 +2866,7 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, arc_done_func_t *done,
28662866
uint64_t size = BP_GET_LSIZE(bp);
28672867
arc_callback_t *acb;
28682868
vdev_t *vd = NULL;
2869-
uint64_t addr;
2869+
uint64_t addr = 0;
28702870
boolean_t devw = B_FALSE;
28712871

28722872
if (hdr == NULL) {
@@ -2981,6 +2981,10 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, arc_done_func_t *done,
29812981
cb->l2rcb_zb = *zb;
29822982
cb->l2rcb_flags = zio_flags;
29832983

2984+
ASSERT(addr >= VDEV_LABEL_START_SIZE &&
2985+
addr + size < vd->vdev_psize -
2986+
VDEV_LABEL_END_SIZE);
2987+
29842988
/*
29852989
* l2arc read. The SCL_L2ARC lock will be
29862990
* released by l2arc_read_done().
@@ -3172,8 +3176,8 @@ arc_release(arc_buf_t *buf, void *tag)
31723176
if (l2hdr) {
31733177
mutex_enter(&l2arc_buflist_mtx);
31743178
hdr->b_l2hdr = NULL;
3175-
buf_size = hdr->b_size;
31763179
}
3180+
buf_size = hdr->b_size;
31773181

31783182
/*
31793183
* Do we have more than one buf?
@@ -4172,7 +4176,7 @@ l2arc_read_done(zio_t *zio)
41724176
static list_t *
41734177
l2arc_list_locked(int list_num, kmutex_t **lock)
41744178
{
4175-
list_t *list;
4179+
list_t *list = NULL;
41764180

41774181
ASSERT(list_num >= 0 && list_num <= 3);
41784182

usr/src/uts/common/fs/zfs/dmu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
405405

406406
if (dn->dn_objset->os_dsl_dataset)
407407
dp = dn->dn_objset->os_dsl_dataset->ds_dir->dd_pool;
408-
if (dp && dsl_pool_sync_context(dp))
409-
start = gethrtime();
408+
start = gethrtime();
410409
zio = zio_root(dn->dn_objset->os_spa, NULL, NULL, ZIO_FLAG_CANFAIL);
411410
blkid = dbuf_whichblock(dn, offset);
412411
for (i = 0; i < nblks; i++) {

usr/src/uts/common/fs/zfs/dmu_objset.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,8 @@ dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx)
13721372
objset_t *os = dn->dn_objset;
13731373
void *data = NULL;
13741374
dmu_buf_impl_t *db = NULL;
1375-
uint64_t *user, *group;
1375+
uint64_t *user = NULL;
1376+
uint64_t *group = NULL;
13761377
int flags = dn->dn_id_flags;
13771378
int error;
13781379
boolean_t have_spill = B_FALSE;

usr/src/uts/common/fs/zfs/dsl_dataset.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ dsl_dataset_get_ref(dsl_pool_t *dp, uint64_t dsobj, void *tag,
375375

376376
ds = dmu_buf_get_user(dbuf);
377377
if (ds == NULL) {
378-
dsl_dataset_t *winner;
378+
dsl_dataset_t *winner = NULL;
379379

380380
ds = kmem_zalloc(sizeof (dsl_dataset_t), KM_SLEEP);
381381
ds->ds_dbuf = dbuf;
@@ -460,11 +460,8 @@ dsl_dataset_get_ref(dsl_pool_t *dp, uint64_t dsobj, void *tag,
460460
ds->ds_reserved = ds->ds_quota = 0;
461461
}
462462

463-
if (err == 0) {
464-
winner = dmu_buf_set_user_ie(dbuf, ds, &ds->ds_phys,
465-
dsl_dataset_evict);
466-
}
467-
if (err || winner) {
463+
if (err != 0 || (winner = dmu_buf_set_user_ie(dbuf, ds,
464+
&ds->ds_phys, dsl_dataset_evict)) != NULL) {
468465
bplist_destroy(&ds->ds_pending_deadlist);
469466
dsl_deadlist_close(&ds->ds_deadlist);
470467
if (ds->ds_prev)

usr/src/uts/common/fs/zfs/dsl_scan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,8 @@ dsl_scan_scrub_cb(dsl_pool_t *dp,
16271627
zio_priority = ZIO_PRIORITY_SCRUB;
16281628
needs_io = B_TRUE;
16291629
scan_delay = zfs_scrub_delay;
1630-
} else if (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) {
1630+
} else {
1631+
ASSERT3U(scn->scn_phys.scn_func, ==, POOL_SCAN_RESILVER);
16311632
zio_flags |= ZIO_FLAG_RESILVER;
16321633
zio_priority = ZIO_PRIORITY_RESILVER;
16331634
needs_io = B_FALSE;

usr/src/uts/common/fs/zfs/lzjb.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838

3939
#include <sys/types.h>
40+
#include <sys/param.h>
4041

4142
#define MATCH_BITS 6
4243
#define MATCH_MIN 3
@@ -50,7 +51,8 @@ lzjb_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
5051
{
5152
uchar_t *src = s_start;
5253
uchar_t *dst = d_start;
53-
uchar_t *cpy, *copymap;
54+
uchar_t *cpy;
55+
uchar_t *copymap = NULL;
5456
int copymask = 1 << (NBBY - 1);
5557
int mlen, offset, hash;
5658
uint16_t *hp;
@@ -99,7 +101,8 @@ lzjb_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
99101
uchar_t *src = s_start;
100102
uchar_t *dst = d_start;
101103
uchar_t *d_end = (uchar_t *)d_start + d_len;
102-
uchar_t *cpy, copymap;
104+
uchar_t *cpy;
105+
uchar_t copymap = 0;
103106
int copymask = 1 << (NBBY - 1);
104107

105108
while (dst < d_end) {

usr/src/uts/common/fs/zfs/refcount.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ refcount_count(refcount_t *rc)
110110
int64_t
111111
refcount_add_many(refcount_t *rc, uint64_t number, void *holder)
112112
{
113-
reference_t *ref;
113+
reference_t *ref = NULL;
114114
int64_t count;
115115

116116
if (reference_tracking_enable) {

usr/src/uts/common/fs/zfs/sa.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ sa_build_layouts(sa_handle_t *hdl, sa_bulk_attr_t *attr_desc, int attr_count,
660660
int buf_space;
661661
sa_attr_type_t *attrs, *attrs_start;
662662
int i, lot_count;
663-
int hdrsize, spillhdrsize;
663+
int hdrsize;
664+
int spillhdrsize = 0;
664665
int used;
665666
dmu_object_type_t bonustype;
666667
sa_lot_t *lot;
@@ -834,7 +835,7 @@ sa_attr_table_setup(objset_t *os, sa_attr_reg_t *reg_attrs, int count)
834835
{
835836
sa_os_t *sa = os->os_sa;
836837
uint64_t sa_attr_count = 0;
837-
uint64_t sa_reg_count;
838+
uint64_t sa_reg_count = 0;
838839
int error = 0;
839840
uint64_t attr_value;
840841
sa_attr_table_t *tb;
@@ -1639,7 +1640,8 @@ sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
16391640
sa_bulk_attr_t *attr_desc;
16401641
void *old_data[2];
16411642
int bonus_attr_count = 0;
1642-
int bonus_data_size, spill_data_size;
1643+
int bonus_data_size = 0;
1644+
int spill_data_size = 0;
16431645
int spill_attr_count = 0;
16441646
int error;
16451647
uint16_t length;

usr/src/uts/common/fs/zfs/spa.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ spa_prop_validate(spa_t *spa, nvlist_t *props)
374374
{
375375
nvpair_t *elem;
376376
int error = 0, reset_bootfs = 0;
377-
uint64_t objnum;
377+
uint64_t objnum = 0;
378378
boolean_t has_feature = B_FALSE;
379379

380380
elem = NULL;
@@ -1342,6 +1342,7 @@ spa_load_l2cache(spa_t *spa)
13421342
newvdevs = kmem_alloc(nl2cache * sizeof (void *), KM_SLEEP);
13431343
} else {
13441344
nl2cache = 0;
1345+
newvdevs = NULL;
13451346
}
13461347

13471348
oldvdevs = sav->sav_vdevs;
@@ -4446,7 +4447,7 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
44464447
vdev_t *rvd = spa->spa_root_vdev;
44474448
vdev_t *vd, *pvd, *cvd, *tvd;
44484449
boolean_t unspare = B_FALSE;
4449-
uint64_t unspare_guid;
4450+
uint64_t unspare_guid = 0;
44504451
char *vdpath;
44514452

44524453
ASSERT(spa_writeable(spa));

usr/src/uts/common/fs/zfs/vdev_raidz.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,8 @@ vdev_raidz_matrix_reconstruct(raidz_map_t *rm, int n, int nmissing,
11901190
uint64_t ccount;
11911191
uint8_t *dst[VDEV_RAIDZ_MAXPARITY];
11921192
uint64_t dcount[VDEV_RAIDZ_MAXPARITY];
1193-
uint8_t log, val;
1193+
uint8_t log = 0;
1194+
uint8_t val;
11941195
int ll;
11951196
uint8_t *invlog[VDEV_RAIDZ_MAXPARITY];
11961197
uint8_t *p, *pp;

0 commit comments

Comments
 (0)