From patchwork Sun Sep 1 04:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 824682 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 75B5881205 for ; Sun, 1 Sep 2024 04:07:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163635; cv=none; b=gpkWdpPPdjNdwwJBRJ+OYcJ1nzQPrZDCZ+JGjBqAVfTr+JjzEGO8jFWZNDjMpXwMkAeSh1+h51DJH9qZHFoNiudWnKVoMNEfbfASSFmjfv3a4VCE0TSmHteYxXhHO7uCWpFOXLsIr241yE3zcoH2aJSCLn6+XxCp9RD29VLZp8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163635; c=relaxed/simple; bh=3V7619Mxma8Aeax8LSroAiPwdTZh9etPyCL5UGAdaDs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z3tjBd/Ax/64OUTm75YtBJV5rmVOKn2pz/HPAIz9Sx0ssgbyyZdKp8eu//a0tKFBkvdjSkhCx9HTTfDeiaVi9EKXhcwWNRnynrFft0RmGiF6T6amMng/vEOuKXzWNqi2C3KRj2m9LUMPLcYhX7Cv6EETXsqbXqPZ5d71/SK1LDU= 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=Fjn6GT0z; arc=none smtp.client-ip=209.85.210.177 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="Fjn6GT0z" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-714187df604so2471292b3a.1 for ; Sat, 31 Aug 2024 21:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163633; x=1725768433; 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=Sko4acOmndCniAhhaR8U/EXx+Ad9ii+FHZslBTejwPk=; b=Fjn6GT0ze9jkBg6J3ysjfDtV3HtMJ52+EXoFOTljJy78xDJiVuCwLLSFKBnCRi/2Sj lhV94FS5v/+1DW8X3sZXXzvGAldu4MgEsXdBIztfOHEcH0Mn/c2/jJv3PqTy/YabnbBz 6eOA8hgVGjJSbTJm8oh127ckpYtOTiwjbNCFo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163633; x=1725768433; 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=Sko4acOmndCniAhhaR8U/EXx+Ad9ii+FHZslBTejwPk=; b=V4QqH4dPnqghGMOdH92p8kow2nc6o39Y9IOkNAm+QbYW6NR9RjzXpw3VL+44f/vHP2 dcFTN8jotg7VWx+MEnHDBndJxT6ocAQAq6pZsBZc6QLLVY2DcsdQojwMdH2ifEJmozPe gKbHIqFfHxbS78NoCzc1KcEG+JBNSf405aa2hJMV/hzG+5dy8IxrdwP6c7xD8zXJPbCa 3jEtw2Et5GtvBJJfltf3HSjBy1YTz5n4d4gz7YUw0VNTxoa1lYl9bCpNfmbCCWof/Amq PH8p9xXST2brvbYGXTzfBbH5B5h6F+Eivb5t5bHltg6AAWzffve+sxr9XFSl3GUgW6DC OyPQ== X-Forwarded-Encrypted: i=1; AJvYcCXMgA0rf7nhZYtLnaVSkcW+FhD9ksc1Gwgz7d16EV8LyFjjgsGmzipxUtC+ylkz8RbelFJBbQyTwP0=@vger.kernel.org X-Gm-Message-State: AOJu0YzKFJyeE3okHtHLnncNT5ZMU12ktp5qgtry9hY0bNiRWHyxZ2aP lF73oSefrK6DWTRXLMqtfaeY4eITSbu0Bkm+HJT1L8lYJJShdMJkKFzLEZlpug== X-Google-Smtp-Source: AGHT+IEupx5MlVbtKwKg6yvd5EiB5c1xx+gvkZPhgQaQWXBcBa4Tm7HItPIXvwrtuhd2v5lBCFGh8g== X-Received: by 2002:a17:902:f60a:b0:1ff:4a01:43f7 with SMTP id d9443c01a7336-2050e97bf7bmr144975245ad.10.1725163632654; Sat, 31 Aug 2024 21:07:12 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-205155673a2sm47107365ad.303.2024.08.31.21.07.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:12 -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 05/18] usb: typec: Add device managed typec_switch_register() Date: Sat, 31 Aug 2024 21:06:43 -0700 Message-ID: <20240901040658.157425-6-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-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify driver error paths by adding devm_typec_switch_register() which will unregister the typec switch 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 | 36 +++++++++++++++++++++++++++++++++++ include/linux/usb/typec_mux.h | 9 +++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index db644bec862c..f420185e36e3 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -235,6 +235,42 @@ void typec_switch_unregister(struct typec_switch_dev *sw_dev) } EXPORT_SYMBOL_GPL(typec_switch_unregister); +static void devm_typec_switch_unregister(void *switch_dev) +{ + typec_switch_unregister(switch_dev); +} + +/** + * devm_typec_switch_register - resource managed typec_switch_register() + * @parent: Parent device + * @desc: Multiplexer description + * + * Register a typec switch and automatically unregister the typec switch + * when @parent is unbound from its driver. + * + * The arguments to this function are identical to typec_switch_register(). + * + * Return: the typec_switch_dev structure on success or error pointer on error. + */ +struct typec_switch_dev * +devm_typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc) +{ + int ret; + struct typec_switch_dev *switch_dev; + + switch_dev = typec_switch_register(parent ,desc); + if (IS_ERR(switch_dev)) + return switch_dev; + + ret = devm_add_action_or_reset(parent, devm_typec_switch_unregister, switch_dev); + if (ret) + return ERR_PTR(ret); + + return switch_dev; +} +EXPORT_SYMBOL_GPL(devm_typec_switch_register); + void typec_switch_set_drvdata(struct typec_switch_dev *sw_dev, void *data) { dev_set_drvdata(&sw_dev->dev, data); diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index 08431f0896d5..c30fc7f4441f 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -35,6 +35,9 @@ int typec_switch_set(struct typec_switch *sw, struct typec_switch_dev * typec_switch_register(struct device *parent, const struct typec_switch_desc *desc); +struct typec_switch_dev * +devm_typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc); void typec_switch_unregister(struct typec_switch_dev *sw); void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data); @@ -60,6 +63,12 @@ typec_switch_register(struct device *parent, { return ERR_PTR(-EOPNOTSUPP); } +static inline struct typec_switch_dev * +devm_typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc) +{ + return typec_switch_register(parent, desc); +} static inline void typec_switch_unregister(struct typec_switch_dev *sw) {} static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data) {}