gpu: pvr: fix memory context refcount problem leading to leaked handle
authorImre Deak <imre.deak@nokia.com>
Mon, 11 Apr 2011 12:36:31 +0000 (15:36 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 20 May 2012 18:43:05 +0000 (21:43 +0300)
commit9267c4505776d41364870b3698e2367a2a2e3766
treef5649afc1234523ff14d92820d419b1082f8f9bf
parent8734b9e8103122036d76cc3ba3750c5719c25c66
gpu: pvr: fix memory context refcount problem leading to leaked handle

Although there is an IOCTL interface for creating memory contexts, in
reality processes can create only a single context. Subsequent create
commands will return the same context _and_ the same handle, so this
resembles more of an 'open' command, except the somewhat orthodox way of
returning the same handle.

In addition there can be kernel only users of the context accounted for
by the current reference count of the context (ui32RefCount).

Removing the user handle should happen when the last process opening
(creating) the context calls the close (destroy) command on the handle.
At the moment the handle is removed only if there are no kernel side or
user space users of the context, which can lead to the handle being
leaked in the following case:

1. create memory context -> ctx_handle created, ctx_refcount=1
2. create buffer -> ctx_refcount=2
3. destroy memory context -> ctx_refcount=1, ctx_handle not removed
4. destroy buffer -> ctx_refcount=0, ctx_handle not removed

To avoid this add a counter tracking the number of opens, so we know
when to remove the handle.

Fixes: NB#245525 - Return value of pvr_put_ctx is not checked

Signed-off-by: Imre Deak <imre.deak@nokia.com>
pvr/bridged_pvr_bridge.c
pvr/buffer_manager.h
pvr/devicemem.c
pvr/pvr_bridge_km.h