From patchwork Wed May 30 00:42:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haneen Mohammed X-Patchwork-Id: 10437791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 34A4D602BD for ; Wed, 30 May 2018 07:23:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A7AB28878 for ; Wed, 30 May 2018 07:23:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E99F28891; Wed, 30 May 2018 07:23:10 +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, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, 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 A710C28878 for ; Wed, 30 May 2018 07:23:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B842172E7C; Wed, 30 May 2018 07:23:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 832866EFC6 for ; Wed, 30 May 2018 00:43:11 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id i12-v6so27766529wrc.4 for ; Tue, 29 May 2018 17:43:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=HjOmy5BgKL3xSBIeI0O/7C2y8AxM3h0BUCXZxj8A0Js=; b=GOURpEc/ovPeWcYaVzKrb5FAZOHveS/ndvmYWDB2Ia9D6JuVf9r24RngtHRQCXU/UP a0k05ZSdcWtmAj1LqxrHJ7SGh/yN7+DplfloWhymHOJsA2Hod+zSYH6aJui8OwbXxLfE WV8hXviGHKaVwFYO+TVafgzE3j6g5hSfXdElF/H58Vxy5EzUskJDEOnJwV/3FUC3iRi3 mnQ+e5cr3qZMjDmPsFaWt+0u2mNpeirqhF/h9I1qHa/V6SHuJ7qiWJmDklnpuOPB/6Eq eoj9ZTJn/PMgBMM3hdqgFk7a8/I8dIva8+zGHJMpjX/3Uj1Xjt3tFGOhlek5dzas6wso lT8w== X-Gm-Message-State: ALKqPwfm1SYpp82jn2UoYOccz5LWOwDGsYvniolPjKeS3uZzODGrx2Oj 2oB2M/zJTem8eClHX6p69URAl7gw X-Google-Smtp-Source: ADUXVKIF7ZMcaaGGwv3gnZDYL09CsTQCA4XUyh/WRua0FEfb6wD4JCqkeE9fIr2WFtD+qQLRr/PEbg== X-Received: by 2002:adf:ae59:: with SMTP id u25-v6mr370622wrd.157.1527640989675; Tue, 29 May 2018 17:43:09 -0700 (PDT) Received: from haneen-vb ([176.45.235.105]) by smtp.gmail.com with ESMTPSA id 44-v6sm79223694wrv.47.2018.05.29.17.43.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 17:43:08 -0700 (PDT) Date: Wed, 30 May 2018 03:42:59 +0300 From: Haneen Mohammed To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm: Add checks for NULL drm_*_helper_funcs Message-ID: <20180530004259.GA7981@haneen-vb> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Mailman-Approved-At: Wed, 30 May 2018 07:23:03 +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: Rodrigo Siqueira , David Airlie , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch add checks for NULL drm_[connector/crtc/plane]_helper_funcs pointers before derefrencing the variable to avoid NULL pointer dereference and make the helper functions optional in the following cases: 1) when using drm_helper_probe_single_connector_modes for fill_modes callback in the drm_connector_funcs. 2) using drm_atomic_helper_[check/commit] for atomic_[check/commit] callbacks in the drm_mode_config_funcs. The dependency is as follow: drm_connector_funcs: * fill_modes = drm_helper_probe_single_connector_modes b) drm_helper_probe_detect -> drm_connector_helper_funcs drm_mode_config_funcs: * atomic_check = drm_atomic_helper_check a) drm_atomic_helper_check_modeset -> drm_connector helper_funcs a) handle_conflicting_encoders -> drm_connector_helper_funcs b) mode_fixup -> drm_crtc_helper_funcs c) update_connector_routing -> drm_connectot_helper_funcs * atomic_commit = drm_atomic_helper_commit a) drm_atomic_helper_prepare_planes -> drm_plane_helper_funcs b) drm_atomic_helper_cleanup_planes -> drm_plane_helper_funcs Signed-off-by: Haneen Mohammed --- Chanes in v2: - add the least amount of checks to make the helpers optional for vkms drivers/gpu/drm/drm_atomic_helper.c | 16 ++++++++-------- drivers/gpu/drm/drm_probe_helper.c | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 2a7ceca82b9e..ff3684c4a83c 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -112,9 +112,9 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state, if (!new_conn_state->crtc) continue; - if (funcs->atomic_best_encoder) + if (funcs && funcs->atomic_best_encoder) new_encoder = funcs->atomic_best_encoder(connector, new_conn_state); - else if (funcs->best_encoder) + else if (funcs && funcs->best_encoder) new_encoder = funcs->best_encoder(connector); else new_encoder = drm_atomic_helper_best_encoder(connector); @@ -308,10 +308,10 @@ update_connector_routing(struct drm_atomic_state *state, funcs = connector->helper_private; - if (funcs->atomic_best_encoder) + if (funcs && funcs->atomic_best_encoder) new_encoder = funcs->atomic_best_encoder(connector, new_connector_state); - else if (funcs->best_encoder) + else if (funcs && funcs->best_encoder) new_encoder = funcs->best_encoder(connector); else new_encoder = drm_atomic_helper_best_encoder(connector); @@ -438,7 +438,7 @@ mode_fixup(struct drm_atomic_state *state) continue; funcs = crtc->helper_private; - if (!funcs->mode_fixup) + if (!funcs || !funcs->mode_fixup) continue; ret = funcs->mode_fixup(crtc, &new_crtc_state->mode, @@ -639,7 +639,7 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, new_crtc_state->connectors_changed = true; } - if (funcs->atomic_check) + if (funcs && funcs->atomic_check) ret = funcs->atomic_check(connector, new_connector_state); if (ret) return ret; @@ -2117,7 +2117,7 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev, funcs = plane->helper_private; - if (funcs->prepare_fb) { + if (funcs && funcs->prepare_fb) { ret = funcs->prepare_fb(plane, new_plane_state); if (ret) goto fail; @@ -2412,7 +2412,7 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev, funcs = plane->helper_private; - if (funcs->cleanup_fb) + if (funcs && funcs->cleanup_fb) funcs->cleanup_fb(plane, plane_state); } } diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c index 527743394150..2fea54d16ebb 100644 --- a/drivers/gpu/drm/drm_probe_helper.c +++ b/drivers/gpu/drm/drm_probe_helper.c @@ -320,7 +320,7 @@ drm_helper_probe_detect(struct drm_connector *connector, if (ret) return ret; - if (funcs->detect_ctx) + if (funcs && funcs->detect_ctx) return funcs->detect_ctx(connector, ctx, force); else if (connector->funcs->detect) return connector->funcs->detect(connector, force); @@ -480,7 +480,8 @@ int drm_helper_probe_single_connector_modes(struct drm_connector *connector, goto prune; } - count = (*connector_funcs->get_modes)(connector); + if (connector_funcs && connector_funcs->get_modes) + count = (*connector_funcs->get_modes)(connector); if (count == 0 && connector->status == connector_status_connected) count = drm_add_modes_noedid(connector, 1024, 768);