Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1517186ybb; Sat, 11 Apr 2020 05:27:33 -0700 (PDT) X-Google-Smtp-Source: APiQypJReKly0OK1ZRzPxxyVJ6oWZs2QAsLvkutuAsLFL53i0MDRPEOsVt0qh5buxrlE5bm2pHy9 X-Received: by 2002:a37:b7c3:: with SMTP id h186mr7527236qkf.428.1586608053002; Sat, 11 Apr 2020 05:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586608052; cv=none; d=google.com; s=arc-20160816; b=Nfljwx8VHoSuTCh62Gi15LSngpqgZQ5476Exv3rut21sDj3HZi5AzL4N94+Wi8+x8C d/y7C8bUM9vmcY+P9aa3b3jwNc+X6deTDPwkFsLeqn0QUhJgyYu5gBCyQkB2K/HRazLh LvxcZTx9mSyVGzGoq8uVbnaGOeThsawFu0YlT72flY71j8n8u+4VhajIwpCCDI5a+ZDZ 9kbO/ezJuWH4GzB46D+6n6aF14JOEbdTwZHG7HKTWm1N7YO4AJBWf2IZ9kuE3yvS4X9u /QXqcbbHgClpq5CfTnewW7TelqPhwvpM9R3KFu8KVFz2P1WkuJ1qGJ5YTiTyVgKMZ7TI ffqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dLzf/lesQlXfHGDhFWgEVvz9IQAMNsG7HF28pLGAG0c=; b=iV0WYWNJvqP6ZOvi/9FxFIeNvA4CKq0kTQb2Xe8hdoPLaQDP3B5oLtu9H3jWXilVYk xtNQ3v/4ZDDVYSe+AFojwOshJUp7gi2HIs4ueqohXlMho+0o3Ib+nBsvoMz8mfnq0jMH vEQvSyGXwRx2jIbVw0F6TMx73Qtg1kvdldX72aLoKFqmYuBZEXSa9P5iTZukCSie2SOo qO9EawTgdCf2Qpq6AyoYLzxoQfKS1iHYMFuEspfaYQpPIKwqm0QFXo07dleU5N7pMNWD cr5/9MPGUxG9/G3D2h3OtzLsVNt2B/vTmkCwkjTcjExlT4JhhSHKRh7dFFgtUGIdLLh6 EAJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PNkTljYi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13si2734477qtv.196.2020.04.11.05.27.18; Sat, 11 Apr 2020 05:27:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PNkTljYi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728226AbgDKMP6 (ORCPT + 99 others); Sat, 11 Apr 2020 08:15:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:50098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727092AbgDKMP4 (ORCPT ); Sat, 11 Apr 2020 08:15:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2276521775; Sat, 11 Apr 2020 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586607356; bh=Qdm/TA6OboJv4benEq37ts+ME43IhFu7UjDCA2hrRlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PNkTljYi5ukYGK/EFbX9yxJpzwI/2p1BdNxjGYXXJoLwmLXs/cyuWba5pRV9cFKHe UOerdT1NKbHtCOZ4wUmXn+veo1NV0bMLDqye5juKMUsDmZdUoMldOBoK4rgg9/KAMX +GwkmmNIEK/VF3rdS+tR+ml7NLbgpDVwAJpHkO04= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Marciniszyn , Kaike Wan , Dennis Dalessandro , Jason Gunthorpe Subject: [PATCH 4.19 40/54] IB/hfi1: Call kobject_put() when kobject_init_and_add() fails Date: Sat, 11 Apr 2020 14:09:22 +0200 Message-Id: <20200411115512.570917687@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200411115508.284500414@linuxfoundation.org> References: <20200411115508.284500414@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kaike Wan commit dfb5394f804ed4fcea1fc925be275a38d66712ab upstream. When kobject_init_and_add() returns an error in the function hfi1_create_port_files(), the function kobject_put() is not called for the corresponding kobject, which potentially leads to memory leak. This patch fixes the issue by calling kobject_put() even if kobject_init_and_add() fails. Cc: Link: https://lore.kernel.org/r/20200326163813.21129.44280.stgit@awfm-01.aw.intel.com Reviewed-by: Mike Marciniszyn Signed-off-by: Kaike Wan Signed-off-by: Dennis Dalessandro Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/hfi1/sysfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/drivers/infiniband/hw/hfi1/sysfs.c +++ b/drivers/infiniband/hw/hfi1/sysfs.c @@ -670,7 +670,11 @@ int hfi1_create_port_files(struct ib_dev dd_dev_err(dd, "Skipping sc2vl sysfs info, (err %d) port %u\n", ret, port_num); - goto bail; + /* + * Based on the documentation for kobject_init_and_add(), the + * caller should call kobject_put even if this call fails. + */ + goto bail_sc2vl; } kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD); @@ -680,7 +684,7 @@ int hfi1_create_port_files(struct ib_dev dd_dev_err(dd, "Skipping sl2sc sysfs info, (err %d) port %u\n", ret, port_num); - goto bail_sc2vl; + goto bail_sl2sc; } kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD); @@ -690,7 +694,7 @@ int hfi1_create_port_files(struct ib_dev dd_dev_err(dd, "Skipping vl2mtu sysfs info, (err %d) port %u\n", ret, port_num); - goto bail_sl2sc; + goto bail_vl2mtu; } kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD); @@ -700,7 +704,7 @@ int hfi1_create_port_files(struct ib_dev dd_dev_err(dd, "Skipping Congestion Control sysfs info, (err %d) port %u\n", ret, port_num); - goto bail_vl2mtu; + goto bail_cc; } kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD); @@ -738,7 +742,6 @@ bail_sl2sc: kobject_put(&ppd->sl2sc_kobj); bail_sc2vl: kobject_put(&ppd->sc2vl_kobj); -bail: return ret; }