* smatch: module_init unwinding on errors
@ 2010-07-29 17:43 Dan Carpenter
2010-07-29 18:00 ` Randy Dunlap
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-07-29 17:43 UTC (permalink / raw)
To: kernel-janitors
Sort of inspired by Vasiliy's coccinelle work, I wrote a Smatch script to
verify that modules unwind on errors.
http://repo.or.cz/w/smatch.git/blob/HEAD:/check_unwind.c
The heuristic is if you
* call request_irq()
* it possibly succeeded
* you don't call free_irq()
* you're in a function that returns an int
* you are returning non-zero
Then complain.
One question that I had was for, "foo = request_region(bar, size)"
should we call release_region() on "foo" or on "bar"?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: smatch: module_init unwinding on errors
2010-07-29 17:43 smatch: module_init unwinding on errors Dan Carpenter
@ 2010-07-29 18:00 ` Randy Dunlap
2010-07-29 20:18 ` Dan Carpenter
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Randy Dunlap @ 2010-07-29 18:00 UTC (permalink / raw)
To: kernel-janitors
On Thu, 29 Jul 2010 19:43:29 +0200 Dan Carpenter wrote:
> Sort of inspired by Vasiliy's coccinelle work, I wrote a Smatch script to
> verify that modules unwind on errors.
>
> http://repo.or.cz/w/smatch.git/blob/HEAD:/check_unwind.c
>
> The heuristic is if you
> * call request_irq()
> * it possibly succeeded
> * you don't call free_irq()
> * you're in a function that returns an int
> * you are returning non-zero
> Then complain.
>
> One question that I had was for, "foo = request_region(bar, size)"
> should we call release_region() on "foo" or on "bar"?
Hi Dan,
Most drivers just use the result of request_region() as a pass/fail indicator.
Only a very few of them actually save the result pointer; mostly they just pass
bar to release_region().
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: smatch: module_init unwinding on errors
2010-07-29 17:43 smatch: module_init unwinding on errors Dan Carpenter
2010-07-29 18:00 ` Randy Dunlap
@ 2010-07-29 20:18 ` Dan Carpenter
2010-08-05 21:19 ` Randy Dunlap
2010-08-06 6:28 ` Julia Lawall
3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-07-29 20:18 UTC (permalink / raw)
To: kernel-janitors
On Thu, Jul 29, 2010 at 11:00:07AM -0700, Randy Dunlap wrote:
> Hi Dan,
>
> Most drivers just use the result of request_region() as a pass/fail indicator.
> Only a very few of them actually save the result pointer; mostly they just pass
> bar to release_region().
>
That was another thing which was concerning me. request_region()
returns freshly allocated memory. Isn't it a leak to discard this?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: smatch: module_init unwinding on errors
2010-07-29 17:43 smatch: module_init unwinding on errors Dan Carpenter
2010-07-29 18:00 ` Randy Dunlap
2010-07-29 20:18 ` Dan Carpenter
@ 2010-08-05 21:19 ` Randy Dunlap
2010-08-06 6:28 ` Julia Lawall
3 siblings, 0 replies; 5+ messages in thread
From: Randy Dunlap @ 2010-08-05 21:19 UTC (permalink / raw)
To: kernel-janitors
On Thu, 29 Jul 2010 22:18:03 +0200 Dan Carpenter wrote:
> On Thu, Jul 29, 2010 at 11:00:07AM -0700, Randy Dunlap wrote:
> > Hi Dan,
> >
> > Most drivers just use the result of request_region() as a pass/fail indicator.
> > Only a very few of them actually save the result pointer; mostly they just pass
> > bar to release_region().
> >
>
> That was another thing which was concerning me. request_region()
> returns freshly allocated memory. Isn't it a leak to discard this?
If I knew the answer, I would have already replied...
I was hoping that someone else could help out here.
I expect that if there was a leak, someone would have already noticed
and pointed this out to us. OTOH, this could be the last class of kernel
leaks that needs to be fixed... I dunno.
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: smatch: module_init unwinding on errors
2010-07-29 17:43 smatch: module_init unwinding on errors Dan Carpenter
` (2 preceding siblings ...)
2010-08-05 21:19 ` Randy Dunlap
@ 2010-08-06 6:28 ` Julia Lawall
3 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2010-08-06 6:28 UTC (permalink / raw)
To: kernel-janitors
On Thu, 5 Aug 2010, Randy Dunlap wrote:
> On Thu, 29 Jul 2010 22:18:03 +0200 Dan Carpenter wrote:
>
> > On Thu, Jul 29, 2010 at 11:00:07AM -0700, Randy Dunlap wrote:
> > > Hi Dan,
> > >
> > > Most drivers just use the result of request_region() as a pass/fail indicator.
> > > Only a very few of them actually save the result pointer; mostly they just pass
> > > bar to release_region().
> > >
> >
> > That was another thing which was concerning me. request_region()
> > returns freshly allocated memory. Isn't it a leak to discard this?
>
> If I knew the answer, I would have already replied...
> I was hoping that someone else could help out here.
>
> I expect that if there was a leak, someone would have already noticed
> and pointed this out to us. OTOH, this could be the last class of kernel
> leaks that needs to be fixed... I dunno.
request_region expands to a call to __request_region, which creates the
new memory and calls __request_resource. __request_resource fortunately
puts it into a tree that release_region subsequently frees. So there is
no problem with discarding the return value.
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-08-06 6:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-29 17:43 smatch: module_init unwinding on errors Dan Carpenter
2010-07-29 18:00 ` Randy Dunlap
2010-07-29 20:18 ` Dan Carpenter
2010-08-05 21:19 ` Randy Dunlap
2010-08-06 6:28 ` Julia Lawall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).