From nobody Mon Feb 9 14:38:41 2026 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 858C66F2FD for ; Sun, 1 Sep 2024 04:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163634; cv=none; b=nhgFpEnxhx46C61A85a8ovjiobSCRjQL0xG/22WbzvTMo30pozdWqHvtKY0Xdo7piYU1xStkiR45Qln6kPiB3yzyAdSMiVqg94KjaEfbEOwjAUqJLR6JiIUOtYUqBlTNHeX2cYrgX3zbZ2spd0Fa0HpkTqDA50vHmuzCi1TRhc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163634; c=relaxed/simple; bh=lQuo9VmpRTMEUSypDAVnMcCD781MhPSwWoCv0Ud9eec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BcGmxapsTLggnjy/u1GhHBc02sQzH2dGm4T0WCIXlT33yKaapz3jmIx6l1YGbXlJaYK8h8xOlXzOVtp4Mild5KADeGIK2cLlnhqBPuYdsrHST6Xk5qjvNcx05hw4x8ACbuyq7Wnb6L7pAntTG9QyYrfEmhNyGKIflA07LXZswgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=XXUBv+CG; arc=none smtp.client-ip=209.85.167.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XXUBv+CG" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3df07fe03acso1969527b6e.3 for ; Sat, 31 Aug 2024 21:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163631; x=1725768431; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2N8vS/njRh59NN9Hhbqh05Yl3HU3mcBshclMsZjbFEo=; b=XXUBv+CGuy3CD5Jb251OYi4bH6NRFL8hhKhRN+LccXoDWdaNtsaE7P7Os2YnehRkya LeblKHIvjH/dRZ/eSwOqRlZKRkvJXh1qTQSu+l5Gm8Htxk54v4f4gWXeZoCia305gNXh XyZUKfsI/VNTFC2iruBY195KOQqTKp8FEjpnY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163631; x=1725768431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2N8vS/njRh59NN9Hhbqh05Yl3HU3mcBshclMsZjbFEo=; b=QNtFdRs4PIDE4W8jO8C162DtFpUcmfl/eDaZe1FPffOZ+Mk6XbxlJTRKkKYr45v4Ke 0ImT7g0JLI89/JeueLg/qtid2poX3BxDGT2vhu6lj0X2kQHcF02CTyi/NzE79wCXz7ia TTedVMTTjcwl1ONsXbCMNikz8GcqvxnHdwEumxzFgBHGSm+607A3couQBxvviWeEIisC F/Vbxq7Jq9KqGlVULV++V41kKUR7g0V+lUEIEgWs9O3/SvjqD2GVOIfTo9ywf9akmVFs B6yGXbpCMDbTPzWvQBn2BGGde779/SfQbXhjBaDtHJ8u65mb4h1ZuWhPi8CQkztJNlHM 3I7g== X-Gm-Message-State: AOJu0YzctfQytBGsmjZHk65gsxnIGbvLUXTshQcNxrLgQ59r47zP6vmZ AaC7F6adfSeNjo7GeF+QHugx5jl+DIMp7vlW64qHjWAtH/HXZiHGsDusfJ/5ow== X-Google-Smtp-Source: AGHT+IGn0G5AiONQD8K5yi4LzBmU8yqa6VFEQOeNXV9U2Ho8xKtvyvDtSksQxtqrZ7RRI09TCw6qDQ== X-Received: by 2002:a05:6830:7310:b0:709:5601:abea with SMTP id 46e09a7af769-70f72bb320amr3883433a34.10.1725163630581; Sat, 31 Aug 2024 21:07:10 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7d22e77a7besm5341681a12.37.2024.08.31.21.07.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:10 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 04/18] usb: typec: Add device managed typec_mux_register() Date: Sat, 31 Aug 2024 21:06:42 -0700 Message-ID: <20240901040658.157425-5-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify driver error paths by adding devm_typec_mux_register() which will unregister the typec mux when the parent device is unbound. Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/usb/typec/mux.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/usb/typec_mux.h | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 49926d6e72c7..db644bec862c 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -457,6 +457,41 @@ void typec_mux_unregister(struct typec_mux_dev *mux_de= v) } EXPORT_SYMBOL_GPL(typec_mux_unregister); =20 +static void devm_typec_mux_unregister(void *mux_dev) +{ + typec_mux_unregister(mux_dev); +} + +/** + * devm_typec_mux_register - resource managed typec_mux_register() + * @parent: Parent device + * @desc: Multiplexer description + * + * Register a typec mux and automatically unregister the typec mux + * when @parent is unbound from its driver. + * + * The arguments to this function are identical to typec_mux_register(). + * + * Return: the typec_mux_dev structure on success or error pointer on erro= r. + */ +struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc= *desc) +{ + int ret; + struct typec_mux_dev *mux_dev; + + mux_dev =3D typec_mux_register(parent, desc); + if (IS_ERR(mux_dev)) + return mux_dev; + + ret =3D devm_add_action_or_reset(parent, devm_typec_mux_unregister, mux_d= ev); + if (ret) + return ERR_PTR(ret); + + return mux_dev; +} +EXPORT_SYMBOL_GPL(devm_typec_mux_register); + void typec_mux_set_drvdata(struct typec_mux_dev *mux_dev, void *data) { dev_set_drvdata(&mux_dev->dev, data); diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index efb5ed32b813..08431f0896d5 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -99,6 +99,8 @@ int typec_mux_set(struct typec_mux *mux, struct typec_mux= _state *state); =20 struct typec_mux_dev * typec_mux_register(struct device *parent, const struct typec_mux_desc *des= c); +struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc= *desc); void typec_mux_unregister(struct typec_mux_dev *mux); =20 void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data); @@ -123,6 +125,11 @@ typec_mux_register(struct device *parent, const struct= typec_mux_desc *desc) { return ERR_PTR(-EOPNOTSUPP); } +static inline struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc= *desc) +{ + return typec_mux_register(parent, desc); +} static inline void typec_mux_unregister(struct typec_mux_dev *mux) {} =20 static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *= data) {} --=20 https://chromeos.dev