Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1692761pxa; Sun, 23 Aug 2020 12:34:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwSiDxNtPK1TES2Bz1Bvdyp99jL0KoWvOWPtk2UryZVtanCn/3BICOzlZtJH3e9s9ivSjc X-Received: by 2002:a17:907:a8c:: with SMTP id by12mr2530974ejc.554.1598211259212; Sun, 23 Aug 2020 12:34:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598211259; cv=none; d=google.com; s=arc-20160816; b=MT8rtdiGuBtEHgr5CU5an+xgmcy7w1vIDXfX6FtA+eBGj1OKG9F/gIs1+6HYXSWQXJ kYoGHmLGp6/f4qjNkl+n7VQwfzTa1cL2hz7IsQCfNbJoL/RhnNS2uHLOC1wLomDHLklw nYifCp0B3TWwLK4eQ4B3pi2rE85Dm4RAdt4TAjJi1lj5DngHXqXRBkLyG7kAFMAmpL+T xF0PcBIswIQggN8vHjn4JUyPm6W6VjXLDKKH2UN2o8/ey/77VUbvd3wcYEkLKz3w5WE5 Ak7nKsnG8CHCKVvWXp5/umj8vRzPpGfNwrJUNGKbb4/PSHRFs0gX0vdqF57dzxD11cGw oH2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=weNWHTNBlFYVLfVtCUahgwUBiIrruSXZn6kHTI1JUaY=; b=05yP1YaXFLOoGGsBkhFBnAXVbPymLJ/uwflECCqMvRLsiN+UV8bQ+lYI/+glVN2i2g 5Fr6a3Fs2lTGw722WGsa2NMijAbtKZwEY8z1z5dGk+lTtGiyeIzrDKHQCGZvvo19nb6u 0pTRlNXlnvNrrFBSH3lvc5vVeJTAoSpGDf9tWWvxzCArwaGFZuFMpepbnNbwlsFQzEYc TRiRGEaMu5/ctOUGUaZNk5L3qAnrgBAcDrjFUknfRtO1hpeUORwi6NTLvCqTpwYgSMBE uYWRdOlIX5XJDERkpdZBrbXDA5KxcExMWh6YfnO0lWz6NRuWDM06r0NYyMGfWVXXcMia 7nCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V77Ac81F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr26si5269144ejb.47.2020.08.23.12.33.56; Sun, 23 Aug 2020 12:34:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V77Ac81F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726706AbgHWTbF (ORCPT + 99 others); Sun, 23 Aug 2020 15:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725885AbgHWTbE (ORCPT ); Sun, 23 Aug 2020 15:31:04 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04CBBC061573; Sun, 23 Aug 2020 12:31:03 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id bh1so3166524plb.12; Sun, 23 Aug 2020 12:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=weNWHTNBlFYVLfVtCUahgwUBiIrruSXZn6kHTI1JUaY=; b=V77Ac81FIKwovH3RsFHYw6KqcGVROAhAK7uQOVOywTRUgnyCtheBeTYlD1U+XRbKHB G/ioAl4eu40NyeaXo8Nl33FsxQSPIUvhrlHT2SLxOszsMe0ByUA9Szm5Jbg9ZuS4b0uy ZHJCNEJV1fLvjRhxlxSMq89sQ7MHRGM6yCJDrAa3t8rrnoQ8QIg5eezpRxC/UgdtYppA PoDfL/7KmBV3kKXseyYll1UVhOqEWjq8reufqJ6BX1Ou5u9bvkAQNSDgr0FJxnig6WZN q3am9o04NOYfbyLNjZlXhDpjGRu+YHnYJCuR1Y2E3KPVC9A4WB3DGhfailImR7zwA9Bg 92Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=weNWHTNBlFYVLfVtCUahgwUBiIrruSXZn6kHTI1JUaY=; b=dL7Y99KWwtreoa0EbxegI5lw84Tz9qq0mTBBL9qZzs7KN5fh4AFKlon3yb4cCPXIRR qKwNs/skHySolqOICLvUpIe9ijEyLuRxKbSOgZOStwCV9E0Q3eArL2gx2J82ln00WuL7 ZapovAL8aMUIVY4S/SIf9GngKvi7m+Gz9//4MRurisWMyPIXnci7xsm+wIAludVRRbMl Y/6W30N34hvKhtsaOIVJCcNUhy3Nb55GtLvaigZ1CyuDPJrWg381/IkTUq5KHE/FIV7F HBSgYnKmTDEC7o+sOYrQBNYvFxcIeQdpsa+1nqfCQX2JRhGZY5Rh65eROF7DehXIJsmU ZVpw== X-Gm-Message-State: AOAM53146SF6QFu8L4gDJqFx4SMoHMwsegcqRIC/LlXXby7nJaNNPeSY zEJnATl+VI/WfxBf0J0KgxE= X-Received: by 2002:a17:902:8bcb:: with SMTP id r11mr1547106plo.65.1598211063471; Sun, 23 Aug 2020 12:31:03 -0700 (PDT) Received: from localhost.localdomain ([49.207.212.93]) by smtp.gmail.com with ESMTPSA id mp1sm7804624pjb.27.2020.08.23.12.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Aug 2020 12:31:02 -0700 (PDT) From: Sumera Priyadarsini To: davem@davemloft.net Cc: Julia.Lawall@lip6.fr, andrew@lunn.ch, sean.wang@mediatek.com, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org, matthias.bgg@gmail.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Sumera Priyadarsini Subject: [PATCH V3] net: dsa: Add of_node_put() before break and return statements Date: Mon, 24 Aug 2020 01:00:54 +0530 Message-Id: <20200823193054.29336-1-sylphrenadin@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Every iteration of for_each_child_of_node() decrements the reference count of the previous node, however when control is transferred from the middle of the loop, as in the case of a return or break or goto, there is no decrement thus ultimately resulting in a memory leak. Fix a potential memory leak in mt7530.c by inserting of_node_put() before the break and return statements. Issue found with Coccinelle. --- Changes in v2: Add another of_node_put() in for_each_child_of_node() as pointed out by Andrew. Changes in v3: - Correct syntax errors - Modify commit message --- Signed-off-by: Sumera Priyadarsini Signed-off-by: Sumera Priyadarsini --- drivers/net/dsa/mt7530.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 8dcb8a49ab67..4b4701c69fe1 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -1326,14 +1326,17 @@ mt7530_setup(struct dsa_switch *ds) if (phy_node->parent == priv->dev->of_node->parent) { ret = of_get_phy_mode(mac_np, &interface); - if (ret && ret != -ENODEV) + if (ret && ret != -ENODEV) { + of_node_put(mac_np); return ret; + } id = of_mdio_parse_addr(ds->dev, phy_node); if (id == 0) priv->p5_intf_sel = P5_INTF_SEL_PHY_P0; if (id == 4) priv->p5_intf_sel = P5_INTF_SEL_PHY_P4; } + of_node_put(mac_np); of_node_put(phy_node); break; } -- 2.17.1