Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2635837pxa; Mon, 17 Aug 2020 15:04:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqyu6dnafuxG35e/VT+aVij1VoVO4OuyI1BqA8oRxJ9luLmTeCpMXEgvmkeknqNr5kbtTd X-Received: by 2002:a17:906:a3d0:: with SMTP id ca16mr17085870ejb.36.1597701887533; Mon, 17 Aug 2020 15:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701887; cv=none; d=google.com; s=arc-20160816; b=i/TcWHLRJ4e4j7eltgoI7055NCENINt3xnhvJqAUfhHA/7QmSJLztSooi2kK3LQ/mP B+oA2myh0immygVhugncO3KjwrhDgj9pvnBVOdmim1j93t/0CdiZrem8LGeXlxKJELOG Fg7PWV/YTnrLWHgXfp0xcca4227DXg9gzvhH6CzVqrJwaN3pktwnjc2ZM5fJ7m0luNmW NrQyzUgTL50x7+CSAo70OZhvSzH6hWdXkW3aUtgMxDhhqyZkmYRGXt6n7UUsZ4FbwZb9 B8Mm855bkoM/pOXsLudT4VfQhcWXyFdReCZ56OQOF/xgAp8Y5fX1fUTcQG42oBuOnt3O qxeg== 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=v0QYRDUOrpPzjcG885dHPTREbXUaIug8wzfr0j6wlHY=; b=tO7nocZeErfpUoMm5Z1lvRekt9C0dSxWgGxgnuu//axY3uuyphjal17wHbs4T0PcaQ m+ISCBP5Ey8gTXfWpt6CM5UQkfLL5gB0Bb3SwUihDY4R8Sj645AcJX9UO0S6tvJy+XHH /++bAb3K5WG8SrIf/qW+n5alp8UhXYIOQ7GQxVTAtp7z/OqLbRDt69ujvJR6Pw3z+inn Z35LZyk05Mq8I1brZnwAffeRiTsyrrQqW9hxPhqKnpKPyFKdzHWLzHBtmGmV1eV9EMfW r8D7B0a6G2kjgCT0jHT9Lejl07DXZi8x0notT2uk8/DHxGtr516Dt7ZQJjE/lgoZrD3s Kjag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hj72UaaX; 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=fail (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 lc20si11939489ejb.468.2020.08.17.15.04.24; Mon, 17 Aug 2020 15:04:47 -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=hj72UaaX; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387931AbgHQPxj (ORCPT + 99 others); Mon, 17 Aug 2020 11:53:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:50270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730697AbgHQPlA (ORCPT ); Mon, 17 Aug 2020 11:41:00 -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 B497420825; Mon, 17 Aug 2020 15:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678859; bh=U+gWfkrY3BsVuOe18g1jlpr8DJgrJunvSINNKdy/Hcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hj72UaaXGzZYdePwp5eJwBWJ0s37nSR9ehEJdvMpyZKzEB4tpkCLWm7kn1o+n2zXq LlpXFftbHfA80pXFUjhgy+fStWBDsv7hOMlzR8VYUaprZm+uItnMFAbpPAIWtgSTR8 lVArrVWP4y7cB82osg3tJrElx/i4BQ4JiIMtopYk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qiushi Wu , Borislav Petkov , Sasha Levin Subject: [PATCH 5.7 015/393] EDAC: Fix reference count leaks Date: Mon, 17 Aug 2020 17:11:05 +0200 Message-Id: <20200817143820.327572146@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@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: Qiushi Wu [ Upstream commit 17ed808ad243192fb923e4e653c1338d3ba06207 ] When kobject_init_and_add() returns an error, it should be handled because kobject_init_and_add() takes a 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. Therefore, replace calling kfree() and call kobject_put() and add a missing kobject_put() in the edac_device_register_sysfs_main_kobj() error path. [ bp: Massage and merge into a single patch. ] Fixes: b2ed215a3338 ("Kobject: change drivers/edac to use kobject_init_and_add") Signed-off-by: Qiushi Wu Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20200528202238.18078-1-wu000273@umn.edu Link: https://lkml.kernel.org/r/20200528203526.20908-1-wu000273@umn.edu Signed-off-by: Sasha Levin --- drivers/edac/edac_device_sysfs.c | 1 + drivers/edac/edac_pci_sysfs.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c index 0e7ea3591b781..5e75937537997 100644 --- a/drivers/edac/edac_device_sysfs.c +++ b/drivers/edac/edac_device_sysfs.c @@ -275,6 +275,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) /* Error exit stack */ err_kobj_reg: + kobject_put(&edac_dev->kobj); module_put(edac_dev->owner); err_out: diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c index 72c9eb9fdffbe..53042af7262e2 100644 --- a/drivers/edac/edac_pci_sysfs.c +++ b/drivers/edac/edac_pci_sysfs.c @@ -386,7 +386,7 @@ static int edac_pci_main_kobj_setup(void) /* Error unwind statck */ kobject_init_and_add_fail: - kfree(edac_pci_top_main_kobj); + kobject_put(edac_pci_top_main_kobj); kzalloc_fail: module_put(THIS_MODULE); -- 2.25.1