From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754490AbcHUVbJ (ORCPT ); Sun, 21 Aug 2016 17:31:09 -0400 Received: from smtprelay0174.hostedemail.com ([216.40.44.174]:41216 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753393AbcHUVbH (ORCPT ); Sun, 21 Aug 2016 17:31:07 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3622:3865:3867:3868:3870:3871:3872:4250:4321:5007:7903:10004:10400:10848:11026:11232:11657:11658:11783:11914:12043:12048:12114:12296:12438:12517:12519:12740:13069:13311:13357:13439:13894:14181:14659:14721:21080:30054:30064:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: size00_982c1e464b07 X-Filterd-Recvd-Size: 2710 Message-ID: <1471815064.3746.29.camel@perches.com> Subject: Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage From: Joe Perches To: Heinrich Schuchardt , Heinrich Schuchardt , Alex Deucher , Christian =?ISO-8859-1?Q?K=F6nig?= Cc: David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Date: Sun, 21 Aug 2016 14:31:04 -0700 In-Reply-To: <6345f323-9fc5-6d26-f646-0a0a5989c34d@gmx.de> References: <1471812743-5095-1-git-send-email-xypron.glpk@gmx.de> <1471813562.3746.23.camel@perches.com> <6345f323-9fc5-6d26-f646-0a0a5989c34d@gmx.de> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2016-08-21 at 23:20 +0200, Heinrich Schuchardt wrote: > On 08/21/2016 11:06 PM, Joe Perches wrote: > > On Sun, 2016-08-21 at 22:52 +0200, Heinrich Schuchardt wrote: > > > > > > It does not make sense to check if table is NULL > > > and afterwards to dereference it without > > > considering the result. > > This makes no sense. > > > The inconsistency was indicated by cppcheck. > > Perhaps this is a defect in cppcheck? > > > An actual NULL pointer dereference was not observed. > > [] > > > diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c > > [] > > > @@ -2962,7 +2962,7 @@ static int si_get_vce_clock_voltage(struct radeon_device *rdev, > > >   &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table; > > >   > > >   if (((evclk == 0) && (ecclk == 0)) || > > > -     (table && (table->count == 0))) { > > Here table is only dereferenced if table is non-null > > > > > > +     table == NULL || table->count == 0) { > > >   *voltage = 0; > > >   return 0; > > >   } > > Perhaps the unnecessary parentheses can be reduce though. > > > >   if ((evclk == 0 && ecclk == 0) || (table && table->count == 0)) { > > > The possible NULL pointer dereference would occur here: > > 2970        for (i = 0; i < table->count; i++) { This still doesn't make any sense as table is known non-null at line 2961 struct radeon_vce_clock_voltage_dependency_table *table = &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table; So I now suggest simply removing the test for table. Perhaps cppcheck can be improved to know about known non-null pointers.