From patchwork Thu Aug 28 17:40:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 4805921 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1CD319F2A9 for ; Thu, 28 Aug 2014 17:40:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 337FE200D4 for ; Thu, 28 Aug 2014 17:40:31 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1A96E20145 for ; Thu, 28 Aug 2014 17:40:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 097AB6E3A9; Thu, 28 Aug 2014 10:40:28 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yh0-f46.google.com (mail-yh0-f46.google.com [209.85.213.46]) by gabe.freedesktop.org (Postfix) with ESMTP id 38A9C6E30E; Thu, 28 Aug 2014 10:40:23 -0700 (PDT) Received: by mail-yh0-f46.google.com with SMTP id t59so725088yho.19 for ; Thu, 28 Aug 2014 10:40:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zC9HhWo1oeT+gCqLcYJdMYKdNlM2a3kdscLIn36yEJs=; b=l828SgexbKMRr8Hx+fOUrqZgeUu+Mi88XfjdMJGIV4OHIb6k6VrhlTlZctg676F6UF KlXgGfFT8+2I1Vz+BisRdos7JPtSk7DHIOsrzSztnt4RzbvWYXrzyRCjwLQ9RaVl+37+ 5NPIVlnONZ1sRZuoKynlQ0LZUg57kf/bnTv1RoX/Tg08a2epTHgwJgHq37lJ7mOCwkSH D+mfF/alWIJgVxjy1LrveJz+vUslcjc3K16sXtaXgqo0QMh1eAxjEYOmiHF4gOrt+38Z z9Qw0EkPi5wGReT942K5RMGQ0RTCgTcHbhwmMWk9fLFy7YwqjUmaMRxUWIrj5frEjPkk OCqg== X-Received: by 10.236.41.50 with SMTP id g38mr6024374yhb.61.1409247622736; Thu, 28 Aug 2014 10:40:22 -0700 (PDT) Received: from localhost.localdomain ([187.10.18.246]) by mx.google.com with ESMTPSA id a14sm2020073yho.33.2014.08.28.10.40.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Aug 2014 10:40:21 -0700 (PDT) From: Gustavo Padovan To: intel-gfx@lists.freedesktop.org Subject: [PATCH 3/9] drm/i915: fix memleak in intel_set_config_save_state() Date: Thu, 28 Aug 2014 14:40:07 -0300 Message-Id: <1409247613-14232-3-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1409247613-14232-1-git-send-email-gustavo@padovan.org> References: <1409247613-14232-1-git-send-email-gustavo@padovan.org> Cc: Gustavo Padovan , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan If the save_encoder_crtcs or save_connector_encoders allocation fail we need to free everything we have already allocated. Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/i915/intel_display.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 05937fe..a8a8abe 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -11018,13 +11018,13 @@ static int intel_set_config_save_state(struct drm_device *dev, kcalloc(dev->mode_config.num_encoder, sizeof(struct drm_crtc *), GFP_KERNEL); if (!config->save_encoder_crtcs) - return -ENOMEM; + goto free_crtc; config->save_connector_encoders = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_encoder *), GFP_KERNEL); if (!config->save_connector_encoders) - return -ENOMEM; + goto free_encoder; /* Copy data. Note that driver private data is not affected. * Should anything bad happen only the expected state is @@ -11046,6 +11046,12 @@ static int intel_set_config_save_state(struct drm_device *dev, } return 0; + +free_encoder: + kfree(config->save_encoder_crtcs); +free_crtc: + kfree(config->save_crtc_enabled); + return -ENOMEM; } static void intel_set_config_restore_state(struct drm_device *dev,