From patchwork Mon Nov 19 09:44:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 12917 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 89ABC23E08 for ; Mon, 19 Nov 2012 09:51:24 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 37231A18443 for ; Mon, 19 Nov 2012 09:51:24 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so6161934iej.11 for ; Mon, 19 Nov 2012 01:51:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=Ha6PPyuuX/S9FG1ZboHPmmS64DTVorR9mVnWAKkC1oU=; b=eGm7V5PYOXBlDBcSU3LFICRBj+Saz2V5qCb4CXBorIuNaWa9MzgczLaYHYHv71RPkx bk/Q/32r+PoqHXPdfqS5+FQlwhjgzF+tPxFFxsWKzkAafNxen7P6jqV0dHGYW9vGRsnN cWGCZPEqGQ2fAbnb0JKOCsxCovW7ffCGJu3XT9/+Qsmg76K7jlQ+Or56pRoBUhSLDaZY C3FujBQpXy0pYIg8I1iY5y3cco5rZFsWlSXDhhKudf1zXLYgI8h+6aBhvqwFEO5IetdQ P41e296T3sVfM4KwFMByup7Ne10s7Ma29WG2Ts9ap4Ds3jNMG9OZhLVa6eU2WPdCUFK5 kzlA== Received: by 10.50.213.69 with SMTP id nq5mr5968313igc.70.1353318684004; Mon, 19 Nov 2012 01:51:24 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp135918igt; Mon, 19 Nov 2012 01:51:23 -0800 (PST) Received: by 10.66.73.102 with SMTP id k6mr34244437pav.22.1353318683465; Mon, 19 Nov 2012 01:51:23 -0800 (PST) Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by mx.google.com with ESMTPS id q6si12784333pay.81.2012.11.19.01.51.23 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Nov 2012 01:51:23 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.44 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.220.44; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.44 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) smtp.mail=sachin.kamat@linaro.org Received: by mail-pa0-f44.google.com with SMTP id hz11so1344006pad.3 for ; Mon, 19 Nov 2012 01:51:23 -0800 (PST) Received: by 10.66.88.102 with SMTP id bf6mr34358918pab.10.1353318683225; Mon, 19 Nov 2012 01:51:23 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id l4sm3180099paw.15.2012.11.19.01.51.17 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Nov 2012 01:51:22 -0800 (PST) From: Sachin Kamat To: dri-devel@lists.freedesktop.org Cc: airlied@linux.ie, airlied@gmail.com, sachin.kamat@linaro.org, patches@linaro.org Subject: [PATCH 3/4] drm/fb_helper: Fix potential NULL pointer dereference Date: Mon, 19 Nov 2012 15:14:58 +0530 Message-Id: <1353318299-3662-3-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1353318299-3662-1-git-send-email-sachin.kamat@linaro.org> References: <1353318299-3662-1-git-send-email-sachin.kamat@linaro.org> X-Gm-Message-State: ALoCoQmzVcp8D8U/C+BC7d4kY/aacP0ZlMIYUM5M7kGQCXG4BMlYOlCm5EKN2gits70NHoYLpBwv kcalloc returns NULL on failure. Hence check for the return value and exit on error to avoid NULL pointer dereference. Fixes the following smatch errors: drivers/gpu/drm/drm_fb_helper.c:1271 drm_setup_crtcs() error: potential null dereference 'modes'. (kcalloc returns null) drivers/gpu/drm/drm_fb_helper.c:1272 drm_setup_crtcs() error: potential null dereference 'crtcs'. (kcalloc returns null) Signed-off-by: Sachin Kamat --- Dependent on the following patch series: http://comments.gmane.org/gmane.comp.video.dri.devel/76605 --- drivers/gpu/drm/drm_fb_helper.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 8c2de02..fc67cc5 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1251,6 +1251,11 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) sizeof(struct drm_display_mode *), GFP_KERNEL); enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool), GFP_KERNEL); + if (!crtcs || !modes || !enabled) { + DRM_ERROR("Memory allocation failed\n"); + goto out; + } + drm_enable_connectors(fb_helper, enabled); @@ -1289,6 +1294,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) } } +out: kfree(crtcs); kfree(modes); kfree(enabled);