From patchwork Tue Jun 23 19:56:34 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: 223245 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=-10.0 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,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 AC0D4C433DF for ; Tue, 23 Jun 2020 21:13:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F0EA20706 for ; Tue, 23 Jun 2020 21:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592946788; bh=zALHqMiguNc+FwOzNshQCTuETpDJRuk1PqNXG/LKOjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=XsE+INFdzaWD7/qdESlKZRuHYNKNN5uLHh3Zai1fYqiWhxDdfzrjkGrEDmPk44E81 Zj+MFNN99nD4fJvZ9fFr1IpI5KpAR9nIjpZ7kHN1XhxwmVEaZiWNKYNBb6NMdiBx70 6StSXL2ax4OFmIhmZ0RO7w6+TKohi3CIpr2oicKA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393241AbgFWVNG (ORCPT ); Tue, 23 Jun 2020 17:13:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:51140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389284AbgFWUas (ORCPT ); Tue, 23 Jun 2020 16:30:48 -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 6BE84206C3; Tue, 23 Jun 2020 20:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944248; bh=zALHqMiguNc+FwOzNshQCTuETpDJRuk1PqNXG/LKOjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ri9+SBOus7CNVadoOcuRr3tYcbN0/lxBgckD/rcwqJMVTwXlOLVfie7rf/9EpdBIj vIQf/PHbkADsSZmhBWI8Ffs8CM80NtVkl7H96nP79chGQuLxMd3Gv74d4Ml/2HyXVC yPgNORRVYS7kVAnlgNhHZ6A/W+7XUozax8+BWoH4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Rob Herring , Sasha Levin Subject: [PATCH 5.4 199/314] of: Fix a refcounting bug in __of_attach_node_sysfs() Date: Tue, 23 Jun 2020 21:56:34 +0200 Message-Id: <20200623195348.417408733@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@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: Dan Carpenter [ Upstream commit 8a325dd06f2358ea0888e4ff1c9ca4bc23bd53f3 ] The problem in this code is that if kobject_add() fails, then it should call of_node_put(np) to drop the reference count. I've actually moved the of_node_get(np) later in the function to avoid needing to do clean up. Fixes: 5b2c2f5a0ea3 ("of: overlay: add missing of_node_get() in __of_attach_node_sysfs") Signed-off-by: Dan Carpenter Signed-off-by: Rob Herring Signed-off-by: Sasha Levin --- drivers/of/kobj.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index c72eef9880417..a32e60b024b8d 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -134,8 +134,6 @@ int __of_attach_node_sysfs(struct device_node *np) if (!name) return -ENOMEM; - of_node_get(np); - rc = kobject_add(&np->kobj, parent, "%s", name); kfree(name); if (rc) @@ -144,6 +142,7 @@ int __of_attach_node_sysfs(struct device_node *np) for_each_property_of_node(np, pp) __of_add_property_sysfs(np, pp); + of_node_get(np); return 0; }