Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10422699ybi; Wed, 24 Jul 2019 22:57:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxl/jNoyv6J6Yvfsm21F3/no5c5Bycx5gtyuWCKjHGN44iPwBY0Pob8PJhulEhTNZU1WIkn X-Received: by 2002:a65:6248:: with SMTP id q8mr44972114pgv.311.1564034256034; Wed, 24 Jul 2019 22:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034256; cv=none; d=google.com; s=arc-20160816; b=H6yjEGqxPivKh7jLiEi/YN/pWvigMw1rD/Q9oosLeCfSFhDWnFzzPko9baQyPaLdGR X167joqMg1+lNoxb5Xk+5yy91n3G+VtgiDKcgnZKpRH/zlhLpUg+/E9eTPfKH/1qoW6G ZEdNjrw213aNxu5qq3UuM2an3X9GHYFOP4Rfs4Kyte+Z8SKnwFycND2sKvjs9Yg3Hhht 9L2pHQhX//AS3frraUKPYwilIgzRgDggNaqrRzNEVY8vg36sRwPg8rO12TYpz1eywLza P9tX7hgw4Ko/bnyyb0iD5/82NxoYVv46xPGxpbWTbWWK+cq3YhjheBbHQV5Cb9irHgaF qQ5A== 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=vhIXwePFWeJg7pbjH8IcUTIZmtdPMvRjzPv4Pf9W5aM=; b=sXP2xCyaBsrJ5jpLpPzd+5WWwoqG/ZgfktjjiLWdbHQ4+oa6KRtCSv0R1aAmK82ZVA oRtJpz8oPA8uOPe/ZRAgg0CWo7wNlL3V3/jbaE76r3wWEp6l44PCzzzWGh8FqdoeXLdG XnTl1UozbHXJGZb3XSfGjft2BaQ/7KPKzM31zgfyzol8k+wYGMP0Q2jRsAN7xZNqlmXd Y3sMBkWRS1Badces+SSQckGcoozv0Ff4cbC99ZXbeFFBFf7284f6HdIl87JA5Fe18LVh dD7RLAuW7KXRmZBQn3bxwhqeyP/c/f6ZbaITJzkQ50jK+Nner3G8err2EPegicNd6GRm MEDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eFIuo+42; 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 68si14382962ple.89.2019.07.24.22.57.21; Wed, 24 Jul 2019 22:57:36 -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=eFIuo+42; 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 S2404279AbfGYFkF (ORCPT + 99 others); Thu, 25 Jul 2019 01:40:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:54352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404241AbfGYFj7 (ORCPT ); Thu, 25 Jul 2019 01:39:59 -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 B155E22BEF; Thu, 25 Jul 2019 05:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033199; bh=2SuPtkwPkO4qr1b97i+rzqWm8BJ7svTIjfYhjq5vB+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eFIuo+42wXpqauJqajL3D6jm3weUdM7ZmrZ/2xrlQPqxTksIW4HksC2KTN+vSvDfm 50uuOcVshjxcGAR6MhPPENPDL6z7I8JIPI/jrlfSLikWXLWh6b2cBNUA7f2VuY0mGh GE4V87mGFUCQDsqHmMrjPE61/TlEEYr99elV6qYU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pan Bian , Borislav Petkov , James Morse , Mauro Carvalho Chehab , linux-edac , Sasha Levin Subject: [PATCH 4.19 086/271] EDAC/sysfs: Fix memory leak when creating a csrow object Date: Wed, 24 Jul 2019 21:19:15 +0200 Message-Id: <20190724191702.568005838@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 [ Upstream commit 585fb3d93d32dbe89e718b85009f9c322cc554cd ] In edac_create_csrow_object(), the reference to the object is not released when adding the device to the device hierarchy fails (device_add()). This may result in a memory leak. Signed-off-by: Pan Bian Signed-off-by: Borislav Petkov Reviewed-by: Greg Kroah-Hartman Cc: James Morse Cc: Mauro Carvalho Chehab Cc: linux-edac Link: https://lkml.kernel.org/r/1555554438-103953-1-git-send-email-bianpan2016@163.com Signed-off-by: Sasha Levin --- drivers/edac/edac_mc_sysfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index 20374b8248f0..e50610b5bd06 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -404,6 +404,8 @@ static inline int nr_pages_per_csrow(struct csrow_info *csrow) static int edac_create_csrow_object(struct mem_ctl_info *mci, struct csrow_info *csrow, int index) { + int err; + csrow->dev.type = &csrow_attr_type; csrow->dev.bus = mci->bus; csrow->dev.groups = csrow_dev_groups; @@ -416,7 +418,11 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci, edac_dbg(0, "creating (virtual) csrow node %s\n", dev_name(&csrow->dev)); - return device_add(&csrow->dev); + err = device_add(&csrow->dev); + if (err) + put_device(&csrow->dev); + + return err; } /* Create a CSROW object under specifed edac_mc_device */ -- 2.20.1