From patchwork Wed Apr 22 09:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 227069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC03AC55189 for ; Wed, 22 Apr 2020 10:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BB122084D for ; Wed, 22 Apr 2020 10:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587552862; bh=RR9zuGd6KTiQ3TJQe/mCK7ogA8Sh/pMX/GIsvBdcKGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DX0btx5xWE9Y72Ev1vHb/rPL/jyaAZ4MTEmIIGJ79Z5nUtuy+Uu4Mvsa94Ma2PxD4 yV7/HY6ScVbJJH5RHYzRhDAv6e4U9qSbFgAMt4ArFp65N6ZkqS09HzzjpxU/f8Y07Y liMLuDTnzZZcC/Hqqf7T5/zpuxhf365PWHcpenKE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729300AbgDVKyV (ORCPT ); Wed, 22 Apr 2020 06:54:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:33050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728631AbgDVKIF (ORCPT ); Wed, 22 Apr 2020 06:08:05 -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 D4AB62075A; Wed, 22 Apr 2020 10:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587550084; bh=RR9zuGd6KTiQ3TJQe/mCK7ogA8Sh/pMX/GIsvBdcKGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLLoHpnLWc0lAH6DLzRCwFeYRwT/H5+YW/Pzo1oTaelJbeGsMKUeuvH0chKzKR6i0 N6ViHzV+8Yw5vw5Zt+NPK11n+cuwsvTc5ur5cd77TF8sDpXPzrTrnIU9R2pltGErBS IVvj6GhauebDK4hdQmXAoSRlDDmJ3cUPaUP4RHUo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Erhard F." , Frank Rowand , Rob Herring , Sasha Levin Subject: [PATCH 4.9 102/125] of: unittest: kmemleak in of_unittest_platform_populate() Date: Wed, 22 Apr 2020 11:56:59 +0200 Message-Id: <20200422095049.485814025@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095032.909124119@linuxfoundation.org> References: <20200422095032.909124119@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Frank Rowand [ Upstream commit 216830d2413cc61be3f76bc02ffd905e47d2439e ] kmemleak reports several memory leaks from devicetree unittest. This is the fix for problem 2 of 5. of_unittest_platform_populate() left an elevated reference count for grandchild nodes (which are platform devices). Fix the platform device reference counts so that the memory will be freed. Fixes: fb2caa50fbac ("of/selftest: add testcase for nodes with same name and address") Reported-by: Erhard F. Signed-off-by: Frank Rowand Signed-off-by: Rob Herring Signed-off-by: Sasha Levin --- drivers/of/unittest.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 40d170c1ecd50..144d123f6ea4f 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -825,10 +825,13 @@ static void __init of_unittest_platform_populate(void) of_platform_populate(np, match, NULL, &test_bus->dev); for_each_child_of_node(np, child) { - for_each_child_of_node(child, grandchild) - unittest(of_find_device_by_node(grandchild), + for_each_child_of_node(child, grandchild) { + pdev = of_find_device_by_node(grandchild); + unittest(pdev, "Could not create device for node '%s'\n", grandchild->name); + of_dev_put(pdev); + } } of_platform_depopulate(&test_bus->dev);