From patchwork Tue Jan 17 16:25:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 91703 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp526503obz; Tue, 17 Jan 2017 08:40:13 -0800 (PST) X-Received: by 10.84.236.76 with SMTP id h12mr60161211pln.173.1484671213846; Tue, 17 Jan 2017 08:40:13 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u19si25447944plj.101.2017.01.17.08.40.13; Tue, 17 Jan 2017 08:40:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbdAQQkG (ORCPT + 25 others); Tue, 17 Jan 2017 11:40:06 -0500 Received: from fw-tnat.cambridge.arm.com ([217.140.96.140]:53818 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751115AbdAQQkE (ORCPT ); Tue, 17 Jan 2017 11:40:04 -0500 X-Greylist: delayed 873 seconds by postgrey-1.27 at vger.kernel.org; Tue, 17 Jan 2017 11:39:36 EST Received: from e110455-lin.cambridge.arm.com (e110455-lin.cambridge.arm.com [10.2.131.175]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id v0HGOvUk022705; Tue, 17 Jan 2017 16:24:57 GMT From: Liviu Dudau To: Brian Starkey Cc: Mali DP Maintainers , David Airlie , DRI devel , LKML , Shailendra Verma , Shailendra Verma Subject: [PATCH 1/8] drm/arm/malidp: Fix possible dereference of NULL Date: Tue, 17 Jan 2017 16:25:00 +0000 Message-Id: <20170117162507.31961-2-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170117162507.31961-1-Liviu.Dudau@arm.com> References: <20170117162507.31961-1-Liviu.Dudau@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shailendra Verma There is possible deference of NULL pointer on return of malidp_duplicate_plane_state() if kmalloc fails. Check the returned kmalloc pointer before continuing. Signed-off-by: Shailendra Verma [cleaned up the code and re-formatted the commit message] Signed-off-by: Liviu Dudau --- drivers/gpu/drm/arm/malidp_planes.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.11.0 diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index eff2fe47e26a..d1cc15724dc3 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -67,13 +67,14 @@ drm_plane_state *malidp_duplicate_plane_state(struct drm_plane *plane) return NULL; state = kmalloc(sizeof(*state), GFP_KERNEL); - if (state) { - m_state = to_malidp_plane_state(plane->state); - __drm_atomic_helper_plane_duplicate_state(plane, &state->base); - state->rotmem_size = m_state->rotmem_size; - state->format = m_state->format; - state->n_planes = m_state->n_planes; - } + if (!state) + return NULL; + + m_state = to_malidp_plane_state(plane->state); + __drm_atomic_helper_plane_duplicate_state(plane, &state->base); + state->rotmem_size = m_state->rotmem_size; + state->format = m_state->format; + state->n_planes = m_state->n_planes; return &state->base; }