mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2/2] drivers/pci/hotplug: Add missing pci_dev_get
@ 2008-11-23  8:08 Julia Lawall
  2008-12-01 20:30 ` Jesse Barnes
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2008-11-23  8:08 UTC (permalink / raw)
  To: jbarnes, linux-pci, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

pci_get_slot does a pci_dev_get, so pci_dev_put needs to be called in an
error case.

An alterative would be to move the test_and_set_bit before the call to
pci_get_slot.

The problem was fixed using the following semantic patch.
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
local idexpression *n;
statement S1,S2;
expression E,E1;
expression *ptr != NULL;
type T,T1;
@@

(
if (!(n = pci_get_slot(...))) S1
|
n = pci_get_slot(...)
)
<... when != pci_dev_put(n)
    when != if (...) { <+... pci_dev_put(n) ...+> }
    when != true !n  || ...
    when != n = (T)E
    when != E = n
if (!n || ...) S2
...>
(
  return \(0\|<+...n...+>\|ptr\);
|
+ pci_dev_put(n);
return ...;
|
pci_dev_put(n);
|
n = (T1)E1
|
E1 = n
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
---

 drivers/pci/hotplug/fakephp.c |    1 +
 1 file changed, 1 insertion(+)

diff -u -p a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -324,6 +324,7 @@ static int disable_slot(struct hotplug_s
 
 		if (test_and_set_bit(0, &dslot->removed)) {
 			dbg("Slot already scheduled for removal\n");
+			pci_dev_put(dev);
 			return -ENODEV;
 		}
 

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

* Re: [PATCH 2/2] drivers/pci/hotplug: Add missing pci_dev_get
  2008-11-23  8:08 [PATCH 2/2] drivers/pci/hotplug: Add missing pci_dev_get Julia Lawall
@ 2008-12-01 20:30 ` Jesse Barnes
  0 siblings, 0 replies; 2+ messages in thread
From: Jesse Barnes @ 2008-12-01 20:30 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-pci, linux-kernel, kernel-janitors

On Sunday, November 23, 2008 12:08 am Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> pci_get_slot does a pci_dev_get, so pci_dev_put needs to be called in an
> error case.
>
> An alterative would be to move the test_and_set_bit before the call to
> pci_get_slot.
>
> The problem was fixed using the following semantic patch.
> (http://www.emn.fr/x-info/coccinelle/)

Applied to my linux-next branch, thanks.  Btw, I've seen quite a few of these 
Coccinelle related patches fly by, but I haven't seen an introduction of the 
tool posted to lkml.  Did I miss it?  Or maybe it just went to the janitors 
list?  If not, it seems like it might be a worthwhile thing to describe for 
people...


-- 
Jesse Barnes, Intel Open Source Technology Center


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

end of thread, other threads:[~2008-12-01 20:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-23  8:08 [PATCH 2/2] drivers/pci/hotplug: Add missing pci_dev_get Julia Lawall
2008-12-01 20:30 ` Jesse Barnes

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

all inboxes | Powered by JetHome®