GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_instance_clean.c Lines: 45 45 100.0 %
Date: 2024-12-12 17:16:36 Branches: 21 24 87.5 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   HID Class                                                           */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
23
/* Include necessary system files.  */
24
25
#define UX_SOURCE_CODE
26
27
#include "ux_api.h"
28
#include "ux_host_class_hid.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_class_hid_instance_clean                   PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function cleans all the components of a HID instance.          */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    hid                                   Pointer to HID class          */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    Completion Status                                                   */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    _ux_utility_memory_free               Release memory block          */
57
/*                                                                        */
58
/*  CALLED BY                                                             */
59
/*                                                                        */
60
/*    HID Class                                                           */
61
/*                                                                        */
62
/*  RELEASE HISTORY                                                       */
63
/*                                                                        */
64
/*    DATE              NAME                      DESCRIPTION             */
65
/*                                                                        */
66
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
67
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
68
/*                                            resulting in version 6.1    */
69
/*                                                                        */
70
/**************************************************************************/
71
391
UINT  _ux_host_class_hid_instance_clean(UX_HOST_CLASS_HID *hid)
72
{
73
74
UX_HOST_CLASS_HID_PARSER     *hid_parser;
75
UX_HOST_CLASS_HID_REPORT     *hid_report;
76
UX_HOST_CLASS_HID_REPORT     *hid_next_report;
77
UX_HOST_CLASS_HID_FIELD      *hid_field;
78
UX_HOST_CLASS_HID_FIELD      *hid_next_field;
79
80
81
    /* Get the parser structure pointer.  */
82
391
    hid_parser =  &hid -> ux_host_class_hid_parser;
83
84
    /* Each report list of the parser should be cleaned: Input report.  */
85
391
    hid_report =  hid_parser -> ux_host_class_hid_parser_input_report;
86
686
    while (hid_report != UX_NULL)
87
    {
88
89
        /* Get the next report before we clean the current report.  */
90
295
        hid_next_report =  hid_report -> ux_host_class_hid_report_next_report;
91
92
        /* Get the first field in the report.  */
93
295
        hid_field =  hid_report -> ux_host_class_hid_report_field;
94
95
        /* Clean all the fields attached.  */
96
1075
        while (hid_field != UX_NULL)
97
        {
98
99
            /* Get the next field before we clean the current field.  */
100
780
            hid_next_field =  hid_field -> ux_host_class_hid_field_next_field;
101
102
            /* Free the usage table.  */
103
780
            if (hid_field -> ux_host_class_hid_field_usages != UX_NULL)
104
349
                _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages);
105
106
            /* Free the value table.  */
107
780
            if (hid_field -> ux_host_class_hid_field_values != UX_NULL)
108
780
                _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values);
109
110
            /* Now free the field memory.  */
111
780
            _ux_utility_memory_free(hid_field);
112
113
            /* Next field.  */
114
780
            hid_field =  hid_next_field;
115
        }
116
117
        /* Free the report.  */
118
295
        _ux_utility_memory_free(hid_report);
119
120
        /* Next report.  */
121
295
        hid_report =  hid_next_report;
122
    }
123
124
    /* Each report list of the parser should be cleaned: Output report.  */
125
391
    hid_report =  hid_parser -> ux_host_class_hid_parser_output_report;
126
566
    while (hid_report != UX_NULL)
127
    {
128
129
        /* Get the next report before we clean the current report.  */
130
175
        hid_next_report =  hid_report -> ux_host_class_hid_report_next_report;
131
132
        /* Get the first field in the report.  */
133
175
        hid_field =  hid_report -> ux_host_class_hid_report_field;
134
135
        /* Clean all the fields attached.  */
136
507
        while (hid_field != UX_NULL)
137
        {
138
139
            /* Get the next field before we clean the current field.  */
140
332
            hid_next_field =  hid_field -> ux_host_class_hid_field_next_field;
141
142
            /* Free the usage table.  */
143
332
            if (hid_field -> ux_host_class_hid_field_usages != UX_NULL)
144
169
                _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages);
145
146
            /* Free the value table.  */
147
332
            if (hid_field -> ux_host_class_hid_field_values != UX_NULL)
148
332
                _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values);
149
150
            /* Now free the field memory.  */
151
332
            _ux_utility_memory_free(hid_field);
152
153
            /* Next field.  */
154
332
            hid_field =  hid_next_field;
155
        }
156
157
        /* Free the report.  */
158
175
        _ux_utility_memory_free(hid_report);
159
160
        /* Next report.  */
161
175
        hid_report =  hid_next_report;
162
    }
163
164
    /* Each report list of the parser should be cleaned: Feature report.  */
165
391
    hid_report =  hid_parser -> ux_host_class_hid_parser_feature_report;
166
696
    while (hid_report != UX_NULL)
167
    {
168
169
        /* Get the next report before we clean the current report.  */
170
305
        hid_next_report =  hid_report -> ux_host_class_hid_report_next_report;
171
172
        /* Get the first field in the report.  */
173
305
        hid_field =  hid_report -> ux_host_class_hid_report_field;
174
175
        /* Clean all the fields attached.  */
176
592
        while (hid_field != UX_NULL)
177
        {
178
179
            /* Get the next field before we clean the current field.  */
180
287
            hid_next_field =  hid_field -> ux_host_class_hid_field_next_field;
181
182
            /* Free the usage table.  */
183
287
            if (hid_field -> ux_host_class_hid_field_usages != UX_NULL)
184
285
                _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages);
185
186
            /* Free the value table.  */
187
287
            if (hid_field -> ux_host_class_hid_field_values != UX_NULL)
188
287
                _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values);
189
190
            /* Now free the field memory.  */
191
287
            _ux_utility_memory_free(hid_field);
192
193
            /* Next field.  */
194
287
            hid_field =  hid_next_field;
195
        }
196
197
        /* Free the report.  */
198
305
        _ux_utility_memory_free(hid_report);
199
200
        /* Next report.  */
201
305
        hid_report =  hid_next_report;
202
    }
203
204
    /* Return successful completion.  */
205
391
    return(UX_SUCCESS);
206
}
207