Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751341AbbFYOea (ORCPT ); Thu, 25 Jun 2015 10:34:30 -0400 Received: from smtp73.iad3a.emailsrvr.com ([173.203.187.73]:40785 "EHLO smtp73.iad3a.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbbFYOeY (ORCPT ); Thu, 25 Jun 2015 10:34:24 -0400 X-Sender-Id: abbotti@mev.co.uk Message-ID: <558C116B.5090505@mev.co.uk> Date: Thu, 25 Jun 2015 15:34:19 +0100 From: Ian Abbott User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: Dan Carpenter , Maninder Singh CC: hsweeten@visionengravers.com, gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, pankaj.m@samsung.com Subject: Re: [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put References: <1435229426-39366-1-git-send-email-maninder1.s@samsung.com> <20150625112114.GB28762@mwanda> In-Reply-To: <20150625112114.GB28762@mwanda> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2031 Lines: 42 On 25/06/15 12:21, Dan Carpenter wrote: > On Thu, Jun 25, 2015 at 04:20:26PM +0530, Maninder Singh wrote: >> pci_dev_put cehcks for NULL pointer itself, >> reported by coccinelle >> > > This patch is correct but the motivation is wrong. > > The check in pci_dev_put() is like a sanity check. There are many > functions which have a sanity check and many which do not, it is > impossible for a human to remember the complete list of each. When we > remove explicit checks for NULL and instead rely on the sanity checks > it sometimes makes the code more subtle and difficult to read. > > In this case, "pcidev" can never be NULL so the check is misleading and > makes the code more complicated. Removing it is a good thing. Also > the attach function does not have a NULL check so when we remove this > check we make the code more consistent. Actually, it is possible for pcidev to be NULL here (pci9118_detach() in drivers/staging/comedi/drivers/adl_pci9118.c). This driver supports both the auto-attach (via PCI driver probe) and "legacy" attach (via COMEDI_DEVCONFIG ioctl). For the auto-attach case, pcidev will never be NULL. For the "legacy" attach case, pcidev can be NULL if the call to pci9118_find_pci() from pci9118_attach() failed to find a matching PCI device and so returned an error before the call to comedi_set_hw_dev(). The comedi core then calls pci9118_detach() which sets pcidev to the return value from comedi_to_pci_dev() which will be NULL in this case. > But in other cases, if "pcidev" could be NULL then we should keep the > check so that the code is easier to read. So we should keep the check in this case too. -- -=( Ian Abbott @ MEV Ltd. E-mail: )=- -=( Web: http://www.mev.co.uk/ )=- -- 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/