public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put
@ 2015-06-25 10:50 Maninder Singh
  2015-06-25 11:10 ` Sudip Mukherjee
  2015-06-25 11:21 ` Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Maninder Singh @ 2015-06-25 10:50 UTC (permalink / raw)
  To: abbotti, hsweeten, gregkh, devel, linux-kernel; +Cc: pankaj.m, Maninder Singh

pci_dev_put cehcks for NULL pointer itself,
reported by coccinelle

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Reviewed-by: Yogesh Gaur <yn.gaur@samsung.com>
---
 drivers/staging/comedi/drivers/adl_pci9118.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index fb3043d..19b5806 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -1717,8 +1717,7 @@ static void pci9118_detach(struct comedi_device *dev)
 		pci9118_reset(dev);
 	comedi_pci_detach(dev);
 	pci9118_free_dma(dev);
-	if (pcidev)
-		pci_dev_put(pcidev);
+	pci_dev_put(pcidev);
 }
 
 static struct comedi_driver adl_pci9118_driver = {
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put
  2015-06-25 10:50 [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put Maninder Singh
@ 2015-06-25 11:10 ` Sudip Mukherjee
  2015-06-25 11:21 ` Dan Carpenter
  1 sibling, 0 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2015-06-25 11:10 UTC (permalink / raw)
  To: Maninder Singh; +Cc: abbotti, hsweeten, gregkh, devel, linux-kernel, pankaj.m

On Thu, Jun 25, 2015 at 04:20:26PM +0530, Maninder Singh wrote:
> pci_dev_put cehcks for NULL pointer itself,
did you mean checks?

regards
sudip

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put
@ 2015-06-25 11:13 Maninder Singh
  0 siblings, 0 replies; 6+ messages in thread
From: Maninder Singh @ 2015-06-25 11:13 UTC (permalink / raw)
  To: Sudip Mukherjee
  Cc: abbotti@mev.co.uk, hsweeten@visionengravers.com,
	gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org, PANKAJ MISHRA

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=windows-1252, Size: 288 bytes --]

>> pci_dev_put cehcks for NULL pointer itself,
>did you mean checks?
Yes did some typo, send v2 of the patch.

Thanks
----------ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put
  2015-06-25 10:50 [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put Maninder Singh
  2015-06-25 11:10 ` Sudip Mukherjee
@ 2015-06-25 11:21 ` Dan Carpenter
  2015-06-25 14:34   ` Ian Abbott
  1 sibling, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2015-06-25 11:21 UTC (permalink / raw)
  To: Maninder Singh; +Cc: abbotti, hsweeten, gregkh, devel, linux-kernel, pankaj.m

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.

But in other cases, if "pcidev" could be NULL then we should keep the
check so that the code is easier to read.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put
@ 2015-06-25 11:31 Maninder Singh
  0 siblings, 0 replies; 6+ messages in thread
From: Maninder Singh @ 2015-06-25 11:31 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: abbotti@mev.co.uk, hsweeten@visionengravers.com,
	gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org, PANKAJ MISHRA

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=windows-1252, Size: 1128 bytes --]

Hi,

>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.
>
>But in other cases, if "pcidev" could be NULL then we should keep the
>check so that the code is easier to read.

Yes agree, I also sent this patch because there is only one call for pci_dev_put
in adl_pci9118.c, and i thoguht its good to remove check around that one.

Thanks for your feedback.
------------ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put
  2015-06-25 11:21 ` Dan Carpenter
@ 2015-06-25 14:34   ` Ian Abbott
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Abbott @ 2015-06-25 14:34 UTC (permalink / raw)
  To: Dan Carpenter, Maninder Singh
  Cc: hsweeten, gregkh, devel, linux-kernel, pankaj.m

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: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-25 14:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-25 10:50 [PATCH 1/1] staging/comedi: remove unnecessary check around pci_dev_put Maninder Singh
2015-06-25 11:10 ` Sudip Mukherjee
2015-06-25 11:21 ` Dan Carpenter
2015-06-25 14:34   ` Ian Abbott
  -- strict thread matches above, loose matches on Subject: below --
2015-06-25 11:13 Maninder Singh
2015-06-25 11:31 Maninder Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox