From: Sebastien Buisson Date: Tue, 18 Sep 2012 07:13:41 +0000 (+0200) Subject: LU-1961 build: fix 'dereference before null check' errors X-Git-Tag: 2.3.60~50 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=a5b6ed491a5fcbe593f0fb8162b7be11d07ba4de LU-1961 build: fix 'dereference before null check' errors Fix 'dereference before null check' defects found by Coverity version 6.0.3: Dereference before null check (REVERSE_INULL) Null-checking variable suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Signed-off-by: Sebastien Buisson Change-Id: I0c1be27ea443865fcb7640976839d95d0dc07b9a Reviewed-on: http://review.whamcloud.com/4023 Tested-by: Hudson Reviewed-by: Bob Glossman Tested-by: Maloo Reviewed-by: Keith Mannthey Reviewed-by: Oleg Drokin --- diff --git a/lnet/klnds/o2iblnd/o2iblnd.c b/lnet/klnds/o2iblnd/o2iblnd.c index 4aa07d6..9fbd1ab 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.c +++ b/lnet/klnds/o2iblnd/o2iblnd.c @@ -727,7 +727,7 @@ kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid, * its ref on 'cmid'). */ rwlock_t *glock = &kiblnd_data.kib_global_lock; kib_net_t *net = peer->ibp_ni->ni_data; - kib_dev_t *dev = net->ibn_dev; + kib_dev_t *dev; struct ib_qp_init_attr *init_qp_attr; struct kib_sched_info *sched; kib_conn_t *conn; @@ -740,6 +740,8 @@ kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid, LASSERT(net != NULL); LASSERT(!cfs_in_interrupt()); + dev = net->ibn_dev; + cpt = lnet_cpt_of_nid(peer->ibp_nid); sched = kiblnd_data.kib_scheds[cpt]; @@ -1342,7 +1344,7 @@ kiblnd_map_tx_pool(kib_tx_pool_t *tpo) kib_pages_t *txpgs = tpo->tpo_tx_pages; kib_pool_t *pool = &tpo->tpo_pool; kib_net_t *net = pool->po_owner->ps_net; - kib_dev_t *dev = net->ibn_dev; + kib_dev_t *dev; struct page *page; kib_tx_t *tx; int page_offset; @@ -1351,6 +1353,8 @@ kiblnd_map_tx_pool(kib_tx_pool_t *tpo) LASSERT (net != NULL); + dev = net->ibn_dev; + /* pre-mapped messages are not bigger than 1 page */ CLASSERT (IBLND_MSG_SIZE <= PAGE_SIZE); diff --git a/lnet/klnds/o2iblnd/o2iblnd_cb.c b/lnet/klnds/o2iblnd/o2iblnd_cb.c index 355260f..3cc7985 100644 --- a/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -551,7 +551,7 @@ kiblnd_kvaddr_to_page (unsigned long vaddr) static int kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob) { - kib_hca_dev_t *hdev = tx->tx_pool->tpo_hdev; + kib_hca_dev_t *hdev; __u64 *pages = tx->tx_pages; kib_fmr_poolset_t *fps; int npages; @@ -560,6 +560,11 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob) int rc; int i; + LASSERT(tx->tx_pool != NULL); + LASSERT(tx->tx_pool->tpo_pool.po_owner != NULL); + + hdev = tx->tx_pool->tpo_hdev; + for (i = 0, npages = 0; i < rd->rd_nfrags; i++) { for (size = 0; size < rd->rd_frags[i].rf_nob; size += hdev->ibh_page_size) { @@ -568,9 +573,6 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob) } } - LASSERT(tx->tx_pool != NULL); - LASSERT(tx->tx_pool->tpo_pool.po_owner != NULL); - cpt = tx->tx_pool->tpo_pool.po_owner->ps_cpt; fps = net->ibn_fmr_ps[cpt]; @@ -594,17 +596,19 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob) static int kiblnd_pmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob) { - kib_hca_dev_t *hdev = tx->tx_pool->tpo_hdev; + kib_hca_dev_t *hdev; kib_pmr_poolset_t *pps; __u64 iova; int cpt; int rc; - iova = rd->rd_frags[0].rf_addr & ~hdev->ibh_page_mask; - LASSERT(tx->tx_pool != NULL); LASSERT(tx->tx_pool->tpo_pool.po_owner != NULL); + hdev = tx->tx_pool->tpo_hdev; + + iova = rd->rd_frags[0].rf_addr & ~hdev->ibh_page_mask; + cpt = tx->tx_pool->tpo_pool.po_owner->ps_cpt; pps = net->ibn_pmr_ps[cpt]; diff --git a/lnet/selftest/framework.c b/lnet/selftest/framework.c index 5f1568a..8371d94 100644 --- a/lnet/selftest/framework.c +++ b/lnet/selftest/framework.c @@ -573,12 +573,16 @@ sfw_test_buffers(sfw_test_instance_t *tsi) int sfw_load_test(struct sfw_test_instance *tsi) { - struct sfw_test_case *tsc = sfw_find_test_case(tsi->tsi_service); - struct srpc_service *svc = tsc->tsc_srv_service; - int nbuf = sfw_test_buffers(tsi); + struct sfw_test_case *tsc; + struct srpc_service *svc; + int nbuf; int rc; + LASSERT(tsi != NULL); + tsc = sfw_find_test_case(tsi->tsi_service); + nbuf = sfw_test_buffers(tsi); LASSERT(tsc != NULL); + svc = tsc->tsc_srv_service; if (tsi->tsi_is_client) { tsi->tsi_ops = tsc->tsc_cli_ops; diff --git a/lnet/selftest/rpc.c b/lnet/selftest/rpc.c index b85ba9a..60282f9 100644 --- a/lnet/selftest/rpc.c +++ b/lnet/selftest/rpc.c @@ -1213,13 +1213,20 @@ int srpc_send_rpc (swi_workitem_t *wi) { int rc = 0; - srpc_client_rpc_t *rpc = wi->swi_workitem.wi_data; - srpc_msg_t *reply = &rpc->crpc_replymsg; - int do_bulk = rpc->crpc_bulk.bk_niov > 0; + srpc_client_rpc_t *rpc; + srpc_msg_t *reply; + int do_bulk; + + LASSERT(wi != NULL); + + rpc = wi->swi_workitem.wi_data; LASSERT (rpc != NULL); LASSERT (wi == &rpc->crpc_wi); + reply = &rpc->crpc_replymsg; + do_bulk = rpc->crpc_bulk.bk_niov > 0; + spin_lock(&rpc->crpc_lock); if (rpc->crpc_aborted) { diff --git a/lustre/fld/fld_request.c b/lustre/fld/fld_request.c index 1d1661c..1aec284 100644 --- a/lustre/fld/fld_request.c +++ b/lustre/fld/fld_request.c @@ -200,11 +200,12 @@ fld_client_get_target(struct lu_client_fld *fld, seqno_t seq) int fld_client_add_target(struct lu_client_fld *fld, struct lu_fld_target *tar) { - const char *name = fld_target_name(tar); + const char *name; struct lu_fld_target *target, *tmp; ENTRY; LASSERT(tar != NULL); + name = fld_target_name(tar); LASSERT(name != NULL); LASSERT(tar->ft_srv != NULL || tar->ft_exp != NULL); diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index e34a426..e0330dc 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -1669,10 +1669,11 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async); static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req) { - struct ptlrpc_bulk_desc *desc = req->rq_bulk; + struct ptlrpc_bulk_desc *desc; int rc; LASSERT(req != NULL); + desc = req->rq_bulk; if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) && req->rq_bulk_deadline > cfs_time_current_sec()) diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c index 1adcaa6..bc78f92 100644 --- a/lustre/ldlm/ldlm_request.c +++ b/lustre/ldlm/ldlm_request.c @@ -840,7 +840,7 @@ int ldlm_cli_enqueue(struct obd_export *exp, struct ptlrpc_request **reqp, void *lvb, __u32 lvb_len, enum lvb_type lvb_type, struct lustre_handle *lockh, int async) { - struct ldlm_namespace *ns = exp->exp_obd->obd_namespace; + struct ldlm_namespace *ns; struct ldlm_lock *lock; struct ldlm_request *body; int is_replay = *flags & LDLM_FL_REPLAY; @@ -851,6 +851,8 @@ int ldlm_cli_enqueue(struct obd_export *exp, struct ptlrpc_request **reqp, LASSERT(exp != NULL); + ns = exp->exp_obd->obd_namespace; + /* If we're replaying this lock, just check some invariants. * If we're creating a new lock, get everything all setup nice. */ if (is_replay) { diff --git a/lustre/llite/vvp_page.c b/lustre/llite/vvp_page.c index ac968ca..6d772e8 100644 --- a/lustre/llite/vvp_page.c +++ b/lustre/llite/vvp_page.c @@ -141,12 +141,14 @@ static void vvp_page_discard(const struct lu_env *env, struct cl_io *unused) { cfs_page_t *vmpage = cl2vm_page(slice); - struct address_space *mapping = vmpage->mapping; + struct address_space *mapping; struct ccc_page *cpg = cl2ccc_page(slice); LASSERT(vmpage != NULL); LASSERT(PageLocked(vmpage)); + mapping = vmpage->mapping; + if (cpg->cpg_defer_uptodate && !cpg->cpg_ra_used) ll_ra_stats_inc(mapping, RA_STAT_DISCARDED); @@ -162,10 +164,13 @@ static int vvp_page_unmap(const struct lu_env *env, struct cl_io *unused) { cfs_page_t *vmpage = cl2vm_page(slice); - __u64 offset = vmpage->index << CFS_PAGE_SHIFT; + __u64 offset; LASSERT(vmpage != NULL); LASSERT(PageLocked(vmpage)); + + offset = vmpage->index << CFS_PAGE_SHIFT; + /* * XXX is it safe to call this with the page lock held? */ diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 104d2b5..b859e37 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -1155,11 +1155,12 @@ static int mdd_recovery_complete(const struct lu_env *env, struct lu_device *d) { struct mdd_device *mdd = lu2mdd_dev(d); - struct lu_device *next = &mdd->mdd_child->dd_lu_dev; + struct lu_device *next; int rc; ENTRY; LASSERT(mdd != NULL); + next = &mdd->mdd_child->dd_lu_dev; /* XXX: orphans handling. */ __mdd_orphan_cleanup(env, mdd); diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 946d428..decdb60 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -878,7 +878,6 @@ static int mdd_changelog_ext_ns_store(const struct lu_env *env, rec->cr.cr_namelen = tname->ln_namelen; memcpy(rec->cr.cr_name, tname->ln_name, tname->ln_namelen); if (sname) { - LASSERT(sfid != NULL); rec->cr.cr_name[tname->ln_namelen] = '\0'; memcpy(rec->cr.cr_name + tname->ln_namelen + 1, sname->ln_name, sname->ln_namelen); diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index cb742d5..0d7d7db 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -951,7 +951,7 @@ static int mdd_changelog_data_store(const struct lu_env *env, int flags, struct mdd_object *mdd_obj, struct thandle *handle) { - const struct lu_fid *tfid = mdo2fid(mdd_obj); + const struct lu_fid *tfid; struct llog_changelog_rec *rec; struct lu_buf *buf; int reclen; @@ -966,6 +966,8 @@ static int mdd_changelog_data_store(const struct lu_env *env, LASSERT(mdd_obj != NULL); LASSERT(handle != NULL); + tfid = mdo2fid(mdd_obj); + if ((type >= CL_MTIME) && (type <= CL_ATIME) && cfs_time_before_64(mdd->mdd_cl.mc_starttime, mdd_obj->mod_cltime)) { /* Don't need multiple updates in this log */ diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 1d02f7a..039d810 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -1586,12 +1586,14 @@ EXPORT_SYMBOL(lprocfs_register_stats); void lprocfs_counter_init(struct lprocfs_stats *stats, int index, unsigned conf, const char *name, const char *units) { - struct lprocfs_counter *c = &(stats->ls_percpu[0]->lp_cntr[index]); + struct lprocfs_counter *c; unsigned long flags = 0; LASSERT(stats != NULL); LASSERT(stats->ls_percpu[0] != NULL); + c = &(stats->ls_percpu[0]->lp_cntr[index]); + lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags); c->lc_config = conf; c->lc_count = 0; diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 6250aa6..b15483f 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -1682,6 +1682,8 @@ static int echo_create_md_object(const struct lu_env *env, ENTRY; + if (ec_parent == NULL) + return -1; parent = lu_object_locate(ec_parent->lo_header, ld->ld_type); if (parent == NULL) RETURN(-ENXIO); @@ -1777,6 +1779,8 @@ static int echo_setattr_object(const struct lu_env *env, ENTRY; + if (ec_parent == NULL) + return -1; parent = lu_object_locate(ec_parent->lo_header, ld->ld_type); if (parent == NULL) RETURN(-ENXIO); @@ -1840,6 +1844,8 @@ static int echo_getattr_object(const struct lu_env *env, ENTRY; + if (ec_parent == NULL) + return -1; parent = lu_object_locate(ec_parent->lo_header, ld->ld_type); if (parent == NULL) RETURN(-ENXIO); @@ -1902,6 +1908,8 @@ static int echo_lookup_object(const struct lu_env *env, int rc = 0; int i; + if (ec_parent == NULL) + return -1; parent = lu_object_locate(ec_parent->lo_header, ld->ld_type); if (parent == NULL) return -ENXIO; diff --git a/lustre/ofd/lproc_ofd.c b/lustre/ofd/lproc_ofd.c index 68b09ce..272aba7 100644 --- a/lustre/ofd/lproc_ofd.c +++ b/lustre/ofd/lproc_ofd.c @@ -60,9 +60,10 @@ static int lprocfs_ofd_rd_tot_dirty(char *page, char **start, off_t off, int count, int *eof, void *data) { struct obd_device *obd = (struct obd_device *)data; - struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev); + struct ofd_device *ofd; LASSERT(obd != NULL); + ofd = ofd_dev(obd->obd_lu_dev); *eof = 1; return snprintf(page, count, LPU64"\n", ofd->ofd_tot_dirty); } @@ -71,9 +72,10 @@ static int lprocfs_ofd_rd_tot_granted(char *page, char **start, off_t off, int count, int *eof, void *data) { struct obd_device *obd = (struct obd_device *)data; - struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev); + struct ofd_device *ofd; LASSERT(obd != NULL); + ofd = ofd_dev(obd->obd_lu_dev); *eof = 1; return snprintf(page, count, LPU64"\n", ofd->ofd_tot_granted); } @@ -82,9 +84,10 @@ static int lprocfs_ofd_rd_tot_pending(char *page, char **start, off_t off, int count, int *eof, void *data) { struct obd_device *obd = (struct obd_device *)data; - struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev); + struct ofd_device *ofd; LASSERT(obd != NULL); + ofd = ofd_dev(obd->obd_lu_dev); *eof = 1; return snprintf(page, count, LPU64"\n", ofd->ofd_tot_pending); } @@ -104,9 +107,10 @@ static int lprocfs_ofd_rd_grant_ratio(char *page, char **start, off_t off, int count, int *eof, void *data) { struct obd_device *obd = (struct obd_device *)data; - struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev); + struct ofd_device *ofd; LASSERT(obd != NULL); + ofd = ofd_dev(obd->obd_lu_dev); *eof = 1; return snprintf(page, count, "%d%%\n", (int) ofd_grant_reserved(ofd, 100)); @@ -176,13 +180,15 @@ static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off, int count, int *eof, void *data) { struct obd_device *obd = data; - struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev); + struct ofd_device *ofd; struct ofd_seq *oseq = NULL; int retval = 0, rc; if (obd == NULL) return 0; + ofd = ofd_dev(obd->obd_lu_dev); + read_lock(&ofd->ofd_seq_list_lock); cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) { rc = snprintf(page, count, LPX64": "LPX64"\n", diff --git a/lustre/ofd/ofd_io.c b/lustre/ofd/ofd_io.c index 83f58a4..7f72a17 100644 --- a/lustre/ofd/ofd_io.c +++ b/lustre/ofd/ofd_io.c @@ -218,6 +218,8 @@ int ofd_preprw(const struct lu_env* env, int cmd, struct obd_export *exp, LASSERT(rc == 0); info = ofd_info_init(env, exp); + LASSERT(oa != NULL); + if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT)) { struct ofd_seq *oseq; oseq = ofd_seq_load(env, ofd, oa->o_seq); @@ -245,7 +247,6 @@ int ofd_preprw(const struct lu_env* env, int cmd, struct obd_export *exp, rc = ofd_auth_capa(exp, &info->fti_fid, oa->o_seq, capa, CAPA_OPC_OSS_WRITE); if (rc == 0) { - LASSERT(oa != NULL); la_from_obdo(&info->fti_attr, oa, OBD_MD_FLGETATTR); rc = ofd_preprw_write(env, exp, ofd, &info->fti_fid, &info->fti_attr, oa, objcount, diff --git a/lustre/ofd/ofd_obd.c b/lustre/ofd/ofd_obd.c index b4dd026..4ae42d0 100644 --- a/lustre/ofd/ofd_obd.c +++ b/lustre/ofd/ofd_obd.c @@ -243,7 +243,7 @@ static int ofd_obd_reconnect(const struct lu_env *env, struct obd_export *exp, struct obd_device *obd, struct obd_uuid *cluuid, struct obd_connect_data *data, void *localdata) { - struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev); + struct ofd_device *ofd; int rc; ENTRY; @@ -251,6 +251,8 @@ static int ofd_obd_reconnect(const struct lu_env *env, struct obd_export *exp, if (exp == NULL || obd == NULL || cluuid == NULL) RETURN(-EINVAL); + ofd = ofd_dev(obd->obd_lu_dev); + rc = lu_env_refill((struct lu_env *)env); if (rc != 0) { CERROR("Failure to refill session: '%d'\n", rc); @@ -485,7 +487,7 @@ static int ofd_set_info_async(const struct lu_env *env, struct obd_export *exp, __u32 keylen, void *key, __u32 vallen, void *val, struct ptlrpc_request_set *set) { - struct ofd_device *ofd = ofd_exp(exp); + struct ofd_device *ofd; int rc = 0; ENTRY; @@ -495,6 +497,8 @@ static int ofd_set_info_async(const struct lu_env *env, struct obd_export *exp, RETURN(-EINVAL); } + ofd = ofd_exp(exp); + if (KEY_IS(KEY_CAPA_KEY)) { rc = ofd_update_capa_key(ofd, val); if (rc) @@ -523,7 +527,7 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp, __u32 keylen, void *key, __u32 *vallen, void *val, struct lov_stripe_md *lsm) { - struct ofd_device *ofd = ofd_exp(exp); + struct ofd_device *ofd; int rc = 0; ENTRY; @@ -533,6 +537,8 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp, RETURN(-EINVAL); } + ofd = ofd_exp(exp); + if (KEY_IS(KEY_BLOCKSIZE)) { __u32 *blocksize = val; if (blocksize) { diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index bb961d3..c0899b2 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -310,7 +310,6 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt) spin_unlock(&svcpt->scp_rep_lock); - LASSERT(rs != NULL); memset(rs, 0, svcpt->scp_service->srv_max_reply_size); rs->rs_svcpt = svcpt; rs->rs_prealloc = 1; diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index 562f009..30af7d4 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -2785,12 +2785,14 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait) { struct l_wait_info lwi = { 0 }; struct ptlrpc_thread *thread; - struct ptlrpc_service *svc = svcpt->scp_service; + struct ptlrpc_service *svc; int rc; ENTRY; LASSERT(svcpt != NULL); + svc = svcpt->scp_service; + CDEBUG(D_RPCTRACE, "%s[%d] started %d min %d max %d\n", svc->srv_name, svcpt->scp_cpt, svcpt->scp_nthrs_running, svc->srv_nthrs_cpt_init, svc->srv_nthrs_cpt_limit);