From patchwork Thu Aug 6 15:37:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 262688 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 B59A6C433E0 for ; Thu, 6 Aug 2020 16:43:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0358204FD for ; Thu, 6 Aug 2020 16:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596732211; bh=6PwJIoVena6bmZRBPbTsuUZUa3HRVYx/aHaiNJK0mzU=; h=From:To:Cc:Subject:Date:List-ID:From; b=n9JjuwtLWAzOmmtl8huRqQCRnbMbfajTib4Bo/kuC+csnGoEoMKXc43sldTfHnCbS 9el0pu2BxxZCLJMj+9gW2oizr4QuF9qcUxVfH+HA2Ldr1E9R/BwvWTjnlksmvsGsh/ IDYEshf+bG6HjloDH+bfREiffhwRKgNZeYKxeoyo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728678AbgHFQmy (ORCPT ); Thu, 6 Aug 2020 12:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729001AbgHFQkm (ORCPT ); Thu, 6 Aug 2020 12:40:42 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AAB8C0086BC; Thu, 6 Aug 2020 08:39:20 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id v4so42602271ljd.0; Thu, 06 Aug 2020 08:39:20 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=q5PIhTZ1k5FdG3NQbW/iiFuxA5Ifg1yNdI35SxS/Xwk=; b=qQGNBo6Ekik496p3/E13FqX0TMGK+7zedJcS9ukf6cmLtwnbAEhkXjXAbK7OHp5zjo /XPHpmUDEPKy8Iw38Q08tzeWDCaC/9ImokMgBOM+HRYwWv7ZdCjDiz8LibmRTeqN4BGD JYVlGgw/o3m3yuE14VtimRONafHPNADq7EkerpnxevEdfxQeHc2PP7JjDLlCHQ13vrnZ KIHN9/EjGf8fGNMsFBINqWmX6eJQUzr/h6XUcXnp9MgkyRAVehdfwdEajwjRkwwmiXeN uIiLMRZHyORk0e/nZ3sGaGObKos2UnoDouX31w8j6vQu2L+u3UpoBNuTxfY3hRic4Ny0 xb0A== X-Gm-Message-State: AOAM532XMv2iAljFtCbUMxAO+hbXbHoRKx+D9JZ/GYsb22XvWAsyqRd6 N6YkizC2wXu/GqsLTevUGxQ= X-Google-Smtp-Source: ABdhPJxkmm9iVoirzrxeN4OhGBs4mKGRNymtq+vksvikDKFhl16Z12DTSOySIPWDzecAwwEXojdHKg== X-Received: by 2002:a2e:9196:: with SMTP id f22mr4160854ljg.435.1596728358635; Thu, 06 Aug 2020 08:39:18 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id v26sm2554919lji.65.2020.08.06.08.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 08:39:17 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1k3hzE-0003Cf-Up; Thu, 06 Aug 2020 17:39:21 +0200 From: Johan Hovold To: Andrew Lunn , Florian Fainelli , Heiner Kallweit Cc: Russell King , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH net] net: phy: fix memory leak in device-create error path Date: Thu, 6 Aug 2020 17:37:53 +0200 Message-Id: <20200806153753.12247-1-johan@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- drivers/net/phy/phy_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 1b9523595839..57d44648c8dd 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -615,7 +615,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, 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(struct mii_bus *bus, int addr, u32 phy_id, 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); }