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>