Received: by 2002:a19:651b:0:0:0:0:0 with SMTP id z27csp5083834lfb; Tue, 10 May 2022 22:15:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyswYwgaetNJgAsyeAR8fGmzMtoUQGlYpO3jv/Mu13rp4IbgVBxKG1fT3gVVRYmIz50YxWi X-Received: by 2002:a05:6a00:1943:b0:4cb:79c9:fa48 with SMTP id s3-20020a056a00194300b004cb79c9fa48mr23577999pfk.47.1652246157989; Tue, 10 May 2022 22:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652246157; cv=none; d=google.com; s=arc-20160816; b=SLCTBuHsGSy8oEzTQEGZm0NIB7EcCibaOgWnK8uhzV7/KPBwQGIW03FoXk7kGb4HJK /Sag9Zta84LR7EznNnDd0XLnE/xocHSRHUpug/zSe2uY8A345iUB2JM2JawkbWf3vJjl eQPTTXBDb67cK1f2RHCmEOXOnQ+fgL1Ele+iuT/xlgpTvIy9yGwRyxTKv5Otoflb2V8C TKUwj02bsXt2eGcIRcZCRwQmahgDQqMhJ1AtBRRanduI6cdIb15bhbYkNoyppWSU7bbJ RDBrbaUcOhK/8gBUgh0GKookj9ZJ1MuZCmcStKpmTENz+UiZrTzVmy3RKVbcBAOMcxsn ezxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=spc3e6Lp3Smlzf38aH5fCH48i9kTiBR8/UYKG1CLueQ=; b=HW+h5KWye7033dCbwSSYu1fM1QSqH6/7KyCsJoEoUz9flET8hKVYjxaG9i3iiRsVEl Sb42f6jnulKUuRPEhyVsfz6a6J8r50ujs6JnCZF6DnU8YKxqkF0HSM6co+Ost7GvtHmF KYXUOtkhHZc/lNn8nTzJk0ddHFmzwhFobnJomo55t43xrYzl3i1FRqtDZZL1p7K+CIKy 9YrUC2ksgEe9ZpyH91eWLgEwqkKmkrjT+7te361lyfQuuk4GkP3syVJYr2bK3sStzFWd j3zCLOczqG1v3GSAOdS2ZkT2P2M7WfYAXn8wol9DNtP7nUFAhn2g7i64CHy0LOcigcu9 0png== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cz0Xr0eL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t11-20020a170902bc4b00b0015d391dab50si1220385plz.153.2022.05.10.22.15.44; Tue, 10 May 2022 22:15:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cz0Xr0eL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233223AbiEJTaO (ORCPT + 99 others); Tue, 10 May 2022 15:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233738AbiEJTaH (ORCPT ); Tue, 10 May 2022 15:30:07 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7116B2A2F68 for ; Tue, 10 May 2022 12:30:02 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id cx11-20020a17090afd8b00b001d9fe5965b3so2817949pjb.3 for ; Tue, 10 May 2022 12:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=spc3e6Lp3Smlzf38aH5fCH48i9kTiBR8/UYKG1CLueQ=; b=cz0Xr0eL1ajvZSsgLbzZbq39CiowXavZ6oKFanIVRSuNSdPrMxAI9a+lUYIybRRI8Z l9f9QgXxhrErMb0+Rw3GcIBYoSBZvvHafQIs7JEGkOMAMdASorM5GZlqQ/R8kl67yLk+ MbgQgs1sU2wNKMz62e7ITFkvv7ogeaeVCTLPs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=spc3e6Lp3Smlzf38aH5fCH48i9kTiBR8/UYKG1CLueQ=; b=UDXah5T632zXw6bxYBXGavK7+WV1tvP7X0Lmgc4ao+/kL71NTpBTfxT26jWt3Heur+ e5Iy0s1xN3dE19FUvx5xfPgX3DJvRD24i+KJbcrEgonGgdS4ES/+xeTbOOTgSHHGcEOO 4FwHGCK0fpzgzLiEMSjwKkN2cZIaaqfo8laxzKTGzaIXiiexYtph9XNm75ULkDT7y0DM n1y5iqblHv22n3fALqhjQvQee9oXC+f8qZUFC8jxI/lcLAo5tEM+Iraw13pUXGxmlDvT H8ktiuMz/cE2lL/0LX6DWP533ob82XGQP9DOQxMbP0m2C37EHCq4eGx0yCbrmBTsxx9b 2+zQ== X-Gm-Message-State: AOAM532/lXOaPO8j7QM8AjRDrJwjXk099IpKHvwrQpWggs7ynmxN4jvp GmUtXrWEQ3goa2Z/N/lLGtDALQ== X-Received: by 2002:a17:90b:1001:b0:1d8:4978:c7d5 with SMTP id gm1-20020a17090b100100b001d84978c7d5mr1405066pjb.167.1652211001798; Tue, 10 May 2022 12:30:01 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:201:6f08:624c:c762:d238]) by smtp.gmail.com with ESMTPSA id s43-20020a056a001c6b00b0050dc762819dsm10786989pfw.119.2022.05.10.12.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 12:30:01 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Cc: Hsin-Yi Wang , Abhinav Kumar , Philip Chen , Sankeerth Billakanti , Robert Foss , freedreno@lists.freedesktop.org, Dmitry Baryshkov , linux-arm-msm@vger.kernel.org, Stephen Boyd , Douglas Anderson , Daniel Vetter , David Airlie , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] drm/bridge: Add devm_drm_bridge_add() Date: Tue, 10 May 2022 12:29:43 -0700 Message-Id: <20220510122726.v3.3.Iba4b9bf6c7a1ee5ea2835ad7bd5eaf84d7688520@changeid> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog In-Reply-To: <20220510192944.2408515-1-dianders@chromium.org> References: <20220510192944.2408515-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds a devm managed version of drm_bridge_add(). Like other "devm" function listed in drm_bridge.h, this function takes an explicit "dev" to use for the lifetime management. A few notes: * In general we have a "struct device" for bridges that makes a good candidate for where the lifetime matches exactly what we want. * The "bridge->dev->dev" device appears to be the encoder device. That's not the right device to use for lifetime management. Suggested-by: Dmitry Baryshkov Signed-off-by: Douglas Anderson --- Changes in v3: - Patch ("drm/bridge: Add devm_drm_bridge_add()") new for v3. drivers/gpu/drm/drm_bridge.c | 23 +++++++++++++++++++++++ include/drm/drm_bridge.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index c96847fc0ebc..e275b4ca344b 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -170,6 +170,29 @@ void drm_bridge_add(struct drm_bridge *bridge) } EXPORT_SYMBOL(drm_bridge_add); +static void drm_bridge_remove_void(void *bridge) +{ + drm_bridge_remove(bridge); +} + +/** + * devm_drm_bridge_add - devm managed version of drm_bridge_add() + * + * @dev: device to tie the bridge lifetime to + * @bridge: bridge control structure + * + * This is the managed version of drm_bridge_add() which automatically + * calls drm_bridge_remove() when @dev is unbound. + * + * Return: 0 if no error or negative error code. + */ +int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge) +{ + drm_bridge_add(bridge); + return devm_add_action_or_reset(dev, drm_bridge_remove_void, bridge); +} +EXPORT_SYMBOL(devm_drm_bridge_add); + /** * drm_bridge_remove - remove the given bridge from the global bridge list * diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index f27b4060faa2..42aec8612f37 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -796,6 +796,7 @@ drm_priv_to_bridge(struct drm_private_obj *priv) } void drm_bridge_add(struct drm_bridge *bridge); +int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge); void drm_bridge_remove(struct drm_bridge *bridge); int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, struct drm_bridge *previous, -- 2.36.0.550.gb090851708-goog