Fix a memory leak if VideoPortInitialize is called more than once from the same miniport.
[reactos.git] / reactos / drivers / video / videoprt / timer.c
1 /*
2 * VideoPort driver
3 *
4 * Copyright (C) 2002, 2003, 2004 ReactOS Team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB.
18 * If not, write to the Free Software Foundation,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * $Id$
22 */
23
24 #include "videoprt.h"
25
26 /* PRIVATE FUNCTIONS **********************************************************/
27
28 VOID NTAPI
29 IntVideoPortTimerRoutine(
30 IN PDEVICE_OBJECT DeviceObject,
31 IN PVOID ServiceContext)
32 {
33 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = ServiceContext;
34
35 ASSERT(DeviceExtension->DriverExtension->InitializationData.HwTimer != NULL);
36
37 DeviceExtension->DriverExtension->InitializationData.HwTimer(
38 &DeviceExtension->MiniPortDeviceExtension);
39 }
40
41 BOOLEAN NTAPI
42 IntVideoPortSetupTimer(
43 IN PDEVICE_OBJECT DeviceObject,
44 IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension)
45 {
46 NTSTATUS Status;
47 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
48
49 DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
50
51 if (DriverExtension->InitializationData.HwTimer != NULL)
52 {
53 DPRINT("Initializing timer\n");
54
55 Status = IoInitializeTimer(
56 DeviceObject,
57 IntVideoPortTimerRoutine,
58 DeviceExtension);
59
60 if (!NT_SUCCESS(Status))
61 {
62 DPRINT("IoInitializeTimer failed with status 0x%08x\n", Status);
63 return FALSE;
64 }
65 }
66
67 return TRUE;
68 }
69
70 /* PUBLIC FUNCTIONS ***********************************************************/
71
72 /*
73 * @implemented
74 */
75
76 VOID NTAPI
77 VideoPortStartTimer(IN PVOID HwDeviceExtension)
78 {
79 DPRINT("VideoPortStartTimer\n");
80 IoStartTimer(VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->FunctionalDeviceObject);
81 }
82
83 /*
84 * @implemented
85 */
86
87 VOID NTAPI
88 VideoPortStopTimer(IN PVOID HwDeviceExtension)
89 {
90 DPRINT("VideoPortStopTimer\n");
91 IoStopTimer(VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->FunctionalDeviceObject);
92 }