Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754138AbcDYJPw (ORCPT ); Mon, 25 Apr 2016 05:15:52 -0400 Received: from down.free-electrons.com ([37.187.137.238]:50836 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753590AbcDYJPu (ORCPT ); Mon, 25 Apr 2016 05:15:50 -0400 Date: Mon, 25 Apr 2016 11:15:43 +0200 From: Boris Brezillon To: Dan Carpenter , Daniel Vetter Cc: David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [patch] drm: atmel-hlcdc: fix a NULL check Message-ID: <20160425111543.5677b80a@bbrezillon> In-Reply-To: <20160425090454.GA25366@mwanda> References: <20160425090454.GA25366@mwanda> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1129 Lines: 40 Hi Daniel, On Mon, 25 Apr 2016 12:04:54 +0300 Dan Carpenter wrote: > If kmalloc() returned NULL we would end up dereferencing "state" a > couple lines later. Can you take this patch in drm-misc, or should I send a PR? Regards, Boris > > Signed-off-by: Dan Carpenter > > diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c > index 8df0aaf..867069b 100644 > --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c > +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c > @@ -415,8 +415,9 @@ atmel_hlcdc_crtc_duplicate_state(struct drm_crtc *crtc) > return NULL; > > state = kmalloc(sizeof(*state), GFP_KERNEL); > - if (state) > - __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base); > + if (!state) > + return NULL; > + __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base); > > cur = drm_crtc_state_to_atmel_hlcdc_crtc_state(crtc->state); > state->output_mode = cur->output_mode; -- Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com