Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17927645ybl; Thu, 2 Jan 2020 15:00:03 -0800 (PST) X-Google-Smtp-Source: APXvYqzDhPz8itppS8UWMcuKjfK/WZmfQ8c0GM0QspqS4J6XBGVlnjRYL+1k8sxTIpng1OnUMeZ1 X-Received: by 2002:a05:6830:1d7b:: with SMTP id l27mr1137149oti.251.1578006003630; Thu, 02 Jan 2020 15:00:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006003; cv=none; d=google.com; s=arc-20160816; b=JGA9N3vkeYCizkA6TD6YYw0c6HA41/7XdP49r7pnkla8srZTzxaFV9mUS6ysnaUkh0 0UUHjdPS7xdk7FVclMa4AR0z1WcSPDGffaIN3CBWeFrWZ2VjeF9BK8paLCNs6Aq2NNnU gbvc5gPgQ7fmhLHWjhTFrhO75Zmy4eG9lM227WjomCI0GCRMwA4YKJYxuCXlRIfhJ4hJ Q4npCj/vcVgx1zhT1JXkY5mGhKScb7SslcL9K7O6AKZ7duYzK2TNk8hB+aNLXvWGWnMx S4wMrl174OiuZCCL0rTXMBnkA2qQEN/mCVLCjzcTFT4u1SZkF7eVqv0Sxabj3U53ljJH IrDw== 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=Cb0R2JC2tz1tnaPNWOBs6JcBISzyns+DK9R8gX4urpY=; b=BQKQld9iQ1HTFgHxpLdjQeEA88R4MVXmmR4OG1kzu1/jfBvDhX/9MH6wYJikVGp84E EV7QanIuLFsiFYTmMisu6thjUXaOv6ozkGxdfs9HIqHYxxcmSU/yU2nUxJw2iEYepBWX 6b5m4nFiRlpwir9LI6UcOYLsqkDQOaqDn9OJxvsc5L16RWcU24ObanlltkUIh2WRlAM1 dJBLprxZoCq7pvFlBlRyi2C/b8P34Ih/PgDilLfoAH9udrGQovxZsoaa4TOcilFaXrqT Y2qZUUYudKFEnvA97+YMQ0N5ibl+2lz86I3YACkdAiV+p/WGfkIKiQ0Y2QeVYIIPuaPq cmcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VYny6Olf; 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 f22si27207769otp.178.2020.01.02.14.59.52; Thu, 02 Jan 2020 15:00:03 -0800 (PST) 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=VYny6Olf; 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 S1727460AbgABWP3 (ORCPT + 99 others); Thu, 2 Jan 2020 17:15:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:56220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727134AbgABWPY (ORCPT ); Thu, 2 Jan 2020 17:15:24 -0500 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 A178C24649; Thu, 2 Jan 2020 22:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003323; bh=P3a/ZEkweCnG571B9JxdD9lRevBt7k9vKFOiEEnafLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VYny6OlfeiX0VvqWuYEYiKca7ub+mtW8iCbxidyCY6bacKZjgQVYL5y79+Ekis+do oUN+STMaEqUfr/f3prTSAhFdR9UUDPC6lmoRz/zbewf1wdBXbyk9qYFW0B9pHqbQs3 r60PGbDpxZe6UmWzvfSj+HkrjCHZLd6dWvlkqz84= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erhard Furtner , Michael Ellerman , Tyrel Datwyler , Rob Herring , Sasha Levin Subject: [PATCH 5.4 112/191] of: unittest: fix memory leak in attach_node_and_children Date: Thu, 2 Jan 2020 23:06:34 +0100 Message-Id: <20200102215841.878154675@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@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: Erhard Furtner [ Upstream commit 2aacace6dbbb6b6ce4e177e6c7ea901f389c0472 ] In attach_node_and_children memory is allocated for full_name via kasprintf. If the condition of the 1st if is not met the function returns early without freeing the memory. Add a kfree() to fix that. This has been detected with kmemleak: Link: https://bugzilla.kernel.org/show_bug.cgi?id=205327 It looks like the leak was introduced by this commit: Fixes: 5babefb7f7ab ("of: unittest: allow base devicetree to have symbol metadata") Signed-off-by: Erhard Furtner Reviewed-by: Michael Ellerman Reviewed-by: Tyrel Datwyler Signed-off-by: Rob Herring Signed-off-by: Sasha Levin --- drivers/of/unittest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 92e895d86458..ca7823eef2b4 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1146,8 +1146,10 @@ static void attach_node_and_children(struct device_node *np) full_name = kasprintf(GFP_KERNEL, "%pOF", np); if (!strcmp(full_name, "/__local_fixups__") || - !strcmp(full_name, "/__fixups__")) + !strcmp(full_name, "/__fixups__")) { + kfree(full_name); return; + } dup = of_find_node_by_path(full_name); kfree(full_name); -- 2.20.1