From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754281AbcEWPf5 (ORCPT ); Mon, 23 May 2016 11:35:57 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:52082 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753235AbcEWPf4 (ORCPT ); Mon, 23 May 2016 11:35:56 -0400 Date: Mon, 23 May 2016 16:35:53 +0100 From: Eric Engestrom To: Chris Wilson , Heinrich Schuchardt , , Subject: Re: [PATCH] drm/mm: avoid possible null pointer dereference Message-ID: <20160523153553.GF13596@imgtec.com> References: <1463602639-4861-1-git-send-email-xypron.glpk@gmx.de> <20160523102714.GA13596@imgtec.com> <20160523125645.GY27098@phenom.ffwll.local> <20160523130226.GB19361@nuc-i3427.alporthouse.com> <20160523133829.GE13596@imgtec.com> <20160523134659.GD19361@nuc-i3427.alporthouse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20160523134659.GD19361@nuc-i3427.alporthouse.com> User-Agent: Mutt/1.6.1 (2016-04-27) X-Originating-IP: [10.60.4.28] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2016 at 02:46:59PM +0100, Chris Wilson wrote: > On Mon, May 23, 2016 at 02:38:29PM +0100, Eric Engestrom wrote: > > On Mon, May 23, 2016 at 02:02:26PM +0100, Chris Wilson wrote: > > > On Mon, May 23, 2016 at 02:56:45PM +0200, Daniel Vetter wrote: > > > > On Mon, May 23, 2016 at 11:27:14AM +0100, Eric Engestrom wrote: > > > > > On Wed, May 18, 2016 at 10:17:19PM +0200, Heinrich Schuchardt wrote: > > > > > > Do not dereference node before the check if node is NULL. > > > > > > > > > > > > Signed-off-by: Heinrich Schuchardt > > > > > > --- > > > > > > drivers/gpu/drm/drm_mm.c | 4 +++- > > > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > > > > > > > diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c > > > > > > index 04de6fd..cb39f45 100644 > > > > > > --- a/drivers/gpu/drm/drm_mm.c > > > > > > +++ b/drivers/gpu/drm/drm_mm.c > > > > > > @@ -179,12 +179,14 @@ static void drm_mm_insert_helper(struct drm_mm_node *hole_node, > > > > > > int drm_mm_reserve_node(struct drm_mm *mm, struct drm_mm_node *node) > > > > > > { > > > > > > struct drm_mm_node *hole; > > > > > > - u64 end = node->start + node->size; > > > > > > + u64 end; > > > > > > u64 hole_start; > > > > > > u64 hole_end; > > > > > > > > > > > > BUG_ON(node == NULL); > > > > > > > > > > > > + end = node->start + node->size; > > > > > > + > > > > > > /* Find the relevant hole to add our node to */ > > > > > > drm_mm_for_each_hole(hole, mm, hole_start, hole_end) { > > > > > > if (hole_start > node->start || hole_end < end) > > > > > > -- > > > > > > 2.1.4 > > > > > > > > > > Reviewed-by: Eric Engestrom > > > > > > Remove useless check instead? > > > -Chris > > > > I tend to prefer erring on the side of caution and have (too) many checks, > > especially simple ones like avoiding null dereferences. > > BUG(node == NULL) is no more informative than hitting a GFP with *node. Good point. > > > That said, BUG() might be too extreme. I'm not all that familiar with > > the code, but it doesn't seem like it would be an unrecoverable failure. > > WARN() instead? > > It's a programming error, just as would be passing in mm == NULL. Mark up > the function as requiring non-NULL parameters. > -Chris Using `__attribute__((nonnull))`? I approve of that idea, as I find those attributes extremely useful and try to get them used as much as possible at $DAYJOB. I have noticed however that this particular attribute isn't used much in the kernel (4 times that I could find with a simple grep), to the point of not even having a `__nonnull`. Any reason you know of? Cheers, Eric