From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 081F779C0 for ; Wed, 30 Nov 2022 18:45:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EE76C433D6; Wed, 30 Nov 2022 18:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669833935; bh=cVdOIEB+97bkgazS7BZdOZ/ofZztyZOhoOSd+z7p9gU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2W+5lywIQ3bY4z8ZfJF9OM1bGiEHO+oVIE1Ag51T/NvsW+Zqx0sE2O9kIuRM2YQCs ytaVkXMlB6F1RZHAh26J08fJ0iIwCjAnTV5yYmmjvSoVFGa3OQmzum5e6dWZL+1TNq UsOzjUFb4kBtI3zMPonS3H3NmDbBjSpxRhU/0Cvo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yang Yingliang , Sumit Garg , Jens Wiklander , Sasha Levin Subject: [PATCH 6.0 068/289] tee: optee: fix possible memory leak in optee_register_device() Date: Wed, 30 Nov 2022 19:20:53 +0100 Message-Id: <20221130180545.671158467@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221130180544.105550592@linuxfoundation.org> References: <20221130180544.105550592@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Yang Yingliang [ Upstream commit cce616e012c215d65c15e5d1afa73182dea49389 ] If device_register() returns error in optee_register_device(), the name allocated by dev_set_name() need be freed. As comment of device_register() says, it should use put_device() to give up the reference in the error path. So fix this by calling put_device(), then the name can be freed in kobject_cleanup(), and optee_device is freed in optee_release_device(). Fixes: c3fa24af9244 ("tee: optee: add TEE bus device enumeration support") Signed-off-by: Yang Yingliang Reviewed-by: Sumit Garg Signed-off-by: Jens Wiklander Signed-off-by: Sasha Levin --- drivers/tee/optee/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c index f3947be13e2e..64f0e047c23d 100644 --- a/drivers/tee/optee/device.c +++ b/drivers/tee/optee/device.c @@ -80,7 +80,7 @@ static int optee_register_device(const uuid_t *device_uuid) rc = device_register(&optee_device->dev); if (rc) { pr_err("device registration failed, err: %d\n", rc); - kfree(optee_device); + put_device(&optee_device->dev); } return rc; -- 2.35.1