Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9985281ybi; Wed, 24 Jul 2019 13:34:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTdj2BpO26kvyVYe12a96FN/6Mt9bmV3TEr+2JLWQ6oINkXOwkXeInbSL9vNFVR5pEdR8d X-Received: by 2002:a17:90a:a404:: with SMTP id y4mr92416873pjp.58.1564000440356; Wed, 24 Jul 2019 13:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000440; cv=none; d=google.com; s=arc-20160816; b=iRF1mK+HtNWWWdhanpd+wPRM7wI0u7M+uvzhfWz82x33wGdR3GXXuFjdZqDmXfJIvL vZs8gvsMAGDHeNhMl/wtNpi6TecTcRJj6FQ6E8FzctF3iuJ4xPvrLJlK7IpjEhy/IyyH SJ/M/++rLOr6lzBVZtjit/ZBsWEXyddO2sdnW6JFacUZXVFpOHX1LVOBnfi3xbc++w0f G+0sr9DwciBVFfOymT1X7nWJigX7BzExrwWEQk42koOKyh2mGdqjpGtPX9BxRHtTsAvj bNWSjeZUhF+XL/8CRsCBt0etDhmNryQhCb8GN7Q2Wim8i0gM31ZSyKA7hppUo2+H6UBR 9arA== 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=4w3ofcougHwy4oTO6jDFO9nkmjiqjyKVYDgRE6QpjkU=; b=OGD8RYrkfWLYS/+hUuT9dVMLDount6RVd8VHiNhnRevmJDijpG9omYAP8VShI+tgTl UavYdLUevOU5NlNxWQ7iLzzBg2gUeNcdcmpvLphEVSDAgEceX92G2hJTov5eiywbGOcH VvQFSwvCSCR9cwkO/AYbNUzkiqpXlpK4MKzz9owgIGXeZd2IbWkkMcqMVI0F6XZwTtmI vmnJFucYoWeqWru3My1TWkaDu+GOWwRph+6HrmzbZ59kbqoIiiTHWPOgm4Y5MTwfLyqN d14SAl46WnM6SlNADeKldOc2+4ojf+mm7XLqa/zEjFSB28y9aP1fDGA/FQqXb1An43ES D4Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mW8kXynh; 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 o61si14921035plb.0.2019.07.24.13.33.45; Wed, 24 Jul 2019 13:34:00 -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=mW8kXynh; 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 S2387627AbfGXT2y (ORCPT + 99 others); Wed, 24 Jul 2019 15:28:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:47534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728886AbfGXT2w (ORCPT ); Wed, 24 Jul 2019 15:28:52 -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 6541120659; Wed, 24 Jul 2019 19:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996531; bh=q+ot2fxsXnPozpPYSz+QkVHJLk2RXJQAoDWjkYnihxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mW8kXynhnlSX5OLjCEvoV/ND4zNX0iOJlmbJn9hkCc/JWqLoqMPfCtcDqf06tQrmI f4LgYF3/TTTojMfbQQcX9bZ8RnOHjlziygwSzl6muX4a/yKZPoj/ZP495izmiB6xs/ bedA4GENImPrNba4O7NxCnVNrr+Dd9v14NquPHfA= 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 5.2 130/413] EDAC/sysfs: Fix memory leak when creating a csrow object Date: Wed, 24 Jul 2019 21:17:01 +0200 Message-Id: <20190724191744.373441644@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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 bf9273437e3f..7c01e1cc030c 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.groups = csrow_dev_groups; device_initialize(&csrow->dev); @@ -415,7 +417,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