GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_device_stack_class_unregister.c Lines: 19 23 82.6 %
Date: 2026-03-06 18:57:10 Branches: 10 14 71.4 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   Device Stack                                                        */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
#define UX_SOURCE_CODE
24
25
26
/* Include necessary system files.  */
27
28
#include "ux_api.h"
29
#include "ux_device_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_device_stack_class_unregister                   PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function unregisters a slave class to the slave stack.         */
45
/*                                                                        */
46
/*    Note: The C string of class_name must be NULL-terminated and the    */
47
/*    length of it (without the NULL-terminator itself) must be no larger */
48
/*    than UX_MAX_CLASS_NAME_LENGTH.                                      */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    class_name                            Name of class                 */
53
/*    class_function_entry                  Class entry function          */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    Completion Status                                                   */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _ux_utility_string_length_check       Check C string and return     */
62
/*                                          its length if null-terminated */
63
/*    _ux_utility_memory_compare            Memory compare                */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application                                                         */
68
/*                                                                        */
69
/**************************************************************************/
70
317
UINT  _ux_device_stack_class_unregister(UCHAR *class_name,
71
                        UINT (*class_entry_function)(struct UX_SLAVE_CLASS_COMMAND_STRUCT *))
72
{
73
74
UX_SLAVE_CLASS              *class_inst;
75
UINT                        status;
76
UX_SLAVE_CLASS_COMMAND      command;
77
#if !defined(UX_NAME_REFERENCED_BY_POINTER)
78
317
UINT                        class_name_length =  0;
79
#endif
80
#if UX_MAX_SLAVE_CLASS_DRIVER > 1
81
ULONG                       class_index;
82
#endif
83
84
85
    /* If trace is enabled, insert this event into the trace buffer.  */
86
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_CLASS_UNREGISTER, class_name, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
87
88
#if !defined(UX_NAME_REFERENCED_BY_POINTER)
89
    /* Get the length of the class name (exclude null-terminator).  */
90
317
    status =  _ux_utility_string_length_check(class_name, &class_name_length, UX_MAX_CLASS_NAME_LENGTH);
91
317
    if (status)
92
1
        return(status);
93
#endif
94
95
316
    class_inst =  _ux_system_slave -> ux_system_slave_class_array;
96
97
#if UX_MAX_SLAVE_CLASS_DRIVER > 1
98
    /* We need to parse the class table to find the right class.  */
99
498
    for (class_index = 0; class_index < _ux_system_slave -> ux_system_slave_max_class; class_index++)
100
    {
101
#endif
102
103
        /* Check if this class is the right one.  */
104
453
        if (class_inst -> ux_slave_class_status == UX_USED)
105
        {
106
107
            /* We have found a used container with a  class. Compare the name (include null-terminator).  */
108
273
            if (ux_utility_name_match(class_inst -> ux_slave_class_name, class_name, class_name_length + 1))
109
            {
110
111
                /* Build all the fields of the Class Command to uninitialize the class.  */
112
271
                command.ux_slave_class_command_request    =  UX_SLAVE_CLASS_COMMAND_UNINITIALIZE;
113
271
                command.ux_slave_class_command_class_ptr  =  class_inst;
114
115
                /* Call the class uninitialization routine.  */
116
271
                status = class_entry_function(&command);
117
118
                /* Check the status.  */
119
271
                if (status != UX_SUCCESS)
120
1
                    return(status);
121
122
                /* Make this class unused now.  */
123
270
                class_inst -> ux_slave_class_status = UX_UNUSED;
124
125
                /* Erase the instance of the class.  */
126
270
                class_inst -> ux_slave_class_instance = UX_NULL;
127
128
                /* Return successful completion.  */
129
270
                return(UX_SUCCESS);
130
            }
131
        }
132
133
#if UX_MAX_SLAVE_CLASS_DRIVER > 1
134
        /* Move to the next class.  */
135
182
        class_inst ++;
136
    }
137
#endif
138
139
    /* No class match.  */
140
45
    return(UX_NO_CLASS_MATCH);
141
}
142
143
144
/**************************************************************************/
145
/*                                                                        */
146
/*  FUNCTION                                               RELEASE        */
147
/*                                                                        */
148
/*    _uxe_device_stack_class_unregister                  PORTABLE C      */
149
/*                                                           6.3.0        */
150
/*  AUTHOR                                                                */
151
/*                                                                        */
152
/*    Chaoqiong Xiao, Microsoft Corporation                               */
153
/*                                                                        */
154
/*  DESCRIPTION                                                           */
155
/*                                                                        */
156
/*    This function checks errors in device stack class unregister        */
157
/*    function call.                                                      */
158
/*                                                                        */
159
/*  INPUT                                                                 */
160
/*                                                                        */
161
/*    class_name                            Name of class                 */
162
/*    class_function_entry                  Class entry function          */
163
/*                                                                        */
164
/*  OUTPUT                                                                */
165
/*                                                                        */
166
/*    None                                                                */
167
/*                                                                        */
168
/*  CALLS                                                                 */
169
/*                                                                        */
170
/*    _ux_device_stack_class_unregister     Class unregister              */
171
/*                                                                        */
172
/*  CALLED BY                                                             */
173
/*                                                                        */
174
/*    Application                                                         */
175
/*                                                                        */
176
/**************************************************************************/
177
UINT  _uxe_device_stack_class_unregister(UCHAR *class_name,
178
                        UINT (*class_entry_function)(struct UX_SLAVE_CLASS_COMMAND_STRUCT *))
179
{
180
181
    /* Sanity checks.  */
182
    if ((class_name == UX_NULL) || (class_entry_function == UX_NULL))
183
        return(UX_INVALID_PARAMETER);
184
185
    /* Invoke unregister function.  */
186
    return(_ux_device_stack_class_unregister(class_name, class_entry_function));
187
}