From patchwork Mon Aug 19 22:38:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 821285 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 89BC21DD3B0 for ; Mon, 19 Aug 2024 22:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107128; cv=none; b=HHgxh7VsT0cugeDcjSwvQDZqzJbJOdBPOZvV7rPX9C0yY1uvNLgXBZj3FpdlkcwYlExzwL/Hp6KqbZQavLB8dQPSXarTt5cAMRpfYFXfIaoIKxXF4WLnw9dTgC8qCRZYdBvnnZKgfpFM+Amr59fp4PM5cMWsHCZMmtt8xruMFc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107128; c=relaxed/simple; bh=YZsJrlae73dDXQ7qQXUAfgucjjDnE3ixdZvtKilWId0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WL64ZURbxQSul74JVM5+yiip6VqwALart2MznNzGLkIXdD6Tm135Z9v3V8bdkf3LH2fvnzFerldHZNsxu3rfgw0xlWgAWrDacknCkXH5A4zNZ344ddv3uJwRX2EGWMGbGym71ln00SjfazzYE9kTdvE50MMnozUtXO0hLmPKuKM= 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=Q8F+oilX; arc=none smtp.client-ip=209.85.215.182 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="Q8F+oilX" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-70b2421471aso3013185a12.0 for ; Mon, 19 Aug 2024 15:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107126; x=1724711926; 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=TByAwKUM3v221HSwHXMGl0z/VgI2w0FSGFaz63ewMCc=; b=Q8F+oilXRY+BpeGI2IOZRfrDirq+ohw2DINZ29jM0siAkVZeORgdj84A1c6wkQky8p Qkq7hs0rNNI7mt296gtTw3/u5/HlNPFiiKAMJ8+VRIHtKiAqXw3s7Bm3IWgdlc0/gjrx dCa0wYYe5NHHcy+gBjEtYRDuuB33mCfm7gpXA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107126; x=1724711926; 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=TByAwKUM3v221HSwHXMGl0z/VgI2w0FSGFaz63ewMCc=; b=oGHDeMZTvtxlaox2OOm6m3hP6wtzzXUYehctOB9djJKMulSbCcugUo7kzj4jwsuZjk 4nXTvDE7IZwuscdFp7HKpOPKCoNq1o9kgVB66lbtv0Oa08or8K3Ew5u97p5yN9bdiT/h gyAr1vH16umlV58gKvDvSNZP5Z2ZYF1yfZgov4YS/H7mhMHp5dBfBXi72SLCSwyoYVMN AvcvrQDQPQcDVQg/pjijQ7fm/8EDHG7o2Wzu801ihxPvtfSayYuONwVwqZB+Iibrg0mC olKr8xk7+T1GP/NIOLuVqmkGbsX16/tr9a6tXpJk4o6/hj8CtmOlZaGRYM2DFYZXLcW2 c46Q== X-Forwarded-Encrypted: i=1; AJvYcCXyVajK8oACHgz/nncWSx48kQ25Kkc+l4YNYm6DQNfc/fheFNdHHN8+UsPJQ+zy7ZNvWSQKUrVzDWiEuELNkvrODsxqXngbLyJo X-Gm-Message-State: AOJu0Yw9LqLxz2481Fd6sQj++nuruVL1A/1XMxGHz+mXiKw3iNOc+dXU rg7mqeE/wQ1o6jXpTFaZrdXqONROG8GzN/mvMUmgvER0ztcF+Lg03+JuqLylgw== X-Google-Smtp-Source: AGHT+IE9mRUEWdSZz44bRNA1IsxkpeUvPxhXUID/IQ/pKL+AsxBfad4S7Hi4SBlwuRZq8RScQNUZsw== X-Received: by 2002:a05:6a20:9d92:b0:1c6:9fe9:c425 with SMTP id adf61e73a8af0-1c9050534fdmr13069748637.45.1724107125678; Mon, 19 Aug 2024 15:38:45 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7127aef410esm7052463b3a.113.2024.08.19.15.38.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:45 -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 v3 04/17] usb: typec: Add device managed typec_mux_register() Date: Mon, 19 Aug 2024 15:38:18 -0700 Message-ID: <20240819223834.2049862-5-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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_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 | 37 +++++++++++++++++++++++++++++++++++ include/linux/usb/typec_mux.h | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 49926d6e72c7..65c60eb56428 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -457,6 +457,43 @@ void typec_mux_unregister(struct typec_mux_dev *mux_dev) } EXPORT_SYMBOL_GPL(typec_mux_unregister); +static void devm_typec_mux_unregister(struct device *dev, void *mux_dev) +{ + typec_mux_unregister(*(struct typec_mux_dev **)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, else an error pointer. + */ +struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc *desc) +{ + struct typec_mux_dev **ptr, *mux_dev; + + ptr = devres_alloc(devm_typec_mux_unregister, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + mux_dev = typec_mux_register(parent ,desc); + if (!IS_ERR(mux_dev)) { + *ptr = mux_dev; + devres_add(parent, ptr); + } else { + devres_free(ptr); + } + + 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 094585205264..c6f49756530d 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -98,6 +98,8 @@ int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state); struct typec_mux_dev * typec_mux_register(struct device *parent, const struct typec_mux_desc *desc); +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); void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data); @@ -122,6 +124,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) {} static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data) {}