Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4415550pxa;
        Mon, 10 Aug 2020 08:34:05 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJxJpM01TKzsXohTz5Rl0AT9jRodmLqZxwRyOMrzOp+P2e4dT9N8XAV05w4iqIH8spB4XnlI
X-Received: by 2002:aa7:c251:: with SMTP id y17mr22183868edo.13.1597073645690;
        Mon, 10 Aug 2020 08:34:05 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1597073645; cv=none;
        d=google.com; s=arc-20160816;
        b=xmn1rqHftgsuMrF5todj4KW5uvDoMdnVHGclSq+45xjjYtZ/Mit11X4023d9J1Dc/C
         oNxAAu35NrnTSQt6MxuykSxA/p7EH9jWnqblabkRIdQsyIFPcGSoQiIpi5MsE/31s6lA
         huv90N2xaC0Avwb71bOAU6itit0xRJaJBaHfL7vGMJKyUT/D5t/vZY+Xf6WTA1l/3dJx
         IRsvOtdXpHaUa5zS6koLMc+WD5Kkz6WPGDGqWqnTGHD6IWMXnuWv+Uev+KrMH0tAvFio
         eei8gXe/2LgBDzU0pZawwAF6007sT0u4izg4+Az3uRnTKwSGyqO9JFcb9vqQ1E8Hhe7J
         CwXw==
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=NKUkqNgvy/+CK+7CJCGI9bhv1ghb3JZoWGlcx/R0FNU=;
        b=hVUIAasaG5xK4rL6DNWrBETHDmLAd2hxVZPWru1jmbs3RcLaJcSwdH+nEweCWqgWpF
         cdmGVQu0jqhVC403dovQ1658unw1ZZQF8SAd7GdFasNRN0OyGSQfJHhSdmlwMTaUPhKB
         xWLquJuSvVXVEXXdEl8zohAoprBnXCkhvEtP54NSLJS4U5tjOmn/8ZPXzp5TAyPlEYon
         +KsPLeGOfSBUO4r98JplbOFm8y0ogA8FHjU4HnKGlo70nMFkwp46N2q/hqaz80zi9jC/
         /RhrUMTaeRbJUoWH4PjYkK267gHxiAkT3q90twABScvKBK8tOJpj0wTsqXvVK97kbMEh
         tqcg==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@kernel.org header.s=default header.b=18afm+A+;
       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: <linux-kernel-owner@vger.kernel.org>
Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18])
        by mx.google.com with ESMTP id os22si10274531ejb.693.2020.08.10.08.33.40;
        Mon, 10 Aug 2020 08:34:05 -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=18afm+A+;
       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 S1727885AbgHJPbL (ORCPT <rfc822;shmalave.kernel@gmail.com>
        + 99 others); Mon, 10 Aug 2020 11:31:11 -0400
Received: from mail.kernel.org ([198.145.29.99]:38416 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1729177AbgHJPbI (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
        Mon, 10 Aug 2020 11:31:08 -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 D9C2520791;
        Mon, 10 Aug 2020 15:31:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
        s=default; t=1597073468;
        bh=ZTr/YgqpNPq1cmvv/g6haa7XXEQeVX52CPB5oRr7ugc=;
        h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
        b=18afm+A+frvgIMSXmuRhYkcA+yBiLsnbS3H9b9rdZfOazArTQXQxWN17knDySvg1D
         +XVXQ0xp5J5qOGev1tzIue45tthdXFcxyrpr9qt9xtnlThjznjLTWlkMsL4CW40xLh
         BA032xGAnFVODU4VQpWbfA99AceTz5eB9QoFo0b8=
From:   Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To:     linux-kernel@vger.kernel.org
Cc:     Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
        stable@vger.kernel.org, Qiushi Wu <wu000273@umn.edu>,
        "Michael S. Tsirkin" <mst@redhat.com>,
        Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.19 25/48] firmware: Fix a reference count leak.
Date:   Mon, 10 Aug 2020 17:21:47 +0200
Message-Id: <20200810151805.452009812@linuxfoundation.org>
X-Mailer: git-send-email 2.28.0
In-Reply-To: <20200810151804.199494191@linuxfoundation.org>
References: <20200810151804.199494191@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: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

From: Qiushi Wu <wu000273@umn.edu>

[ Upstream commit fe3c60684377d5ad9b0569b87ed3e26e12c8173b ]

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object.
Callback function fw_cfg_sysfs_release_entry() in kobject_put()
can handle the pointer "entry" properly.

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Link: https://lore.kernel.org/r/20200613190533.15712-1-wu000273@umn.edu
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/firmware/qemu_fw_cfg.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 039e0f91dba8f..6945c3c966375 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -605,8 +605,10 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
 	/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
 	err = kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype,
 				   fw_cfg_sel_ko, "%d", entry->select);
-	if (err)
-		goto err_register;
+	if (err) {
+		kobject_put(&entry->kobj);
+		return err;
+	}
 
 	/* add raw binary content access */
 	err = sysfs_create_bin_file(&entry->kobj, &fw_cfg_sysfs_attr_raw);
@@ -622,7 +624,6 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
 
 err_add_raw:
 	kobject_del(&entry->kobj);
-err_register:
 	kfree(entry);
 	return err;
 }
-- 
2.25.1