Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754127AbbFOKsW (ORCPT ); Mon, 15 Jun 2015 06:48:22 -0400 Received: from cantor2.suse.de ([195.135.220.15]:40930 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754046AbbFOKsN (ORCPT ); Mon, 15 Jun 2015 06:48:13 -0400 Date: Mon, 15 Jun 2015 12:48:05 +0200 From: Johannes Thumshirn To: Sreekanth Reddy Cc: "jejb@kernel.org" , Christoph Hellwig , "Martin K. Petersen" , "linux-scsi@vger.kernel.org" , "James E.J. Bottomley" , Sathya Prakash , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 04/20] [SCSI] mpt3sas: Remove redundancy code while freeing the controller resources. Message-ID: <20150615104805.GA10429@c203.arch.suse.de> References: <1434102153-38581-1-git-send-email-Sreekanth.Reddy@avagotech.com> <1434102153-38581-5-git-send-email-Sreekanth.Reddy@avagotech.com> <20150612112826.GC2812@c203.arch.suse.de> <20150612124024.GB16614@c203.arch.suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3070 Lines: 85 On Mon, Jun 15, 2015 at 03:56:56PM +0530, Sreekanth Reddy wrote: > On Fri, Jun 12, 2015 at 6:10 PM, Johannes Thumshirn wrote: > > On Fri, Jun 12, 2015 at 05:48:56PM +0530, Sreekanth Reddy wrote: > >> On Fri, Jun 12, 2015 at 4:58 PM, Johannes Thumshirn wrote: > >> > On Fri, Jun 12, 2015 at 03:12:16PM +0530, Sreekanth Reddy wrote: > >> >> Removed the redundancy code while freeing the controller resources. > >> >> > >> >> Signed-off-by: Sreekanth Reddy > >> >> --- > >> >> drivers/scsi/mpt3sas/mpt3sas_base.c | 57 +++++++++++++++++++++---------------- > > [...] > >> >> + _base_free_irq(ioc); > >> >> + _base_disable_msix(ioc); > >> >> + > >> >> + if (ioc->msix96_vector) > >> >> + kfree(ioc->replyPostRegisterIndex); > >> > > >> > kfree() already checks for zero or a NULL pointer. > >> > >> Sorry Johannes, I didn't get you. If I understand this correctly, you > >> are suggesting to check for NULL pointer before calling kree() API as > >> shown below, > >> > >> if (ioc->msix96_vector && (ioc->replyPostRegisterIndex != NULL)) > >> kfree(ioc->replyPostRegisterIndex); > > > > Correct me if I'm wrong, but I thought you don't need the if > > (ioc->msix96_vector) before the kfree(). ioc->replyPostRegisterIndex should be > > NULL if ioc->msix96_vector is 0, as far as I can see. > > > > In _scsih_probe() you have: > > shost = scsi_host_alloc(&scsih_driver_template, > > sizeof(struct MPT3SAS_ADAPTER)); > > if (!shost) > > return -ENODEV; > > > > /* init local params */ > > ioc = shost_priv(shost); > > > > and scsi_host_alloc() does a kzalloc() for shost. > > > > so ioc->replyPortRegisterIndex is NULL. > > > > Or am I thinking wrong here? > > Yes, ioc->replyPostRegisterIndex will be NULL if ioc->msix96_vector is 0, > We have added this checks as a precautionary. since calling this > function (i.e kfree()) on memory not previously allocated with > kmalloc(), or on memory which has already been freed, may results in > very bad things, such as freeing memory belonging to another part of > the kernel. > OK, then please leave it in. > > > >> > >> Regards, > >> Sreekanth > > > > -- > > Johannes Thumshirn Storage > > jthumshirn@suse.de +49 911 74053 689 > > SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg > > GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton > > HRB 21284 (AG N?rnberg) > > > > -- > > Regards, > Sreekanth -- Johannes Thumshirn Storage jthumshirn@suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG N?rnberg) -- 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/