Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp590122pxb; Wed, 3 Mar 2021 10:11:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjoUGnGQN5H1ZudR+zo14tNykmYygiC9lVoSf1UDvS+Q5N1dztsTrbqrtAJUGAPXg0MsTM X-Received: by 2002:a17:907:1b12:: with SMTP id mp18mr110461ejc.128.1614795071541; Wed, 03 Mar 2021 10:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614795071; cv=none; d=google.com; s=arc-20160816; b=b9R+cxNLqErqD8h6m4SWLOTA55h5GikkaLVtCcG5lQoXdG6dNB0NKVa8z41W+3zN3T mIEPFW0C7M3ls9wjd5B1Tp9UEWjfUenTcph56ooLUBB4NE55GAP4Bc4hVVAfGdLyZ7hp kk3WwiSP3Gqbe4Ym6VLRwMBXFtYEbts6GwO6PSRJpFvmhzyAqrdiZCuH6atfez0ybZI/ qHJZASGeiEgbxnyoM80YslwZ8X+NU4ezjkQ6f5qr64LBV7ECSd9sBwEPtC838h691Rso NiSgfqKn13IFOJU1FOZWIMbOm7f0tukD6feB2bMTNTQgxofQtHdQtdoFgJYumLuP7whB rJ+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=af4iJAH1IAHql/ooxcdN5x+CVM7aU2YhwfTO+ryK9yY=; b=GXXVn4uYXsEQmx5QGaTdYbmxtDWmJEyKFocfmv8r+QjWUfcg+9VWmliJyizPGyS1by Yt9y8lW9XjlEe5+Rc7U7ULRs0WxmncrKL5C0Ca4urP0UoYnvluFz6XdDBE4EWOWlYFnX 5gRQRBiHMjbTyL9jyzPjWkyLM18I70Y3NuUqeYLFi6KWZ2BqP2XKLQD6WdkvC/Ql7oDo dQx3OohvULbmtrT6dcTXF2dVPBeOjdLEv1nsP6wNl6UEzYmepzNHoomcbL17/0w3bKiG lqHsiaBcj263Y/MmNRbjy5R3rfPw+PTKqdPtkgIjvLeoJ38Ujphzy+KMrFokSvKP2vu7 Hj2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xSF18KW7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d9si15734808edt.564.2021.03.03.10.09.41; Wed, 03 Mar 2021 10:11:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xSF18KW7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348483AbhCBBCy (ORCPT + 99 others); Mon, 1 Mar 2021 20:02:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:58456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240786AbhCASxz (ORCPT ); Mon, 1 Mar 2021 13:53:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DEDB960241; Mon, 1 Mar 2021 17:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619103; bh=MlCNaozikj7dZsiSVfzXOoHx/DXdC6FL94fFywA+2wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xSF18KW71+rJfgD39tDWABqgIogd8cWJ4BNtoaUBn3xVhLXLZaDlJQvHHdhrQylcD qb+r8o+Hx+R6mP2Kl2OdvzwnCgwV9++bAUU9J85KLRK5qP1RI4mcWxaHS6+jfdB/Ot 4wgj4bvxIAv4fWkBkKQrbM1z1RGHM2ldgFeVEqvM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guoqing Jiang , Md Haris Iqbal , Jack Wang , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.10 292/663] RDMA/rtrs-clt: Refactor the failure cases in alloc_clt Date: Mon, 1 Mar 2021 17:09:00 +0100 Message-Id: <20210301161156.280535732@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guoqing Jiang [ Upstream commit eab098246625e91c1cbd6e8f75b09e4c9c28a9fc ] Make all failure cases go to the common path to avoid duplicate code. And some issued existed before. 1. clt need to be freed to avoid memory leak. 2. return ERR_PTR(-ENOMEM) if kobject_create_and_add fails, because rtrs_clt_open checks the return value of by call "IS_ERR(clt)". Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality") Link: https://lore.kernel.org/r/20201217141915.56989-15-jinpu.wang@cloud.ionos.com Signed-off-by: Guoqing Jiang Reviewed-by: Md Haris Iqbal Signed-off-by: Jack Wang Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c index 88397bf4b044b..6115db7ca2030 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -2576,11 +2576,8 @@ static struct rtrs_clt *alloc_clt(const char *sessname, size_t paths_num, clt->dev.class = rtrs_clt_dev_class; clt->dev.release = rtrs_clt_dev_release; err = dev_set_name(&clt->dev, "%s", sessname); - if (err) { - free_percpu(clt->pcpu_path); - kfree(clt); - return ERR_PTR(err); - } + if (err) + goto err; /* * Suppress user space notification until * sysfs files are created @@ -2588,29 +2585,31 @@ static struct rtrs_clt *alloc_clt(const char *sessname, size_t paths_num, dev_set_uevent_suppress(&clt->dev, true); err = device_register(&clt->dev); if (err) { - free_percpu(clt->pcpu_path); put_device(&clt->dev); - return ERR_PTR(err); + goto err; } clt->kobj_paths = kobject_create_and_add("paths", &clt->dev.kobj); if (!clt->kobj_paths) { - free_percpu(clt->pcpu_path); - device_unregister(&clt->dev); - return NULL; + err = -ENOMEM; + goto err_dev; } err = rtrs_clt_create_sysfs_root_files(clt); if (err) { - free_percpu(clt->pcpu_path); kobject_del(clt->kobj_paths); kobject_put(clt->kobj_paths); - device_unregister(&clt->dev); - return ERR_PTR(err); + goto err_dev; } dev_set_uevent_suppress(&clt->dev, false); kobject_uevent(&clt->dev.kobj, KOBJ_ADD); return clt; +err_dev: + device_unregister(&clt->dev); +err: + free_percpu(clt->pcpu_path); + kfree(clt); + return ERR_PTR(err); } static void wait_for_inflight_permits(struct rtrs_clt *clt) -- 2.27.0