Coverity: Try to avoid tainted values

CID#469253
parent 4a395640
......@@ -1635,18 +1635,21 @@ fellow_disk_seg_init(struct fellow_disk_seg *fds, uint8_t fht)
fds->fht = fht;
}
static void
fellow_disk_seglist_init(struct fellow_disk_seglist *fdsl,
uint16_t ldsegs, uint8_t fht)
static struct fellow_disk_seglist *
fellow_disk_seglist_init(void *ptr, uint16_t ldsegs, uint8_t fht)
{
struct fellow_disk_seglist *fdsl = ptr;
unsigned u;
AN(ptr);
assert(PAOK(ptr));
INIT_OBJ(fdsl, FELLOW_DISK_SEGLIST_MAGIC);
fdsl->version = 1;
fdsl->lsegs = ldsegs;
fdsl->fht = fht;
for (u = 0; u < ldsegs; u++)
fellow_disk_seg_init(&fdsl->segs[u], fht);
return (fdsl);
}
static inline void
......@@ -1704,14 +1707,15 @@ fellow_cache_seglist_associate(
}
}
static void
fellow_cache_seglist_init(struct fellow_cache_seglist *fcsl,
size_t space, struct fellow_cache_obj *fco)
static struct fellow_cache_seglist *
fellow_cache_seglist_init(void *ptr, size_t space, struct fellow_cache_obj *fco)
{
uint16_t u;
struct fellow_cache_seglist *fcsl = ptr;
size_t lsegs;
uint16_t u;
AN(fcsl);
AN(ptr);
assert(PAOK(ptr));
assert(space > sizeof *fcsl);
INIT_OBJ(fcsl, FELLOW_CACHE_SEGLIST_MAGIC);
lsegs = space / sizeof *fcsl->segs;
......@@ -1719,6 +1723,7 @@ fellow_cache_seglist_init(struct fellow_cache_seglist *fcsl,
fcsl->lsegs = (uint16_t)lsegs;
for (u = 0; u < fcsl->lsegs; u++)
fellow_cache_seg_init(&fcsl->segs[u], fco, FCS_INIT);
return (fcsl);
}
static void
......@@ -1869,13 +1874,12 @@ fellow_cache_seglists_load(const struct fellow_cache *fc,
fcsl_mem = buddy_alloc1_ptr_extent_wait(fc->membuddy, FEP_META,
sz, 0);
fcsl = fcsl_mem.ptr;
if (FC_INJ || fcsl == NULL) {
if (FC_INJ || fcsl_mem.ptr == NULL) {
err = FC_ERRSTR("disk seglist fcsl alloc failed");
goto err;
}
fellow_cache_seglist_init(fcsl,
fcsl = fellow_cache_seglist_init(fcsl_mem.ptr,
fcsl_mem.size - sizeof *fcsl, fco);
fcsl->fdsl_sz = fdsl_mem.size;
fcsl->fcsl_sz = fcsl_mem.size;
......@@ -1980,7 +1984,7 @@ fellow_cache_obj_new(struct fellow_cache *fc,
ssz = ((size_t)1 << fco_mem.bits) - sizeof *fco;
fellow_cache_seglist_init(&fco->seglist, ssz, fco);
(void) fellow_cache_seglist_init(&fco->seglist, ssz, fco);
#define FDO_AUXATTR(U, l) \
fellow_cache_seg_init(&fco->aa_##l##_seg, fco, FCS_INIT);
......@@ -2111,10 +2115,9 @@ fellow_busy_obj_alloc(struct fellow_cache *fc,
fcs->refcnt = 2;
fellow_cache_seg_transition_locked_notincore(fcs, FCO_BUSY);
fdsl = (void *)((uint8_t *)fdo + sizeof *fdo + wsl);
assert(PAOK(fdsl));
fellow_disk_seglist_init(fdsl, ldsegs, fc->tune->hash_obj);
fdsl = fellow_disk_seglist_init(
(void *)((uint8_t *)fdo + sizeof *fdo + wsl),
ldsegs, fc->tune->hash_obj);
fellow_cache_seglist_associate(&fco->seglist, fdsl, FCS_USABLE);
// DBG("fdsl lsegs %u fcsl lsegs %u", fdsl->lsegs, fco->seglist.lsegs);
......@@ -2306,14 +2309,12 @@ fellow_disk_seglist_alloc(struct fellow_busy *fbo,
buddy_alloc_wait_done(reqs);
fdsl = fdsl_mem.ptr;
AN(fdsl);
assert(fdsl_mem.size == fdr->size);
fellow_disk_seglist_init(fdsl, ldsegs, fht);
fdsl = fellow_disk_seglist_init(fdsl_mem.ptr, ldsegs, fht);
fcsl = fcsl_mem.ptr;
AN(fcsl);
fellow_cache_seglist_init(fcsl, fcsl_mem.size - sizeof *fcsl, fbo->fco);
AN(fcsl_mem.ptr);
fcsl = fellow_cache_seglist_init(fcsl_mem.ptr,
fcsl_mem.size - sizeof *fcsl, fbo->fco);
fellow_cache_seglist_associate(fcsl, fdsl, FCS_USABLE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment