Received: by 10.192.165.156 with SMTP id m28csp1075623imm; Wed, 11 Apr 2018 11:59:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx48lgL21LM4X41IZUtNaNz68cYVlWjeCNRjkNrEyZ/8SUQz7vhjr8lEWjfT1F6IaKOC2kJKd X-Received: by 10.101.69.198 with SMTP id m6mr4289885pgr.244.1523473146264; Wed, 11 Apr 2018 11:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523473146; cv=none; d=google.com; s=arc-20160816; b=fs/m3qdE7ufkeVePxE9zp+5uceF3V4gvo9dR7Sw7f8c5ijnrO3zZV35TpPT+8S22EM YsY6VnVxpDG5ozNpZU9Nyus0QbqHDrW/uGPnsiTEb44D/FRYAWJkSQNoxIo46W0T2d87 8Ti2aQVpeOPxJVgmqg+In3/ZQa/wssuJsWoPFCDADsdNznDAMT4+jOGIADW3amYdBdin wyqz4P+7t/21Vkf5VsAXODSggh5cR5AtkJMVtEo4Os3T65yieZNjBo17nmRDnyp5WoAc see2x8apewk6hKuTkp2LimggRZ1Uug+L1tSlyyB5TYYiS8M4RFNor9dsEx+nmNkoGS4K DNRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=2ZU2lzQ9IvDZ5gc2ckoeIejqimOxWsAb0z+urICEjLw=; b=n4P4KwhCrWQK5BhpRmch0dI4aDNoXexAU4lcyo1FwSTNb4cHsDFMiJ007wSBbNQXfW dbHiRVm2bGDSBloW6ChgmN3VYQ/Pk9C5AEwbTKgnDs5SpLjQfZGu2Q9n2UBIiYE/w1Jh o8GJUb1+wkUL1+AcG64627WDXmSLB6edBhm3pTsGOm8uSCTgXu2VWqrTiPNwqXNZfNaJ AdKifWbU+0tRG/IqSuDwhNyTP19WGMVErd+VVwOEJgHw1nPIpruZ9lmrUXbBHpIhloym 7kj9O1Pswv7jc/uFVfVWqzacO4CbYNfJzCV8gDgtDWCqTGMZJ4bkgXDNcGlIAgZ3fFRr dY1A== ARC-Authentication-Results: i=1; mx.google.com; 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 l4-v6si1663656plb.741.2018.04.11.11.58.29; Wed, 11 Apr 2018 11:59:06 -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; 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 S933661AbeDKSzJ (ORCPT + 99 others); Wed, 11 Apr 2018 14:55:09 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34886 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933614AbeDKSzG (ORCPT ); Wed, 11 Apr 2018 14:55:06 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C918199F; Wed, 11 Apr 2018 18:55:05 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Mason , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 032/310] mdio: mux: Correct mdio_mux_init error path issues Date: Wed, 11 Apr 2018 20:32:51 +0200 Message-Id: <20180411183623.663974819@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jon Mason [ Upstream commit b60161668199ac62011c024adc9e66713b9554e7 ] There is a potential unnecessary refcount decrement on error path of put_device(&pb->mii_bus->dev), as it is possible to avoid the of_mdio_find_bus() call if mux_bus is specified by the calling function. The same put_device() is not called in the error path if the devm_kzalloc of pb fails. This caused the variable used in the put_device() to be changed, as the pb pointer was obviously not set up. There is an unnecessary of_node_get() on child_bus_node if the of_mdiobus_register() is successful, as the for_each_available_child_of_node() automatically increments this. Thus the refcount on this node will always be +1 more than it should be. There is no of_node_put() on child_bus_node if the of_mdiobus_register() call fails. Finally, it is lacking devm_kfree() of pb in the error path. While this might not be technically necessary, it was present in other parts of the function. So, I am adding it where necessary to make it uniform. Signed-off-by: Jon Mason Fixes: f20e6657a875 ("mdio: mux: Enhanced MDIO mux framework for integrated multiplexers") Fixes: 0ca2997d1452 ("netdev/of/phy: Add MDIO bus multiplexer support.") Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/mdio-mux.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/drivers/net/phy/mdio-mux.c +++ b/drivers/net/phy/mdio-mux.c @@ -122,10 +122,9 @@ int mdio_mux_init(struct device *dev, pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL); if (pb == NULL) { ret_val = -ENOMEM; - goto err_parent_bus; + goto err_pb_kz; } - pb->switch_data = data; pb->switch_fn = switch_fn; pb->current_child = -1; @@ -154,6 +153,7 @@ int mdio_mux_init(struct device *dev, cb->mii_bus = mdiobus_alloc(); if (!cb->mii_bus) { ret_val = -ENOMEM; + devm_kfree(dev, cb); of_node_put(child_bus_node); break; } @@ -169,8 +169,8 @@ int mdio_mux_init(struct device *dev, if (r) { mdiobus_free(cb->mii_bus); devm_kfree(dev, cb); + of_node_put(child_bus_node); } else { - of_node_get(child_bus_node); cb->next = pb->children; pb->children = cb; } @@ -181,9 +181,11 @@ int mdio_mux_init(struct device *dev, return 0; } + devm_kfree(dev, pb); +err_pb_kz: /* balance the reference of_mdio_find_bus() took */ - put_device(&pb->mii_bus->dev); - + if (!mux_bus) + put_device(&parent_bus->dev); err_parent_bus: of_node_put(parent_bus_node); return ret_val;