From 0607e01af74a81d0fe12ceec79bd22810a5dfe92 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Fri, 29 Mar 2013 14:30:48 +0100 Subject: [PATCH] LU-3068 build: fix 'incorrect expression' errors Fix 'program hangs' defects found by Coverity version 6.5.1: Array compared against 0 (NO_EFFECT) Comparing an array to null is not useful. Copy-paste error (COPY_PASTE_ERROR) This line looks like a copy-paste error. Self assignment (NO_EFFECT) Assignment operation has no effect. Side effect in assertion (ASSERT_SIDE_EFFECT) Assignment has a side effect. This code will work differently in a non-debug build. You might have intended to use a comparison instead. Wrong sizeof argument (SIZEOF_MISMATCH) Passing argument is suspicious. Signed-off-by: Sebastien Buisson Change-Id: Icf6ea9632da6159beca0fd9fd3ff9bb57effc305 Reviewed-on: http://review.whamcloud.com/5887 Tested-by: Hudson Reviewed-by: John Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/fld/fld_index.c | 2 +- lustre/llite/llite_lib.c | 14 +++++++------- lustre/lmv/lmv_obd.c | 8 ++++---- lustre/lod/lod_lov.c | 2 +- lustre/lod/lod_object.c | 2 +- lustre/mdd/mdd_lfsck.c | 2 +- lustre/obdclass/genops.c | 5 ++--- lustre/obdclass/lprocfs_status.c | 1 - lustre/ptlrpc/lproc_ptlrpc.c | 3 --- lustre/ptlrpc/service.c | 2 +- lustre/tests/openunlink.c | 8 ++++---- 11 files changed, 22 insertions(+), 27 deletions(-) diff --git a/lustre/fld/fld_index.c b/lustre/fld/fld_index.c index cbe8300..a6f9be5 100644 --- a/lustre/fld/fld_index.c +++ b/lustre/fld/fld_index.c @@ -331,7 +331,7 @@ int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld, if (attr == NULL) RETURN(-ENOMEM); - memset(attr, 0, sizeof(attr)); + memset(attr, 0, sizeof(*attr)); attr->la_valid = LA_MODE; attr->la_mode = S_IFREG | 0666; dof.dof_type = DFT_INDEX; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index a96f878..43da149 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -2074,15 +2074,15 @@ void ll_umount_begin(struct super_block *sb) obd->obd_force = 1; OBD_ALLOC_PTR(ioc_data); - if (ioc_data) { - obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp, - sizeof ioc_data, ioc_data, NULL); + if (ioc_data) { + obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp, + sizeof *ioc_data, ioc_data, NULL); - obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp, - sizeof ioc_data, ioc_data, NULL); + obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp, + sizeof *ioc_data, ioc_data, NULL); - OBD_FREE_PTR(ioc_data); - } + OBD_FREE_PTR(ioc_data); + } /* Really, we'd like to wait until there are no requests outstanding, diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index d4284e6..e55f4a0 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -2309,10 +2309,10 @@ int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp, meap->mea_count = cpu_to_le32(lsmp->mea_count); meap->mea_master = cpu_to_le32(lsmp->mea_master); - for (i = 0; i < lmv->desc.ld_tgt_count; i++) { - meap->mea_ids[i] = meap->mea_ids[i]; - fid_cpu_to_le(&meap->mea_ids[i], &meap->mea_ids[i]); - } + for (i = 0; i < lmv->desc.ld_tgt_count; i++) { + meap->mea_ids[i] = lsmp->mea_ids[i]; + fid_cpu_to_le(&meap->mea_ids[i], &lsmp->mea_ids[i]); + } RETURN(mea_size); } diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index 37a5809..9a9eec1 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -266,7 +266,7 @@ int lod_add_device(const struct lu_env *env, struct lod_device *lod, } LASSERT(obd->obd_lu_dev); - LASSERT(obd->obd_lu_dev->ld_site = lod->lod_dt_dev.dd_lu_dev.ld_site); + LASSERT(obd->obd_lu_dev->ld_site == lod->lod_dt_dev.dd_lu_dev.ld_site); ldev = obd->obd_lu_dev; d = lu2dt_dev(ldev); diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index dbed5eb..070b2b6 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -433,7 +433,7 @@ static int lod_declare_xattr_set(const struct lu_env *env, if (rc) RETURN(rc); } else { - memset(attr, 0, sizeof(attr)); + memset(attr, 0, sizeof(*attr)); attr->la_valid = LA_TYPE | LA_MODE; attr->la_mode = S_IFREG; } diff --git a/lustre/mdd/mdd_lfsck.c b/lustre/mdd/mdd_lfsck.c index bca6ce1..f012418 100644 --- a/lustre/mdd/mdd_lfsck.c +++ b/lustre/mdd/mdd_lfsck.c @@ -484,7 +484,7 @@ static int mdd_lfsck_bookmark_init(const struct lu_env *env, struct lfsck_bookmark *mb = &lfsck->ml_bookmark_ram; int rc; - memset(mb, 0, sizeof(mb)); + memset(mb, 0, sizeof(*mb)); mb->lb_magic = LFSCK_BOOKMARK_MAGIC; mb->lb_version = LFSCK_VERSION_V2; mutex_lock(&lfsck->ml_mutex); diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index cd1443c..436aa4d 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -315,8 +315,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name) for (i = 0; i < class_devno_max(); i++) { struct obd_device *obd = class_num2obd(i); - if (obd && obd->obd_name && - (strcmp(name, obd->obd_name) == 0)) { + if (obd && (strcmp(name, obd->obd_name) == 0)) { CERROR("Device %s already exists at %d, won't add\n", name, i); if (result) { @@ -397,7 +396,7 @@ int class_name2dev(const char *name) for (i = 0; i < class_devno_max(); i++) { struct obd_device *obd = class_num2obd(i); - if (obd && obd->obd_name && strcmp(name, obd->obd_name) == 0) { + if (obd && strcmp(name, obd->obd_name) == 0) { /* Make sure we finished attaching before we give out any references */ LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC); diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 173ad85..117eb50 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -590,7 +590,6 @@ int lprocfs_rd_name(char *page, char **start, off_t off, int count, struct obd_device *dev = data; LASSERT(dev != NULL); - LASSERT(dev->obd_name != NULL); *eof = 1; return snprintf(page, count, "%s\n", dev->obd_name); } diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index 03ed9b9..c68bcaf 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -370,7 +370,6 @@ ptlrpc_lprocfs_rd_threads_started(char *page, char **start, off_t off, int total = 0; int i; - LASSERT(svc->srv_parts != NULL); ptlrpc_service_for_each_part(svcpt, i, svc) total += svcpt->scp_nthrs_running; @@ -1024,8 +1023,6 @@ static int ptlrpc_lprocfs_rd_timeouts(char *page, char **start, off_t off, int rc = 0; int i; - LASSERT(svc->srv_parts != NULL); - if (AT_OFF) { rc += snprintf(page + rc, count - rc, "adaptive timeouts off, using obd_timeout %u\n", diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index 6278f7b..5b2a77f 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -3195,7 +3195,7 @@ ptlrpc_service_health_check(struct ptlrpc_service *svc) struct ptlrpc_service_part *svcpt; int i; - if (svc == NULL || svc->srv_parts == NULL) + if (svc == NULL) return 0; ptlrpc_service_for_each_part(svcpt, i, svc) { diff --git a/lustre/tests/openunlink.c b/lustre/tests/openunlink.c index 64a3eeb..c471e3b 100644 --- a/lustre/tests/openunlink.c +++ b/lustre/tests/openunlink.c @@ -90,10 +90,10 @@ int main(int argc, char **argv) } fprintf(stderr, "accessing (1)\n"); - if (access(fname, F_OK) == 0) { - fprintf(stderr, "%s still exists\n", fname2); - exit(1); - } + if (access(fname, F_OK) == 0) { + fprintf(stderr, "%s still exists\n", fname); + exit(1); + } fprintf(stderr, "seeking (1)\n"); rc = lseek(fd, 0, SEEK_SET); -- 1.8.3.1