Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3783692ybi; Mon, 29 Jul 2019 12:32:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjgupYvafTMFWRMBlmm2TnV3yvn+WM6+jN9pbiqL93OqPujicG+lSxGMokRjRU/NrDM5fS X-Received: by 2002:a63:6154:: with SMTP id v81mr71881777pgb.296.1564428778285; Mon, 29 Jul 2019 12:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428778; cv=none; d=google.com; s=arc-20160816; b=EUsM/DnT/rxT94hUWZ7e3WzKjLQO3iU4R0MN74RoY5d13dV2vrNaKwXXEWTnqQ2ZT6 BvOaebMU5MubPSdlJFBjTbhgxvUPVK+tTPvxVbaXlm/lpUmBg18TK0ScMsddSOSF0+jd SPK7oSFhT5sp+hcXai9k6RIzEdFamSWS08mbVvsBE7m/U0z7VejEdoqepc5Imf3y3qNk dYoIQwFo7WJjAtzGliZwcnZlPOVhUzDtfYW6M73btR4X+VFLbm8hLVx8mw0aA1Ru+5QA S65On8mOq/sWXy07ekqMVYricG3cBDK0d7PtCg5V2eq/LjqsQMeiYKTUOXKHQStZ49Cj Z/Zg== 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=AjL5U7Y7CR0+ihUFTXmGkz/5nxaJNzdhZiGnA917abs=; b=RqYJ7MjpI5UPXtS4hG+I8k33NWIroTtZ+F2XEbOIqRK+s9YsWqupUXaeqBL4wa8zIX U8mqhyoMRdhDQ49XFq3zA3ePPbzU0XbDgKoOIzJV1on3OvAJixKFXXqg1tH6pMoIpfJJ 1BdIDlX7Fp6pXWz8Po7ZYSQ8i6qdDzRx6S2Em6lyHJiSDmoRrBu6Gz43i2XbDx9tpz+G sHpCEXky/yjkTG/blpmdPnR6Oa0HM/USFHECrXBvJC+KCqDIonQr74shpMF9KkArWMAn cmfKDS4sPeybJS+d3H0E07RzrFbACswZ/bgp/Gj/Py3EV7Etz1DBSkkBqrgLGjZnBFLm Or/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xjyZQIsT; 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 d38si28201902pgl.519.2019.07.29.12.32.42; Mon, 29 Jul 2019 12:32:58 -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=xjyZQIsT; 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 S2388348AbfG2T1U (ORCPT + 99 others); Mon, 29 Jul 2019 15:27:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:39914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729886AbfG2T1R (ORCPT ); Mon, 29 Jul 2019 15:27:17 -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 C5A9F2171F; Mon, 29 Jul 2019 19:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428437; bh=WNEwlZmblCDELfMHFO9HduNW/EQ4DWBXMScy77tVMug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xjyZQIsTvBSAD/RzUmU8a/S6Ho7dYKDS5hk07ej/oXK+ks1uJ6g10HCnt53ZyO7vT zOPJDv+wbFVXZI9fyqmE8efuYGG9cVpg1z2HibnbQG0wER8AMD5EYJl9gIqXJYZAs5 RpibLLEWTW7dEy1MGB5tDMnu8RgcBv5lT31HrVCs= 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.14 059/293] EDAC/sysfs: Fix memory leak when creating a csrow object Date: Mon, 29 Jul 2019 21:19:10 +0200 Message-Id: <20190729190828.825030264@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 79c13301bf41..148c4649b155 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -426,6 +426,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; @@ -438,7 +440,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