From patchwork Mon Aug 17 15:17:02 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: 266263 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=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 C0712C433E5 for ; Mon, 17 Aug 2020 18:07:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A84A020758 for ; Mon, 17 Aug 2020 18:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597687625; bh=Ng2tOrxEp8pZfbfhtFR6UdaLGZgSyRBgIuydK9oq/+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=l6033q6Yodw5USn9beRbgQNyZ4O4zEddP9B2XxTn38pcc8jkJvrrz3pAXqEcYqf16 bpjmUNEEH0Q15YkujXod+UEFQC91s11iSUt0QbLEZk9VQZ1J9cyLG7tYx+Uw2kyfVa 0YRnfACcFYXJbyfrPI0L4U4Q0h08IH2jUfU3lLRY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390304AbgHQSGu (ORCPT ); Mon, 17 Aug 2020 14:06:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:58728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388475AbgHQQIv (ORCPT ); Mon, 17 Aug 2020 12:08:51 -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 F04E6207FF; Mon, 17 Aug 2020 16:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680528; bh=Ng2tOrxEp8pZfbfhtFR6UdaLGZgSyRBgIuydK9oq/+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIahBpPMoCBjSGq2C7eDqrW8pRSUikR0cJ+n4ii36onhOUJvHtBimwptAsZ70daqY /ko85i6La2FN54aS256yBEzH4dswvcqZeeKUJx9JFIiHSSi9qqyqRlk+0/tcoHNRMl zhbXKPXfqdwc101G+KcoR0jKQTbTBFChWbqHTg0c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heiner Kallweit , Johan Hovold , "David S. Miller" Subject: [PATCH 5.4 221/270] net: phy: fix memory leak in device-create error path Date: Mon, 17 Aug 2020 17:17:02 +0200 Message-Id: <20200817143806.780252460@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@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: Johan Hovold [ Upstream commit d02cbc46136105cf86f84ac355e16f04696f538d ] A recent commit introduced a late error path in phy_device_create() which fails to release the device name allocated by dev_set_name(). Fixes: 13d0ab6750b2 ("net: phy: check return code when requesting PHY driver module") Cc: Heiner Kallweit Signed-off-by: Johan Hovold Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/phy_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -615,7 +615,9 @@ struct phy_device *phy_device_create(str if (c45_ids) dev->c45_ids = *c45_ids; dev->irq = bus->irq[addr]; + dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr); + device_initialize(&mdiodev->dev); dev->state = PHY_DOWN; @@ -649,10 +651,8 @@ struct phy_device *phy_device_create(str ret = phy_request_driver_module(dev, phy_id); } - if (!ret) { - device_initialize(&mdiodev->dev); - } else { - kfree(dev); + if (ret) { + put_device(&mdiodev->dev); dev = ERR_PTR(ret); }