From nobody Fri Sep 20 13:32:02 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 971ECCA0FFB for ; Fri, 1 Sep 2023 23:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351380AbjIAXoT (ORCPT ); Fri, 1 Sep 2023 19:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351331AbjIAXoH (ORCPT ); Fri, 1 Sep 2023 19:44:07 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D927C1710 for ; Fri, 1 Sep 2023 16:43:31 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-34df502d238so8638525ab.0 for ; Fri, 01 Sep 2023 16:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693611773; x=1694216573; 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=pzZMfYrc4MS7Ddrskta252Gk/vbJZVRLTsLEIZtE5Vw=; b=FN5js8Si5UfNhghP9yH/+SW5UzMm8bitbD1a4lDJppllxdRKO8GAmxnc7HpCMK25O1 7ltQ2vY056qt4ru2BRxicNzxJq4AQX0SXZELXgL6RfyqBx+t/zT6I2X8wykNX8LhzTTT KwD4MLzAgaj5J7FnsR1OlERDj/rNH+4BcGIx8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693611773; x=1694216573; 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=pzZMfYrc4MS7Ddrskta252Gk/vbJZVRLTsLEIZtE5Vw=; b=P3zVNp/DlHFwh3HlNIzyUPTfTdUrSm0aZ/4zXrlFFdLWKcJ1LC1O8KC+BV+GyS81aS XRW0y0mIhMr0CF6rusLrszdV++ACRjxKPEhgixUgq4OtrpbQj5yi+jLZAGxQo8n17Bp+ +fL8Fi2AX98nSVI1v4lRaW++eQxmm8mNa9WFxLQ0cKwoQ7JYvh3ip5Axjqsg1/E1EQ0p HrPOjSFixlU59iBVJcURGKlLzJqtvOlk4bBRID16b88nSIvWgRRNZAadz33dZLPIYsv5 +U1/JOo7REp5TaoPoVrD/Xu6SogGPTrYYdN4LFKIJ9HaY/WKwZ/8LagqOAdwIbFSkQJy WS6g== X-Gm-Message-State: AOJu0YyWpKu3+5CotGmXCnbTC+ulmWIikNSydbKTBfbXtrpoVgJh/ZqD EbmWrm9rRyzn6FekE6LdXKqX2w== X-Google-Smtp-Source: AGHT+IFvdRCJwMr99Yb1JrwpTHYD/RaTUnsuipwnbiYPCDCcEBVC17WQxgviFC4gHISPtQjZ2Wly3g== X-Received: by 2002:a05:6e02:1a21:b0:348:fe3b:c8b with SMTP id g1-20020a056e021a2100b00348fe3b0c8bmr5295836ile.1.1693611773002; Fri, 01 Sep 2023 16:42:53 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:8d94:1fc5:803c:41cc]) by smtp.gmail.com with ESMTPSA id o9-20020a639a09000000b0056c3a4a3ca5sm3326390pge.36.2023.09.01.16.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:42:52 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org, Maxime Ripard Cc: Douglas Anderson , Sascha Hauer , airlied@gmail.com, daniel@ffwll.ch, festevam@gmail.com, kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, p.zabel@pengutronix.de, shawnguo@kernel.org Subject: [RFT PATCH 13/15] drm/imx/ipuv3: Call drm_atomic_helper_shutdown() at shutdown/unbind time Date: Fri, 1 Sep 2023 16:41:24 -0700 Message-ID: <20230901164111.RFT.13.I0a9940ff6f387d6acf4e71d8c7dbaff8c42e3aaa@changeid> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230901234202.566951-1-dianders@chromium.org> References: <20230901234202.566951-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Based on grepping through the source code this driver appears to be missing a call to drm_atomic_helper_shutdown() at system shutdown time and at driver unbind time. Among other things, this means that if a panel is in use that it won't be cleanly powered off at system shutdown time. The fact that we should call drm_atomic_helper_shutdown() in the case of OS shutdown/restart and at driver remove (or unbind) time comes straight out of the kernel doc "driver instance overview" in drm_drv.c. A few notes about this fix: - When adding drm_atomic_helper_shutdown() to the unbind path, I added it after drm_kms_helper_poll_fini() since that's when other drivers seemed to have it. - Technically with a previous patch, ("drm/atomic-helper: drm_atomic_helper_shutdown(NULL) should be a noop"), we don't actually need to check to see if our "drm" pointer is NULL before calling drm_atomic_helper_shutdown(). We'll leave the "if" test in, though, so that this patch can land without any dependencies. It could potentially be removed later. - This patch also makes sure to set the drvdata to NULL in the case of bind errors to make sure that shutdown can't access freed data. Suggested-by: Maxime Ripard Signed-off-by: Douglas Anderson Reviewed-by: Maxime Ripard Tested-by: Philipp Zabel --- This commit is only compile-time tested. drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c b/drivers/gpu/drm/imx= /ipuv3/imx-drm-core.c index 4a866ac60fff..4c8bc49758a7 100644 --- a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +++ b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c @@ -257,6 +257,7 @@ static int imx_drm_bind(struct device *dev) drm_kms_helper_poll_fini(drm); component_unbind_all(drm->dev, drm); err_kms: + dev_set_drvdata(dev, NULL); drm_dev_put(drm); =20 return ret; @@ -269,6 +270,7 @@ static void imx_drm_unbind(struct device *dev) drm_dev_unregister(drm); =20 drm_kms_helper_poll_fini(drm); + drm_atomic_helper_shutdown(drm); =20 component_unbind_all(drm->dev, drm); =20 @@ -298,6 +300,14 @@ static int imx_drm_platform_remove(struct platform_dev= ice *pdev) return 0; } =20 +static void imx_drm_platform_shutdown(struct platform_device *pdev) +{ + struct drm_device *drm =3D platform_get_drvdata(pdev); + + if (drm) + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + #ifdef CONFIG_PM_SLEEP static int imx_drm_suspend(struct device *dev) { @@ -325,6 +335,7 @@ MODULE_DEVICE_TABLE(of, imx_drm_dt_ids); static struct platform_driver imx_drm_pdrv =3D { .probe =3D imx_drm_platform_probe, .remove =3D imx_drm_platform_remove, + .shutdown =3D imx_drm_platform_shutdown, .driver =3D { .name =3D "imx-drm", .pm =3D &imx_drm_pm_ops, --=20 2.42.0.283.g2d96d420d3-goog