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 27AC612F5AB; Tue, 23 Jan 2024 00:16:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969004; cv=none; b=KDxRY2mjgMcV1d+ssHzNln068RNkqXcVP1QjWBIC5/YMzom4ff5RswL4HO4+SWjBCG09sx4J96mUcgAvHqwdR9WnR6iC2XCJYqWTWgjoykNhCmoprVjDAGxxpJpvFIk2Q0vvKMEzHF9xDas/94lXIwSqpknd1RYDcJ1LLBRtb98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969004; c=relaxed/simple; bh=Ty0PQUrgRb0qmXxN91t1Ic9KYLaX8puYDAHaQPpFYwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EE0MW1dfTJRBZ/P22kixMm6snGGaMyMiWPMzUyNON6hpH2g4bc3pQ8EdiT9cStHnbMX2sj/lmnwdh/5g9bBpXAaYMiuIXRMEPx77ZR4wVX7/4r7/I4mmt3xEm/tEUtvLOrlIAiIgIHjIkzQiGMLJ2XFh7JKA5SEvlwMBB24Qg1k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YGrILZyG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="YGrILZyG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0CD6C433F1; Tue, 23 Jan 2024 00:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705969004; bh=Ty0PQUrgRb0qmXxN91t1Ic9KYLaX8puYDAHaQPpFYwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YGrILZyGBK5L1iLKq16vimw6UJG5U3xzFT4X6xC8Ln9Xh17V1nzPBZ7YBeLvkI67u VnW8MeGF8n0o0w3Mw9b7hXTZcv/8wmtbRP23iA0ENwmh6Vkz879BEsXkSZB3HJRtIa 9gAUuqUUBQ3RZPpg48h2tz+zajtJU7QUqG7gBQ/o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Christian A. Ehrhardt" , RD Babiera , Heikki Krogerus Subject: [PATCH 5.4 153/194] usb: typec: class: fix typec_altmode_put_partner to put plugs Date: Mon, 22 Jan 2024 15:58:03 -0800 Message-ID: <20240122235725.750578615@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235719.206965081@linuxfoundation.org> References: <20240122235719.206965081@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: RD Babiera commit 5962ded777d689cd8bf04454273e32228d7fb71f upstream. When typec_altmode_put_partner is called by a plug altmode upon release, the port altmode the plug belongs to will not remove its reference to the plug. The check to see if the altmode being released is a plug evaluates against the released altmode's partner instead of the calling altmode, so change adev in typec_altmode_put_partner to properly refer to the altmode being released. Because typec_altmode_set_partner calls get_device() on the port altmode, add partner_adev that points to the port altmode in typec_put_partner to call put_device() on. typec_altmode_set_partner is not called for port altmodes, so add a check in typec_altmode_release to prevent typec_altmode_put_partner() calls on port altmode release. Fixes: 8a37d87d72f0 ("usb: typec: Bus type for alternate modes") Cc: Co-developed-by: Christian A. Ehrhardt Signed-off-by: Christian A. Ehrhardt Signed-off-by: RD Babiera Tested-by: Christian A. Ehrhardt Acked-by: Heikki Krogerus Link: https://lore.kernel.org/r/20240103181754.2492492-2-rdbabiera@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/class.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -189,11 +189,13 @@ static void typec_altmode_put_partner(st { struct altmode *partner = altmode->partner; struct typec_altmode *adev; + struct typec_altmode *partner_adev; if (!partner) return; - adev = &partner->adev; + adev = &altmode->adev; + partner_adev = &partner->adev; if (is_typec_plug(adev->dev.parent)) { struct typec_plug *plug = to_typec_plug(adev->dev.parent); @@ -202,7 +204,7 @@ static void typec_altmode_put_partner(st } else { partner->partner = NULL; } - put_device(&adev->dev); + put_device(&partner_adev->dev); } static void *typec_port_match(struct device_connection *con, int ep, void *data) @@ -465,7 +467,8 @@ static void typec_altmode_release(struct { struct altmode *alt = to_altmode(to_typec_altmode(dev)); - typec_altmode_put_partner(alt); + if (!is_typec_port(dev->parent)) + typec_altmode_put_partner(alt); altmode_id_remove(alt->adev.dev.parent, alt->id); kfree(alt);