From patchwork Thu May 31 22:10:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haneen Mohammed X-Patchwork-Id: 10442543 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 73C75603D7 for ; Fri, 1 Jun 2018 07:03:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 637B928E7F for ; Fri, 1 Jun 2018 07:03:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5811F28F42; Fri, 1 Jun 2018 07:03:29 +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 08CBE28E7F for ; Fri, 1 Jun 2018 07:03:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CEAB96E532; Fri, 1 Jun 2018 07:03:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E4F789C9C for ; Thu, 31 May 2018 22:10:36 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id x2-v6so49066465wmh.5 for ; Thu, 31 May 2018 15:10:36 -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=reIPv9A53Hh8ar/xpWuQP/kdrr9l2nDk3d8BZyT0Q58=; b=IOR9R7R+uMnQdCtDS6oYcmtWHTKf2p/emtkk0IEfjFEx/eKpQ/K3Sh4rrw/kuK3mFM gNbykK5yOl7XfSY8yzs4e5/UbiSC5W5AopSJKNhgtWb3KwoIT9Vdmy3Ho29qFA2pv2en Tg0DTLWsxtJQhBELWk1bVAOliQMmXl6TnVw30o5f8ggk0QQtKgX2Owl57YKsszocIdR/ cGHz+8emem1xYGZVyNLEZVDe0IP+tlkhTsOlv39NpbxbEQiYRKp5L682hfjQItWBlt60 /Tp7S6FrS0qUUyVQsvpHCJO5rRxcBEuN237PmDwCENoYmxQkKgvfzF4mc1OxcOciMSkv nCGA== X-Gm-Message-State: APt69E19m+3nzAT83j0RrL3dcfY6xruHtb1Q5oxAGUjK51IR0hN8AL+D V/5GVk9nsBh1KGFgNr5h7qONFiOK X-Google-Smtp-Source: ADUXVKKic4tpo6a+nDpEMHEfiPinEksEGcUctcE+eBlinZpdBv0/oaF47t5Om0GCO2txSOwFOdLNag== X-Received: by 2002:a1c:4a5d:: with SMTP id x90-v6mr945799wma.67.1527804634333; Thu, 31 May 2018 15:10:34 -0700 (PDT) Received: from haneen-vb ([188.50.43.173]) by smtp.gmail.com with ESMTPSA id n11-v6sm3228462wro.13.2018.05.31.15.10.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 May 2018 15:10:33 -0700 (PDT) Date: Fri, 1 Jun 2018 01:10:24 +0300 From: Haneen Mohammed To: dri-devel@lists.freedesktop.org Subject: [PATCH v3] drm: Add checks for NULL drm_connector_helper_funcs Message-ID: <20180531221024.GA8016@haneen-vb> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Mailman-Approved-At: Fri, 01 Jun 2018 07:03:19 +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: rodrigosiqueiramelo@gmail.com, David Airlie , daniel.vetter@ffwll.ch 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_helper_funcs pointers before derefrencing the variable to avoid NULL pointer dereference and make the helper function 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 for atomic_check 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_mode_config_func: * atomic_check = drm_atomic_helper_check a) drm_atomic_helper_check_modeset a) handle_conflicting_encoders c) update_connector_routing Signed-off-by: Haneen Mohammed --- Changes in v3: - add checks for drm_connector_helper_funcs only since plane/crtc helper funcs are necessary for a functional driver Changes in v2: - add the least amount of checks to make the helpers optional for vkms drivers/gpu/drm/drm_atomic_helper.c | 10 +++++----- drivers/gpu/drm/drm_probe_helper.c | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 2a7ceca82b9e..065e7fe1f979 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); @@ -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; 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);