Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753082AbbGBLMW (ORCPT ); Thu, 2 Jul 2015 07:12:22 -0400 Received: from opensource.wolfsonmicro.com ([80.75.67.52]:49686 "EHLO opensource.wolfsonmicro.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751707AbbGBLMP (ORCPT ); Thu, 2 Jul 2015 07:12:15 -0400 Date: Thu, 2 Jul 2015 12:12:13 +0100 From: Charles Keepax To: Maninder Singh Cc: "lgirdwood@gmail.com" , "broonie@kernel.org" , "patches@opensource.wolfsonmicro.com" , "linux-kernel@vger.kernel.org" , PANKAJ MISHRA Subject: Re: [PATCH v2] regulator: wm831x-dcdc: Use pointer after NULL check Message-ID: <20150702111213.GC16517@opensource.wolfsonmicro.com> References: <1041654268.190401435834974293.JavaMail.weblogic@ep2mlwas01a> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1041654268.190401435834974293.JavaMail.weblogic@ep2mlwas01a> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1288 Lines: 32 On Thu, Jul 02, 2015 at 11:02:54AM +0000, Maninder Singh wrote: > Hello charles, > >> pdata is used before NULL check, so it looks misleading. > >> If pdata validation is required then we have to > >> first check for pdata validation, then calculate id, > >> and then second check for pdata->dcdc[id]. > >> > >> and it is better to use !pointer than (pointer == NULL) > >> > >> Signed-off-by: Maninder Singh > >> --- > > >The patch basically looks fine, but it feels a bit like needless > >churn. The current code is perfectly correct and feels clear > >enough to me. > > Reason for patch is we are checking a pointer which is already dereferenced > before NULL check, which looks misleading. > If we know code is working correctly, Then we may simply drop NULL check, > rather than these changes. You can't drop the NULL check because then we might dereference a NULL pointer. ARRAY_SIZE(pdata->dcdc) is perfectly save because sizeof only works on types so no actual dereference takes place. Thanks, Charles -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/