From patchwork Tue Aug 13 09:30:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 11095249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAD671398 for ; Thu, 15 Aug 2019 08:36:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 985AA2811A for ; Thu, 15 Aug 2019 08:36:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C5EF28842; Thu, 15 Aug 2019 08:36:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D04E2811A for ; Thu, 15 Aug 2019 08:36:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DB3F6E904; Thu, 15 Aug 2019 08:35:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 301 seconds by postgrey-1.36 at gabe; Tue, 13 Aug 2019 09:35:57 UTC Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 72EDB6E0D2 for ; Tue, 13 Aug 2019 09:35:57 +0000 (UTC) Received: from ramsan ([84.194.98.4]) by michel.telenet-ops.be with bizsmtp id oZWn2000Y05gfCL06ZWnvJ; Tue, 13 Aug 2019 11:30:54 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1hxT8h-0001Ef-Ny; Tue, 13 Aug 2019 11:30:47 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1hxT8h-0001Iz-KD; Tue, 13 Aug 2019 11:30:47 +0200 From: Geert Uytterhoeven To: Andrzej Pietrasiewicz , Neil Armstrong , Andrzej Hajda Subject: [PATCH] drm/bridge: dumb-vga-dac: Fix dereferencing -ENODEV DDC channel Date: Tue, 13 Aug 2019 11:30:46 +0200 Message-Id: <20190813093046.4976-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 X-Mailman-Approved-At: Thu, 15 Aug 2019 08:34:55 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jernej Skrabec , Geert Uytterhoeven , Jonas Karlman , David Airlie , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-renesas-soc@vger.kernel.org, Laurent Pinchart , Sam Ravnborg , Guenter Roeck , Emil Velikov MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP If the VGA connector has no DDC channel, an error pointer will be dereferenced, e.g. on Salvator-XS: Unable to handle kernel NULL pointer dereference at virtual address 000000000000017d ... Call trace: sysfs_do_create_link_sd.isra.0+0x40/0x108 sysfs_create_link+0x20/0x40 drm_sysfs_connector_add+0xa8/0xc8 drm_connector_register.part.3+0x54/0xb0 drm_connector_register_all+0xb0/0xd0 drm_modeset_register_all+0x54/0x88 drm_dev_register+0x18c/0x1d8 rcar_du_probe+0xe4/0x150 ... This happens because vga->ddc either contains a valid DDC channel pointer, or -ENODEV, and drm_connector_init_with_ddc() expects a valid DDC channel pointer, or NULL. Fix this by resetting vga->ddc to NULL in case of -ENODEV, and replacing the existing error checks by non-NULL checks. This is similar to what the HDMI connector driver does. Fixes: a4f9087e85de141e ("drm/bridge: dumb-vga-dac: Provide ddc symlink in connector sysfs directory") Signed-off-by: Geert Uytterhoeven Tested-by: Guenter Roeck --- An alternative would be to check if vga->ddc contains an error pointer, and calling drm_connector_init() instead of drm_connector_init_with_ddc(), like before. --- drivers/gpu/drm/bridge/dumb-vga-dac.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/dumb-vga-dac.c b/drivers/gpu/drm/bridge/dumb-vga-dac.c index 8ef6539ae78a6eb3..7aa789c358829b05 100644 --- a/drivers/gpu/drm/bridge/dumb-vga-dac.c +++ b/drivers/gpu/drm/bridge/dumb-vga-dac.c @@ -42,7 +42,7 @@ static int dumb_vga_get_modes(struct drm_connector *connector) struct edid *edid; int ret; - if (IS_ERR(vga->ddc)) + if (!vga->ddc) goto fallback; edid = drm_get_edid(connector, vga->ddc); @@ -84,7 +84,7 @@ dumb_vga_connector_detect(struct drm_connector *connector, bool force) * wire the DDC pins, or the I2C bus might not be working at * all. */ - if (!IS_ERR(vga->ddc) && drm_probe_ddc(vga->ddc)) + if (vga->ddc && drm_probe_ddc(vga->ddc)) return connector_status_connected; return connector_status_unknown; @@ -197,6 +197,7 @@ static int dumb_vga_probe(struct platform_device *pdev) if (PTR_ERR(vga->ddc) == -ENODEV) { dev_dbg(&pdev->dev, "No i2c bus specified. Disabling EDID readout\n"); + vga->ddc = NULL; } else { dev_err(&pdev->dev, "Couldn't retrieve i2c bus\n"); return PTR_ERR(vga->ddc); @@ -218,7 +219,7 @@ static int dumb_vga_remove(struct platform_device *pdev) drm_bridge_remove(&vga->bridge); - if (!IS_ERR(vga->ddc)) + if (vga->ddc) i2c_put_adapter(vga->ddc); return 0;