Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7123574rdb; Wed, 3 Jan 2024 05:33:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRv23rSqm8fXG7egEs7GSP3t+8CzQ+/6rYcZCY0BlKOScDEkYkxcOlzQqocbtD2uXJvcoc X-Received: by 2002:a17:90a:b102:b0:28b:bc1f:6671 with SMTP id z2-20020a17090ab10200b0028bbc1f6671mr6557112pjq.80.1704288781061; Wed, 03 Jan 2024 05:33:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704288781; cv=none; d=google.com; s=arc-20160816; b=yipcmQYjkLO5/PNGpEGJ95uyp+ismOKbX4w7MH1iUoXWMVgpyyXq+kB1RpvNVIrCIi 50tZNlbcDcqC+QzS4GPFB4peZ9WdgAl/WLlmPJMrceAS0JnTx18VUJKXbLRgD56eutts CSGN4UicRM+bHu55kyxC+KKuBF/oPC0Ml3WznjE8aynAE1l+GAMGrNied8rVTyvGNbag rtc6ZLG0yaUDBd43guXdo3we1W+n416w6VxXve5OEqeuaNHkOs5+5hwhLrMNeqG0QiQZ akW3kkBprrfYSGWoXBqM/CTZETjHm1i4E/DqxFJiTgCyQHyYR+SAjdVqP53IeyBmiMCK uSuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=wEkd5k8GQrLcu7ZFnX9UIXfSY5JciQcBQpfvUhcPgy8=; fh=J0s/Ne42feNV7+bQc6NAkuwQ3NU+6eXy49Su1M/5CR8=; b=gLQPOFQsu5uVBuwjN8cJW+HqmHJfHPn9CWrqlM8LB8PYSnvD0Zetv8WARrQoOqfzSG q+l7L0/OA716mGDUwbfyS6ZaKkR2q6yEwUinOLKXB3uNd21ixiqIuC2Rlg2fA05NN4Do 2KYRz+9Dze89WSzNeKQ1i4C9hN4rKGIgNr3yOi/Q+SgyY+sBTBPjVrwT5Uj9cJQ+nzBN HiVT4xwgDuTt4s1ce29WfGl0rWfuGe+PyHQBlS1rtbpEJV6cepldA5n2T2DeD+uqv0jv 1CZ/fTvEGCyTqYRREjtZSP/LnVx7GLuH/nBF/ffX8UjqxKpasENZOgFrPKBFZPTzHpOJ xNSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Bx3sEDe1; spf=pass (google.com: domain of linux-kernel+bounces-15582-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15582-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n12-20020a17090a9f0c00b00279020d1fb0si1187556pjp.129.2024.01.03.05.33.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 05:33:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15582-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Bx3sEDe1; spf=pass (google.com: domain of linux-kernel+bounces-15582-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15582-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A4A93285FC4 for ; Wed, 3 Jan 2024 13:33:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9DDA119BD9; Wed, 3 Jan 2024 13:32:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Bx3sEDe1" X-Original-To: linux-kernel@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BFA6199A2 for ; Wed, 3 Jan 2024 13:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-158-149-209.elisa-laajakaista.fi [91.158.149.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3B1BC13AC; Wed, 3 Jan 2024 14:30:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1704288657; bh=iMFg46C9AVK+gqtNslZ2al4rP2jrirD8l6lsmVVtiyk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Bx3sEDe1ZUi988Lh97lIJyub8NL9Km5Rk62w+TLK3NOy3nqvj2iGdyzvZ7uoq3Mfg wAWiQ8pca3QDlxttaZabiuiu5cuexa8w/PPu0Lbun3ODKz8jtArTh321vykOCdfHmD 2SnXxuPyxDgh+Kqfgm7TftNwkHOmGyejgyNbX8MU= From: Tomi Valkeinen Date: Wed, 03 Jan 2024 15:31:07 +0200 Subject: [PATCH 1/2] drm/bridge: sii902x: Fix probing race issue Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240103-si902x-fixes-v1-1-b9fd3e448411@ideasonboard.com> References: <20240103-si902x-fixes-v1-0-b9fd3e448411@ideasonboard.com> In-Reply-To: <20240103-si902x-fixes-v1-0-b9fd3e448411@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Boris Brezillon , Peter Rosin , Linus Walleij , Fabrizio Castro , Jyri Sarha Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Nishanth Menon , Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=4397; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=iMFg46C9AVK+gqtNslZ2al4rP2jrirD8l6lsmVVtiyk=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBllWHJ48014vEMwPWbraxNYKyeSnFgAcEdghFPm cFM3olcS4uJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZZVhyQAKCRD6PaqMvJYe 9Y3qD/0Zvilv3i8x82Qg+42RLBewo/CU/NSBWfwXkwtyIaXR+7gDxHg2RNtTiT8XaXQm3ZKw7Ry EBo+kfQZUzf2tNeyrt+zZxkqSgKBNLt12aiVC2c6N70mspTJYwFCsCzpVwyaHao3PJSRW36B2DR CEoHVt0T6pcbQ739umy7OxzMtwCZoGGpgfgj360MHmsfgJ7yitRLEhw3kPm+SI96mTK0Ga1GI52 4SBR4XKzg7lhqnvORBj6GY0nKJ068p8tqKqfbOPkTLVpSY51Xq2tU0EsufRpPm7u3ONVTDrt6/0 cxgtNf0HCOXlBcHvgnImUFxYjk8h9Gw+Ing/zNNyPLxFuMkxYdaHuSuYNW4B/RuW6XBM6ks2om2 DCVG9F5i8DvQCQshxRTY0zugyPROgCSwGLNQkJb5chFYlDGKXp7m4V8+cI7KFQnmjRCxofXbddd oDLspl3GUElVQaoNUF1ao/4faJBACMINBqwIATOVz/azpmUAy0lgqSiEBneDN3nxe3PRfB0R5QD NbASLd920v4buPKhMh9Bh2hwISPijaRkDYcjxKOyVI6OhAgHULE0uy5aguGNCkyW2sFHzB36uni pN/fG2G3TKuq9iq1zu8y1mZylLNA/E1D7Kz1MlwR8CTkiaw0e4I6ICUalAIwMcJpy4Wn1sY7rxv Idxcg4ks24HPrpA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 A null pointer dereference crash has been observed rarely on TI platforms using sii9022 bridge: [ 53.271356] sii902x_get_edid+0x34/0x70 [sii902x] [ 53.276066] sii902x_bridge_get_edid+0x14/0x20 [sii902x] [ 53.281381] drm_bridge_get_edid+0x20/0x34 [drm] [ 53.286305] drm_bridge_connector_get_modes+0x8c/0xcc [drm_kms_helper] [ 53.292955] drm_helper_probe_single_connector_modes+0x190/0x538 [drm_kms_helper] [ 53.300510] drm_client_modeset_probe+0x1f0/0xbd4 [drm] [ 53.305958] __drm_fb_helper_initial_config_and_unlock+0x50/0x510 [drm_kms_helper] [ 53.313611] drm_fb_helper_initial_config+0x48/0x58 [drm_kms_helper] [ 53.320039] drm_fbdev_dma_client_hotplug+0x84/0xd4 [drm_dma_helper] [ 53.326401] drm_client_register+0x5c/0xa0 [drm] [ 53.331216] drm_fbdev_dma_setup+0xc8/0x13c [drm_dma_helper] [ 53.336881] tidss_probe+0x128/0x264 [tidss] [ 53.341174] platform_probe+0x68/0xc4 [ 53.344841] really_probe+0x188/0x3c4 [ 53.348501] __driver_probe_device+0x7c/0x16c [ 53.352854] driver_probe_device+0x3c/0x10c [ 53.357033] __device_attach_driver+0xbc/0x158 [ 53.361472] bus_for_each_drv+0x88/0xe8 [ 53.365303] __device_attach+0xa0/0x1b4 [ 53.369135] device_initial_probe+0x14/0x20 [ 53.373314] bus_probe_device+0xb0/0xb4 [ 53.377145] deferred_probe_work_func+0xcc/0x124 [ 53.381757] process_one_work+0x1f0/0x518 [ 53.385770] worker_thread+0x1e8/0x3dc [ 53.389519] kthread+0x11c/0x120 [ 53.392750] ret_from_fork+0x10/0x20 The issue here is as follows: - tidss probes, but is deferred as sii902x is still missing. - sii902x starts probing and enters sii902x_init(). - sii902x calls drm_bridge_add(). Now the sii902x bridge is ready from DRM's perspective. - sii902x calls sii902x_audio_codec_init() and platform_device_register_data() - The registration of the audio platform device causes probing of the deferred devices. - tidss probes, which eventually causes sii902x_bridge_get_edid() to be called. - sii902x_bridge_get_edid() tries to use the i2c to read the edid. However, the sii902x driver has not set up the i2c part yet, leading to the crash. Fix this by moving the drm_bridge_add() to the end of the sii902x_init(), which is also at the very end of sii902x_probe(). Signed-off-by: Tomi Valkeinen Fixes: 21d808405fe4 ("drm/bridge/sii902x: Fix EDID readback") --- drivers/gpu/drm/bridge/sii902x.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/bridge/sii902x.c b/drivers/gpu/drm/bridge/sii902x.c index 2bdc5b439beb..69da73e414a9 100644 --- a/drivers/gpu/drm/bridge/sii902x.c +++ b/drivers/gpu/drm/bridge/sii902x.c @@ -1080,16 +1080,6 @@ static int sii902x_init(struct sii902x *sii902x) return ret; } - sii902x->bridge.funcs = &sii902x_bridge_funcs; - sii902x->bridge.of_node = dev->of_node; - sii902x->bridge.timings = &default_sii902x_timings; - sii902x->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID; - - if (sii902x->i2c->irq > 0) - sii902x->bridge.ops |= DRM_BRIDGE_OP_HPD; - - drm_bridge_add(&sii902x->bridge); - sii902x_audio_codec_init(sii902x, dev); i2c_set_clientdata(sii902x->i2c, sii902x); @@ -1102,7 +1092,21 @@ static int sii902x_init(struct sii902x *sii902x) return -ENOMEM; sii902x->i2cmux->priv = sii902x; - return i2c_mux_add_adapter(sii902x->i2cmux, 0, 0, 0); + ret = i2c_mux_add_adapter(sii902x->i2cmux, 0, 0, 0); + if (ret) + return ret; + + sii902x->bridge.funcs = &sii902x_bridge_funcs; + sii902x->bridge.of_node = dev->of_node; + sii902x->bridge.timings = &default_sii902x_timings; + sii902x->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID; + + if (sii902x->i2c->irq > 0) + sii902x->bridge.ops |= DRM_BRIDGE_OP_HPD; + + drm_bridge_add(&sii902x->bridge); + + return 0; } static int sii902x_probe(struct i2c_client *client) @@ -1170,12 +1174,11 @@ static int sii902x_probe(struct i2c_client *client) } static void sii902x_remove(struct i2c_client *client) - { struct sii902x *sii902x = i2c_get_clientdata(client); - i2c_mux_del_adapters(sii902x->i2cmux); drm_bridge_remove(&sii902x->bridge); + i2c_mux_del_adapters(sii902x->i2cmux); } static const struct of_device_id sii902x_dt_ids[] = { -- 2.34.1