From patchwork Tue Dec 17 07:44:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ma Ke X-Patchwork-Id: 13911344 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2BFBE7716A for ; Tue, 17 Dec 2024 07:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=wQ7T+TgR98exSx/S6Kdj9wB+K9BJ91/JRdNfZIHCRXM=; b=tAgsJKEN5Iwipu n4CvBV5dnbhM/EZJO9PEEWPwIaEV7y5bmCfK5SU9a5hMkNSfm3wyj36Ykm47IDpTZHvVrB+6sUvri 49uy2DQqRRVmpFzAJ9zz5bFl+MY6bd/UCdwgu6k+cVK3Tz5rCoFQHV5YT0+AYsHHsmcFelMQ3fOBr VpGRON5T9sChLgGYWapEODL7rwMntek09y5nFTh5/DSFxYxPyayt03APZ4xV4wizf2hRYLrKGSi/3 xRGVG28qfgKMRNYpZS3CRu7J97GQL8stbv4z+VxGKXfZHiBCf4ou7tmxNJ1WZFYTmtJ8QmDQUie1G vaAz3nB3SYUm/MywJ0sA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNSGu-0000000CcMV-2aIY; Tue, 17 Dec 2024 07:45:36 +0000 Received: from m16.mail.163.com ([117.135.210.2]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNSGs-0000000CcLz-0Cb4 for linux-phy@lists.infradead.org; Tue, 17 Dec 2024 07:45:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=SNECs J0XKp8vy5JU0Zqz2v1x01Madw93zTND8IbZ038=; b=hRhpjsdg5OkoVnR0WKaEL JBWLl5dmD080kRNjcv/z36HN6RRatBjNCG63NvR03oGH2PKeyy7l0bzTWe4G5XG+ a8qmPIrvKxfmUUBpYBq/1NVNR3jnw6oxxDcjVZBUC0F6DpX0roTi6hLkYiA6O1Wy l87C8NqMq11LRAbPx6hYpU= Received: from icess-ProLiant-DL380-Gen10.. (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wC3P7_6K2FnmKuTBA--.3033S4; Tue, 17 Dec 2024 15:45:07 +0800 (CST) From: Ma Ke To: jckuo@nvidia.com, vkoul@kernel.org, kishon@kernel.org, thierry.reding@gmail.com, jonathanh@nvidia.com Cc: linux-phy@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, Ma Ke , stable@vger.kernel.org Subject: [PATCH] phy: Fix error handling in tegra_xusb_port_init Date: Tue, 17 Dec 2024 15:44:57 +0800 Message-Id: <20241217074457.2909598-1-make_ruc2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: _____wC3P7_6K2FnmKuTBA--.3033S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gr15JF48GryxJFy3Zr1UKFg_yoWkXrgEkr nYv3s3WrWvga1kCr15Crn3ZryIkF42qFyIqr4IqF93AayrXrs2vryDWrZxZr47Wws8ur1U Ga45ur48Zr1SgjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRNtxhDUUUUU== X-Originating-IP: [183.174.60.14] X-CM-SenderInfo: 5pdnvshuxfjiisr6il2tof0z/xtbBXx+4C2dhH7fIsgABsm X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_234534_512384_E6E722D8 X-CRM114-Status: UNSURE ( 8.99 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org The reference count of the device incremented in device_initialize() is not decremented when device_add() fails. Add a put_device() call before returning from the function to decrement reference count for cleanup. Or it could cause memory leak. Found by code review. Cc: stable@vger.kernel.org Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support") Signed-off-by: Ma Ke --- drivers/phy/tegra/xusb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c index 79d4814d758d..c89df95aa6ca 100644 --- a/drivers/phy/tegra/xusb.c +++ b/drivers/phy/tegra/xusb.c @@ -548,16 +548,16 @@ static int tegra_xusb_port_init(struct tegra_xusb_port *port, err = dev_set_name(&port->dev, "%s-%u", name, index); if (err < 0) - goto unregister; + goto put_device; err = device_add(&port->dev); if (err < 0) - goto unregister; + goto put_device; return 0; -unregister: - device_unregister(&port->dev); +put_device: + put_device(&port->dev); return err; }