From: Andreas Dilger Date: Tue, 17 Jun 2014 22:20:54 +0000 (-0600) Subject: LU-1399 config: check lustre_cfg_new() return X-Git-Tag: 2.6.92~21 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2d15edc7be83555a7fa17a666d99b6af4922ab82 LU-1399 config: check lustre_cfg_new() return Check if lustre_cfg_new() fails its allocation and pass that error on to the caller instead of dereferencing the NULL pointer. Signed-off-by: Andreas Dilger Change-Id: I8a934777ea68a866f5f087a6c0948a6dbc3ebbe5 Reviewed-on: http://review.whamcloud.com/10739 Reviewed-by: Dmitry Eremin Tested-by: Jenkins Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/lod/lproc_lod.c b/lustre/lod/lproc_lod.c index 08c5673..f748010 100644 --- a/lustre/lod/lproc_lod.c +++ b/lustre/lod/lproc_lod.c @@ -514,6 +514,9 @@ lod_qos_maxage_seq_write(struct file *file, const char *buffer, sprintf(str, "%smaxage=%d", PARAM_OSP, val); lustre_cfg_bufs_set_string(&bufs, 1, str); lcfg = lustre_cfg_new(LCFG_PARAM, &bufs); + if (lcfg == NULL) + return -ENOMEM; + lod_getref(&lod->lod_ost_descs); lod_foreach_ost(lod, i) { next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev; diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 4f5ec9e..3d5de6f 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -3869,10 +3869,9 @@ static void mdt_stack_pre_fini(const struct lu_env *env, lustre_cfg_bufs_reset(bufs, mdt_obd_name(m)); lustre_cfg_bufs_set_string(bufs, 1, NULL); lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs); - if (!lcfg) { - CERROR("%s: cannot alloc lcfg\n", mdt_obd_name(m)); - return; - } + if (lcfg == NULL) + RETURN_EXIT; + top->ld_ops->ldo_process_config(env, top, lcfg); lustre_cfg_free(lcfg); EXIT; @@ -3905,10 +3904,9 @@ static void mdt_stack_fini(const struct lu_env *env, strcat(flags, "A"); lustre_cfg_bufs_set_string(bufs, 1, flags); lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs); - if (!lcfg) { - CERROR("Cannot alloc lcfg!\n"); - return; - } + if (lcfg == NULL) + RETURN_EXIT; + LASSERT(top); top->ld_ops->ldo_process_config(env, top, lcfg); lustre_cfg_free(lcfg); @@ -4032,7 +4030,7 @@ static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt, lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt); lcfg = lustre_cfg_new(LCFG_ATTACH, bufs); - if (!lcfg) + if (lcfg == NULL) GOTO(free_bufs, rc = -ENOMEM); rc = class_attach(lcfg); @@ -4054,6 +4052,8 @@ static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt, lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt); lcfg = lustre_cfg_new(LCFG_SETUP, bufs); + if (lcfg == NULL) + GOTO(class_detach, rc = -ENOMEM); rc = class_setup(obd, lcfg); if (rc) @@ -4160,7 +4160,7 @@ static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt, lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt); lcfg = lustre_cfg_new(LCFG_ATTACH, bufs); - if (!lcfg) + if (lcfg == NULL) GOTO(cleanup_mem, rc = -ENOMEM); rc = class_attach(lcfg); @@ -4185,6 +4185,8 @@ static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt, mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name); lcfg = lustre_cfg_new(LCFG_SETUP, bufs); + if (lcfg == NULL) + GOTO(class_detach, rc = -ENOMEM); rc = class_setup(obd, lcfg); if (rc) diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index de63a86..9f2d005 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -1528,12 +1528,11 @@ static int mgc_apply_recover_logs(struct obd_device *mgc, lustre_cfg_bufs_set_string(&bufs, 1, params); - rc = -ENOMEM; - lcfg = lustre_cfg_new(LCFG_PARAM, &bufs); - if (lcfg == NULL) { - CERROR("mgc: cannot allocate memory\n"); - break; - } + lcfg = lustre_cfg_new(LCFG_PARAM, &bufs); + if (lcfg == NULL) { + rc = -ENOMEM; + break; + } CDEBUG(D_INFO, "ir apply logs "LPD64"/"LPD64" for %s -> %s\n", prev_version, max_version, obdname, params); diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 7e196fb..3c006c5 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -115,6 +115,8 @@ static int mgs_set_info(struct tgt_session_info *tsi) lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL); lustre_cfg_bufs_set_string(&mgi->mgi_bufs, 1, msp->mgs_param); lcfg = lustre_cfg_new(LCFG_PARAM, &mgi->mgi_bufs); + if (lcfg == NULL) + RETURN(-ENOMEM); rc = mgs_setparam(tsi->tsi_env, exp2mgs_dev(tsi->tsi_exp), lcfg, mgi->mgi_fsname); diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 08bd8c4..05505c3 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -1016,7 +1016,6 @@ struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg, lustre_cfg_bufs_set_string(bufs, 1, new_param); new_cfg = lustre_cfg_new(cfg->lcfg_command, bufs); - OBD_FREE(new_param, new_len); OBD_FREE_PTR(bufs); if (new_cfg == NULL) @@ -1889,11 +1888,11 @@ int class_manual_cleanup(struct obd_device *obd) CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n", obd->obd_name, flags); - lustre_cfg_bufs_reset(&bufs, obd->obd_name); - lustre_cfg_bufs_set_string(&bufs, 1, flags); - lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); - if (!lcfg) - RETURN(-ENOMEM); + lustre_cfg_bufs_reset(&bufs, obd->obd_name); + lustre_cfg_bufs_set_string(&bufs, 1, flags); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); + if (lcfg == NULL) + RETURN(-ENOMEM); rc = class_process_config(lcfg); if (rc) { diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index e3ffc17..82bcafc 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -231,10 +231,8 @@ static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m, strcat(flags, "A"); lustre_cfg_bufs_set_string(&bufs, 1, flags); lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); - if (!lcfg) { - CERROR("Cannot alloc lcfg!\n"); + if (lcfg == NULL) RETURN_EXIT; - } LASSERT(top); top->ld_ops->ldo_process_config(env, top, lcfg); diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index aa9117f..20ec5f4 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -3209,9 +3209,9 @@ static int pool_cmd(enum lcfg_command_type cmd, if (ostname != NULL) lustre_cfg_bufs_set_string(&bufs, 2, ostname); - lcfg = lustre_cfg_new(cmd, &bufs); + lcfg = lustre_cfg_new(cmd, &bufs); if (lcfg == NULL) - return rc; + return -ENOMEM; memset(&data, 0, sizeof(data)); rc = data.ioc_dev = get_mgs_device(); @@ -3228,6 +3228,7 @@ static int pool_cmd(enum lcfg_command_type cmd, if (rc) { fprintf(stderr, "error: %s: invalid ioctl\n", jt_cmdname(cmdname)); + lustre_cfg_free(lcfg); return rc; } rc = l_ioctl(OBD_DEV_ID, OBD_IOC_POOL, buf);