* question about sound/pci/ctxfi/ctpcm.c
@ 2010-11-08 16:58 Julia Lawall
2010-11-09 8:07 ` Clemens Ladisch
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2010-11-08 16:58 UTC (permalink / raw)
To: perex, tiwai, tj, alsa-devel
The file sound/pci/ctxfi/ctpcm.c contains the functions
ct_pcm_playback_open and ct_pcm_capture_open that contain the following
pattern of code:
runtime->private_data = apcm;
...
if (err < 0) {
kfree(apcm);
return err;
}
I wonder if this leaves a dangling pointer to apcm in runtime?
The function ct_atc_pcm_free_substream on the other hand does set the
private_data field to NULL after freeing apcm. But perhaps there is
something in the calling context of open that ensures that if the open
function fails, the private_data field of runtime will never be used?
thanks,
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about sound/pci/ctxfi/ctpcm.c
2010-11-08 16:58 question about sound/pci/ctxfi/ctpcm.c Julia Lawall
@ 2010-11-09 8:07 ` Clemens Ladisch
2010-11-09 8:25 ` Julia Lawall
0 siblings, 1 reply; 5+ messages in thread
From: Clemens Ladisch @ 2010-11-09 8:07 UTC (permalink / raw)
To: Julia Lawall; +Cc: tiwai, tj, alsa-devel
Julia Lawall wrote:
> The file sound/pci/ctxfi/ctpcm.c contains the functions
> ct_pcm_playback_open and ct_pcm_capture_open that contain the following
> pattern of code:
>
> runtime->private_data = apcm;
> ...
> if (err < 0) {
> kfree(apcm);
> return err;
> }
>
> I wonder if this leaves a dangling pointer to apcm in runtime?
The runtime structure contains data that is valid only while the
substream is open; it is allocated by the ALSA framework before
calling the open callback, and deallocated after calling the close
callback (or if the open callback fails).
> The function ct_atc_pcm_free_substream on the other hand does set the
> private_data field to NULL after freeing apcm.
This is superfluous.
> But perhaps there is something in the calling context of open that
> ensures that if the open function fails, the private_data field of
> runtime will never be used?
If the open callback fails, the close callback will not be called.
However, the runtime->private_free callback, if set, will be called.
So there is indeed a dangling pointer.
Regards,
Clemens
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about sound/pci/ctxfi/ctpcm.c
2010-11-09 8:07 ` Clemens Ladisch
@ 2010-11-09 8:25 ` Julia Lawall
2010-11-09 11:03 ` Clemens Ladisch
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2010-11-09 8:25 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: tiwai, tj, alsa-devel
On Tue, 9 Nov 2010, Clemens Ladisch wrote:
> Julia Lawall wrote:
> > The file sound/pci/ctxfi/ctpcm.c contains the functions
> > ct_pcm_playback_open and ct_pcm_capture_open that contain the following
> > pattern of code:
> >
> > runtime->private_data = apcm;
> > ...
> > if (err < 0) {
> > kfree(apcm);
> > return err;
> > }
> >
> > I wonder if this leaves a dangling pointer to apcm in runtime?
>
> The runtime structure contains data that is valid only while the
> substream is open; it is allocated by the ALSA framework before
> calling the open callback, and deallocated after calling the close
> callback (or if the open callback fails).
>
> > The function ct_atc_pcm_free_substream on the other hand does set the
> > private_data field to NULL after freeing apcm.
>
> This is superfluous.
>
> > But perhaps there is something in the calling context of open that
> > ensures that if the open function fails, the private_data field of
> > runtime will never be used?
>
> If the open callback fails, the close callback will not be called.
> However, the runtime->private_free callback, if set, will be called.
>
> So there is indeed a dangling pointer.
Thanks for the explanation. One option would be to move the
initializations downwards, since the intervening calls that use runtime
don't use those fields. The other would be to set provate_data to NULL
after doing the free. Any preference?
thanks,
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about sound/pci/ctxfi/ctpcm.c
2010-11-09 11:03 ` Clemens Ladisch
@ 2010-11-09 11:03 ` Julia Lawall
0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2010-11-09 11:03 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: tiwai, tj, alsa-devel
On Tue, 9 Nov 2010, Clemens Ladisch wrote:
> Julia Lawall wrote:
> > [...] One option would be to move the
> > initializations downwards, since the intervening calls that use runtime
> > don't use those fields. The other would be to set provate_data to NULL
> > after doing the free. Any preference?
>
> I notice that ct_atc_pcm_free_substream does not expect private_data to
> be NULL, so only the first option would work. Furthermore, apcm->timer
> must not be NULL, so the initialization must be moved to the end of the
> function.
Thanks. I will send a patch later today.
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about sound/pci/ctxfi/ctpcm.c
2010-11-09 8:25 ` Julia Lawall
@ 2010-11-09 11:03 ` Clemens Ladisch
2010-11-09 11:03 ` Julia Lawall
0 siblings, 1 reply; 5+ messages in thread
From: Clemens Ladisch @ 2010-11-09 11:03 UTC (permalink / raw)
To: Julia Lawall; +Cc: tiwai, tj, alsa-devel
Julia Lawall wrote:
> [...] One option would be to move the
> initializations downwards, since the intervening calls that use runtime
> don't use those fields. The other would be to set provate_data to NULL
> after doing the free. Any preference?
I notice that ct_atc_pcm_free_substream does not expect private_data to
be NULL, so only the first option would work. Furthermore, apcm->timer
must not be NULL, so the initialization must be moved to the end of the
function.
Regards,
Clemens
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-11-09 11:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-08 16:58 question about sound/pci/ctxfi/ctpcm.c Julia Lawall
2010-11-09 8:07 ` Clemens Ladisch
2010-11-09 8:25 ` Julia Lawall
2010-11-09 11:03 ` Clemens Ladisch
2010-11-09 11:03 ` 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).