Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp256889rwj; Sat, 29 Oct 2022 02:36:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CupY7sI0uyxZjpWZohpZ3Fm2f6vfLYzxZRi3Zu4Ek4/eJWUOL8co/Tlh6begHokl7geMZ X-Received: by 2002:a17:902:e94f:b0:17f:6df3:1a99 with SMTP id b15-20020a170902e94f00b0017f6df31a99mr3548131pll.20.1667036164787; Sat, 29 Oct 2022 02:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667036164; cv=none; d=google.com; s=arc-20160816; b=YkVDHBNCauQSDXFEtomD2F/OqU0zDRjPICbRKNF1ujr5h8C1vjmwPOP1JiGdiWqVLi HBT+VjolR3A8JvCaSVuhAqnL8CmZvb42KMjl7loQD2vvKIBQ7GJ7KgI1V5ARSHF8KRv6 wqU4XQa9TRwf7dyCyHM98DDlj2Nf8DN8O/LtnaGcWWWugOL9AAfdmYXsaGObe3DWgG/V KrR8zksPSSIWL6uqVhrY8PRAkt/VDT6npqoq24E7gKHpabrSD1jHl/Dj2kHrK2CgbZ9E JWj5Q8oJ8fYfXCjqAnJMB0F6z75fnILSP8T+zfB8AzQGPpTWuUo+uN5Wq/S5bGZ2lseG opqA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=0s7cusbjRhvfSFjBw6Lx4DFnE28qr99VM/89xctrXcY=; b=dpYDzRrqMUTdEsfeZjNmN5mkTCIguEwyD5YkNwGJmXJxpAj+Il1CrHTFdepKJxjQtN GPjtI15yCPRbKY9O0GwdlhN/k1sQFx5iQmHSl6NHou+uMAzCcCzEkNftifJ+oy/3NNeG jz386x42PsI28kUYIXAsO+yzzi9n/Pg37N8iofaI2jGBCckZkF+G6T0xWwdK8eNZdto6 9HST1/70HMSd1YPRcQGPSiTTsf9Buwf7o9eUhai0xxLrVkn8oZ2Y8XYsC5qnknLHOku8 OFE45D2Uyn+bM1bwjPSO20WKwMaNuoPxgMWoQxfnQW9zJB8bb1HBPOH9/mGebIdPVSGA r4MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R8r9MYiV; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l67-20020a633e46000000b0046ec9d03aaasi1449616pga.589.2022.10.29.02.35.53; Sat, 29 Oct 2022 02:36:04 -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=@gmail.com header.s=20210112 header.b=R8r9MYiV; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229510AbiJ2Jer (ORCPT + 99 others); Sat, 29 Oct 2022 05:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiJ2Jen (ORCPT ); Sat, 29 Oct 2022 05:34:43 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FDA117049 for ; Sat, 29 Oct 2022 02:34:39 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id v130-20020a1cac88000000b003bcde03bd44so7894208wme.5 for ; Sat, 29 Oct 2022 02:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0s7cusbjRhvfSFjBw6Lx4DFnE28qr99VM/89xctrXcY=; b=R8r9MYiVR/n1QCShgiCRjvlsyCmGxIth8d68WOBKuFwGFdpvU0hLifsKHXaA0i7R7T FATSb70x39JDuCr+RFIEMHkzCbXWDBVXLQrDeb9y7eB4/OehDirtQMwmoI+nEp+BrN0G u/fUtaHezDnpUbrRdrgmORy9rD4FhXGYMCmjG/LapRowSvd+EZrEGPnCIBo1dsmqrQzE esyFj2o/J+WqlmQTU+aoX79Wvn1x2MTGTvXbk00TQxNzSp0U4mMc+L1GZbZv4260jlSX DI4iK78azGeF6BR5yBioI4MAexmAQiV7qakqP16N3f0ibROLougrJyoyhWfCUkuqRZ00 Lydw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0s7cusbjRhvfSFjBw6Lx4DFnE28qr99VM/89xctrXcY=; b=25vfB19PYz3EZ3QYszyFKnt+t5tvUPJGoYqCdemPIHjw832vt13thOqcpS8eYvWKk3 x1X5WVWQ9rc6BtV4EEb9medZKJKewLl+DVFZ+NR4/cRQ9gTdF6DUW9BiVLaXR8/tXBn9 LjCrWnc+D1A9Nn9uhECQVHYCW1tcWfX8k85V8/noigQqYz6SlFOqXmP+G4P/Zj9yT/QK PrtRzl69qsJs/VlUf0558g796YEyQeJ9dg2Z0Tz4k/bZ2CkwnKQVUSSDlQgafoXDyVEY UixinLOt/6n/9Eot07YmFBVTXdZOqNDWjcTt90jLaBbb2Nnb6wfAgx1RflkW0B/qGM+A izkw== X-Gm-Message-State: ACrzQf1UmkKnSbYEY6DW8r//rrqOq6yADbiXX/Z2bU2no+4IY1yF5yVz pO6L2CPzenbXFZdBKnsajCc= X-Received: by 2002:a05:600c:310f:b0:3c6:ff0a:c41 with SMTP id g15-20020a05600c310f00b003c6ff0a0c41mr11820655wmo.91.1667036078032; Sat, 29 Oct 2022 02:34:38 -0700 (PDT) Received: from localhost.localdomain ([94.73.35.109]) by smtp.gmail.com with ESMTPSA id k18-20020adfe3d2000000b00236705daefesm1053785wrm.39.2022.10.29.02.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 02:34:37 -0700 (PDT) From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= To: mripard@kernel.org Cc: emma@anholt.net, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Subject: [PATCH] drm/vc4: hdmi: Fix pointer dereference before check Date: Sat, 29 Oct 2022 11:34:13 +0200 Message-Id: <20221029093413.546103-1-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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 Commit 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") introduced the vc4_hdmi_reset_link() function. This function dereferences the "connector" pointer before checking whether it is NULL or not. Rework variable assignment to avoid this issue. Fixes: 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") Signed-off-by: José Expósito --- drivers/gpu/drm/vc4/vc4_hdmi.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 4a73fafca51b..07d058b6afb7 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -319,9 +319,9 @@ static int reset_pipe(struct drm_crtc *crtc, static int vc4_hdmi_reset_link(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx) { - struct drm_device *drm = connector->dev; - struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); - struct drm_encoder *encoder = &vc4_hdmi->encoder.base; + struct drm_device *drm; + struct vc4_hdmi *vc4_hdmi; + struct drm_encoder *encoder; struct drm_connector_state *conn_state; struct drm_crtc_state *crtc_state; struct drm_crtc *crtc; @@ -332,6 +332,10 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!connector) return 0; + drm = connector->dev; + vc4_hdmi = connector_to_vc4_hdmi(connector); + encoder = &vc4_hdmi->encoder.base; + ret = drm_modeset_lock(&drm->mode_config.connection_mutex, ctx); if (ret) return ret; -- 2.25.1