From patchwork Wed Jun 19 18:19:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 11005009 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 7AB0614B6 for ; Wed, 19 Jun 2019 18:19:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64C5D2858A for ; Wed, 19 Jun 2019 18:19:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 564FC28644; Wed, 19 Jun 2019 18:19:57 +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 D8EC52858A for ; Wed, 19 Jun 2019 18:19:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 06F626E44B; Wed, 19 Jun 2019 18:19:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0CE266E44B for ; Wed, 19 Jun 2019 18:19:54 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id d17so125289qtj.8 for ; Wed, 19 Jun 2019 11:19:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8gaGsAxBQTelnZZ0SJOq1SzgW7Jm91FjOBQ5oH/bkng=; b=R2UtI7uTKxi/ysofb8rTL3N33AXChhez/JDwRki8cRtZcLXyOITBzbfSZmN8nQWNSQ FPnR1DAL0TWL3kkJRTMacHPDASTuRvOuKZxEyxBA+9fASzntGnJyddYMMFcNLEibBh5H Xfn53gAqiBBaKNTZK1Tc8wYc70DsS1X8p77dfAe2UjyNatVKKnhXo04cCw0uOeq/YPlU rlvXBYjelwvrjQEUVUYWMOFJHECFF6vUR2Ivdm5f2xyhurVgeUZYgl5lcEXvh73WCVo2 AtcXO8VBFnD1fuVpFT3LVkoBjePyeXpklpPZVR7zwd+Mdqt6NmEN2YaUU+2bWXUp6Oyk IbMw== X-Gm-Message-State: APjAAAXBNqlDpnrVBLk40nyX738ktdM5GF4B0DA1nEoD+q0oVMIMvswj q+1LLdJTQehnS5taRojjRnmzvkrYSv8= X-Google-Smtp-Source: APXvYqzo+XJsugt5hB0u6K2mTfSTR3XwF7LvyY97zejuxp7eEMEZ+G6Hf7u9GqwpgcAsC6gPW7mibQ== X-Received: by 2002:ac8:34f4:: with SMTP id x49mr97190999qtb.95.1560968392921; Wed, 19 Jun 2019 11:19:52 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id m6sm9303963qte.17.2019.06.19.11.19.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 11:19:52 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/self_refresh: Fix possible NULL deref in failure path Date: Wed, 19 Jun 2019 14:19:47 -0400 Message-Id: <20190619181951.192305-1-sean@poorly.run> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190619094151.GI18776@kadam> References: <20190619094151.GI18776@kadam> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8gaGsAxBQTelnZZ0SJOq1SzgW7Jm91FjOBQ5oH/bkng=; b=bTvrLwjKX8Q5u6oUL6C43a7jMfzK7cT7R8/DrQheDCjQyKRyxDgQ4cAeDKcozDWKWB 3o62I/GR3LjOujYbsfe6pCIH6LHAj5e+t8i0QAPjQ9s0GOGUJKxLk2Fbzn6eTTl/vdcf AlHm8RaQeLzZgP6RFFfsCO3jnGXyYUnxYKaKqBHOCvQWlqMc5OPJ8Wo2n1cCS2jb86Qs hS4IHcvmj0fDy5fLw7jQX4XquRKaA/oOG5FXtdnKnqqY4zmI+fqSfLrdpSps8T/Ai/bQ 2gewt+wKpq585I/hvcpk2D610j4q+4hoeMP8mG5quxgBaDu/xdlyWUcAg947UOuxCWYf DEyg== 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: Zain Wang , Maxime Ripard , Sean Paul , Jose Souza , Tomasz Figa , David Airlie , Sean Paul , Dan Carpenter , Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Paul If state allocation fails, we still try to give back the reference on it. Also initialize ret in case the crtc is not enabled and we hit the eject button. Fixes: 1452c25b0e60 ("drm: Add helpers to kick off self refresh mode in drivers") Cc: Daniel Vetter Cc: Jose Souza Cc: Zain Wang Cc: Tomasz Figa Cc: Ville Syrjälä Cc: Sam Ravnborg Cc: Sean Paul Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: dri-devel@lists.freedesktop.org Reported-by: Dan Carpenter Signed-off-by: Sean Paul Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_self_refresh_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_self_refresh_helper.c b/drivers/gpu/drm/drm_self_refresh_helper.c index e0d2ad1f070cb..4b9424a8f1f1c 100644 --- a/drivers/gpu/drm/drm_self_refresh_helper.c +++ b/drivers/gpu/drm/drm_self_refresh_helper.c @@ -69,14 +69,14 @@ static void drm_self_refresh_helper_entry_work(struct work_struct *work) struct drm_connector *conn; struct drm_connector_state *conn_state; struct drm_crtc_state *crtc_state; - int i, ret; + int i, ret = 0; drm_modeset_acquire_init(&ctx, 0); state = drm_atomic_state_alloc(dev); if (!state) { ret = -ENOMEM; - goto out; + goto out_drop_locks; } retry: @@ -116,6 +116,8 @@ static void drm_self_refresh_helper_entry_work(struct work_struct *work) } drm_atomic_state_put(state); + +out_drop_locks: drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); }