Return-Path: Received: from fldsmtpe03.verizon.com ([140.108.26.142]:3598 "EHLO fldsmtpe03.verizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753556AbdJGWi1 (ORCPT ); Sat, 7 Oct 2017 18:38:27 -0400 From: "Levin, Alexander (Sasha Levin)" Cc: Ulka Vaze , Aditya Pandit , James Simmons , "Greg Kroah-Hartman" , "Levin, Alexander (Sasha Levin)" To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH review for 4.9 37/50] staging: lustre: lmv: Error not handled for lmv_find_target Date: Sat, 7 Oct 2017 22:36:55 +0000 Message-ID: <20171007223636.24797-37-alexander.levin@verizon.com> References: <20171007223636.24797-1-alexander.levin@verizon.com> In-Reply-To: <20171007223636.24797-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Ulka Vaze [ Upstream commit 30af99db7ab3483f5ce83ccb890533c9378c2ced ] This issue is found by smatch; has been reported as- Unchecked usage of potential ERR_PTR result in lmv_hsm_req_count and lmv_hsm_req_build. Added ERR_PTR in both functions and also return value check added. Signed-off-by: Ulka Vaze Signed-off-by: Aditya Pandit Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6523 Reviewed-on: http://review.whamcloud.com/14918 Reviewed-by: Dmitry Eremin Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin Signed-off-by: James Simmons Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/lustre/lustre/lmv/lmv_obd.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/= lustre/lustre/lmv/lmv_obd.c index 7dbb2b946acf..cd19ce811e62 100644 --- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c +++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c @@ -744,16 +744,18 @@ static int lmv_hsm_req_count(struct lmv_obd *lmv, /* count how many requests must be sent to the given target */ for (i =3D 0; i < hur->hur_request.hr_itemcount; i++) { curr_tgt =3D lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid); + if (IS_ERR(curr_tgt)) + return PTR_ERR(curr_tgt); if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) nr++; } return nr; } =20 -static void lmv_hsm_req_build(struct lmv_obd *lmv, - struct hsm_user_request *hur_in, - const struct lmv_tgt_desc *tgt_mds, - struct hsm_user_request *hur_out) +static int lmv_hsm_req_build(struct lmv_obd *lmv, + struct hsm_user_request *hur_in, + const struct lmv_tgt_desc *tgt_mds, + struct hsm_user_request *hur_out) { int i, nr_out; struct lmv_tgt_desc *curr_tgt; @@ -764,6 +766,8 @@ static void lmv_hsm_req_build(struct lmv_obd *lmv, for (i =3D 0; i < hur_in->hur_request.hr_itemcount; i++) { curr_tgt =3D lmv_find_target(lmv, &hur_in->hur_user_item[i].hui_fid); + if (IS_ERR(curr_tgt)) + return PTR_ERR(curr_tgt); if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) { hur_out->hur_user_item[nr_out] =3D hur_in->hur_user_item[i]; @@ -773,6 +777,8 @@ static void lmv_hsm_req_build(struct lmv_obd *lmv, hur_out->hur_request.hr_itemcount =3D nr_out; memcpy(hur_data(hur_out), hur_data(hur_in), hur_in->hur_request.hr_data_len); + + return 0; } =20 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, in= t len, @@ -1052,15 +1058,17 @@ static int lmv_iocontrol(unsigned int cmd, struct o= bd_export *exp, } else { /* split fid list to their respective MDS */ for (i =3D 0; i < count; i++) { - unsigned int nr, reqlen; - int rc1; struct hsm_user_request *req; + size_t reqlen; + int nr, rc1; =20 tgt =3D lmv->tgts[i]; if (!tgt || !tgt->ltd_exp) continue; =20 nr =3D lmv_hsm_req_count(lmv, hur, tgt); + if (nr < 0) + return nr; if (nr =3D=3D 0) /* nothing for this MDS */ continue; =20 @@ -1072,10 +1080,13 @@ static int lmv_iocontrol(unsigned int cmd, struct o= bd_export *exp, if (!req) return -ENOMEM; =20 - lmv_hsm_req_build(lmv, hur, tgt, req); + rc1 =3D lmv_hsm_req_build(lmv, hur, tgt, req); + if (rc1 < 0) + goto hsm_req_err; =20 rc1 =3D obd_iocontrol(cmd, tgt->ltd_exp, reqlen, req, uarg); +hsm_req_err: if (rc1 !=3D 0 && rc =3D=3D 0) rc =3D rc1; kvfree(req); --=20 2.11.0