Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp667850ybg; Mon, 1 Jun 2020 11:12:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo/igTU5IOTZO8trpcsfih15GpZpdnmeP16UF7BW7mrep8tOMFLUCwB2WiQStyqIzBdNBw X-Received: by 2002:a05:6402:362:: with SMTP id s2mr6320654edw.337.1591035133837; Mon, 01 Jun 2020 11:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591035133; cv=none; d=google.com; s=arc-20160816; b=RKZRsdbF5hxvOIFU/ZGVakYDxHLByXqoGwoOTCrWvlGoT0xdagaxcm1zhs0X93EnJT BQTrCp9+FwfW5Q67lIcYZcD4T776w8aEvY0Oovy1n1gbgxbAAb7/99yobTUStO0XxJ7D wQ9gvRCsGtc98QeN1aupBTrKao8svVAjJg7qdBLiIsFlD5dAHUlIQqu1kylNrGvdTAji CIbNEzMWTYd5sSjdON8tBl2IB7JXzdkc4JR3ZxoD5qZil+fBXuCh2aKjN4X+6LPj9hwH a1kZ2Rswzej7FwnUS/m3Hj30DtrUxYyVG3quvfH0EXOx2Z1j+kslIOXFamd25rEeo3Oc Z+mg== 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=yf2rRc6MG6udFvL+bfMO0tSzcXiJ1eNhpoSuCsx+SHE=; b=w8KMuTGg8Rypn1jKuGULZTbtBED6J2lU6b/XReEePvKcxDCQ2fC0guD9eFf6/0AAGq QHpqkEC2hXXU9Op8l/ERGJqKMcsbjGVa5yA/EzCeQncCR7ljX8tQp5QyS/tagenEEQnm jjbIEQa5NAgB7c8+AMoHsq+Cqmc1YAKeVeTomn2lE+4CWgwYezLtzyL2tbxHBZYh73JJ bmQnA1VlWjz1+K3LlbhAJZg9CxKunCfp2oP7aa0OMhwfCLzm/eJpZfKgLuuVmkSrSiFH yTICdIhYbbR8+KDgpfdCXkO2TmHpKvGsKX0TapHzNa0e7FYFMKN2+Ykc1yxDrXbNCOCv C0wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ycq83Dna; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i4si70941edq.200.2020.06.01.11.11.50; Mon, 01 Jun 2020 11:12:13 -0700 (PDT) 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=@kernel.org header.s=default header.b=Ycq83Dna; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730812AbgFASI7 (ORCPT + 99 others); Mon, 1 Jun 2020 14:08:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:55230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730805AbgFASI6 (ORCPT ); Mon, 1 Jun 2020 14:08:58 -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 E988E206E2; Mon, 1 Jun 2020 18:08:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034937; bh=XO+oMWgl804ly3oZq6jef/75wIN+ikeQHz5cht/6Jlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ycq83DnaB3TOK17LQ3jl6YxCqKZSJN9ricjCIRwAcEGwULm3ZCuGHN1PFHqlRgMrr romzHa7fnzaa7zXedExoQ5d0GQaMgbuJu+CaJ5HXU1BCuhy2rCaSPxQ7NvHGW3Q8T0 046k9qOBnAwa2WrpPtFrI1NqzwgS4y0K7zUsVM3g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lin Yi , Mike Marciniszyn , Kaike Wan , Dennis Dalessandro , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.4 079/142] IB/qib: Call kobject_put() when kobject_init_and_add() fails Date: Mon, 1 Jun 2020 19:53:57 +0200 Message-Id: <20200601174046.194998835@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@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 [ Upstream commit a35cd6447effd5c239b564c80fa109d05ff3d114 ] When kobject_init_and_add() returns an error in the function qib_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. In addition, the ppd->diagc_kobj is released along with other kobjects when the sysfs is unregistered. Fixes: f931551bafe1 ("IB/qib: Add new qib driver for QLogic PCIe InfiniBand adapters") Link: https://lore.kernel.org/r/20200512031328.189865.48627.stgit@awfm-01.aw.intel.com Cc: Suggested-by: Lin Yi Reviewed-by: Mike Marciniszyn Signed-off-by: Kaike Wan Signed-off-by: Dennis Dalessandro Reviewed-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/qib/qib_sysfs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c index 568b21eb6ea1..021df0654ba7 100644 --- a/drivers/infiniband/hw/qib/qib_sysfs.c +++ b/drivers/infiniband/hw/qib/qib_sysfs.c @@ -760,7 +760,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num, qib_dev_err(dd, "Skipping linkcontrol sysfs info, (err %d) port %u\n", ret, port_num); - goto bail; + goto bail_link; } kobject_uevent(&ppd->pport_kobj, KOBJ_ADD); @@ -770,7 +770,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num, qib_dev_err(dd, "Skipping sl2vl sysfs info, (err %d) port %u\n", ret, port_num); - goto bail_link; + goto bail_sl; } kobject_uevent(&ppd->sl2vl_kobj, KOBJ_ADD); @@ -780,7 +780,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num, qib_dev_err(dd, "Skipping diag_counters sysfs info, (err %d) port %u\n", ret, port_num); - goto bail_sl; + goto bail_diagc; } kobject_uevent(&ppd->diagc_kobj, KOBJ_ADD); @@ -793,7 +793,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num, qib_dev_err(dd, "Skipping Congestion Control sysfs info, (err %d) port %u\n", ret, port_num); - goto bail_diagc; + goto bail_cc; } kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD); @@ -854,6 +854,7 @@ void qib_verbs_unregister_sysfs(struct qib_devdata *dd) &cc_table_bin_attr); kobject_put(&ppd->pport_cc_kobj); } + kobject_put(&ppd->diagc_kobj); kobject_put(&ppd->sl2vl_kobj); kobject_put(&ppd->pport_kobj); } -- 2.25.1