GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_class_instance_verify.c Lines: 16 16 100.0 %
Date: 2026-03-06 18:57:10 Branches: 12 12 100.0 %

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
/**   Host Stack                                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
24
/* Include necessary system files.  */
25
26
#define UX_SOURCE_CODE
27
28
#include "ux_api.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_stack_class_instance_verify                PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function ensures that a given instance exists. An application  */
45
/*    is not responsible for keeping the instance valid pointer. The      */
46
/*    class is responsible for the instance checks if the instance is     */
47
/*    still valid.                                                        */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    class_name                            Name of class                 */
52
/*    class_instance                        Pointer to class instance     */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    Completion Status                                                   */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _ux_utility_string_length_check       Check C string and return its */
61
/*                                          length if null-terminated     */
62
/*    _ux_utility_memory_compare            Compare blocks of memory      */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    USBX Components                                                     */
67
/*                                                                        */
68
/**************************************************************************/
69
7048
UINT  _ux_host_stack_class_instance_verify(UCHAR *class_name, VOID *class_instance)
70
{
71
72
UX_HOST_CLASS   *class_inst;
73
#if UX_MAX_CLASS_DRIVER > 1
74
ULONG           class_index;
75
#endif
76
VOID            **current_class_instance;
77
#if !defined(UX_NAME_REFERENCED_BY_POINTER)
78
UINT            status;
79
7048
UINT            class_name_length =  0;
80
#endif
81
82
#if !defined(UX_NAME_REFERENCED_BY_POINTER)
83
    /* Get the length of the class name (exclude null-terminator).  */
84
7048
    status =  _ux_utility_string_length_check(class_name, &class_name_length, UX_MAX_CLASS_NAME_LENGTH);
85
7048
    if (status)
86
1
        return(status);
87
#endif
88
89
    /* Get first class.  */
90
7047
    class_inst =  _ux_system_host -> ux_system_host_class_array;
91
92
#if UX_MAX_CLASS_DRIVER > 1
93
    /* We need to parse the class table.  */
94
7229
    for(class_index = 0; class_index < _ux_system_host -> ux_system_host_max_class; class_index++)
95
    {
96
#endif
97
98
        /* Check if this class is already used.  */
99
7210
        if (class_inst -> ux_host_class_status == UX_USED)
100
        {
101
102
            /* Start with the first class instance attached to the class container.  */
103
7074
            current_class_instance =  class_inst -> ux_host_class_first_instance;
104
105
            /* Traverse the list of the class instances until we find the correct instance.  */
106
7279
            while (current_class_instance != UX_NULL)
107
            {
108
109
                /* Check the class instance attached to the container with the caller's
110
                   instance.  */
111
7233
                if (current_class_instance == class_instance)
112
                {
113
114
                    /* We have found the class container. Check if this is the one we need (compare including null-terminator).  */
115
7029
                    if (ux_utility_name_match(class_inst-> ux_host_class_name, class_name, class_name_length + 1))
116
7028
                        return(UX_SUCCESS);
117
                }
118
119
                /* Points to the next class instance.  */
120
205
                current_class_instance =  *current_class_instance;
121
            }
122
        }
123
#if UX_MAX_CLASS_DRIVER > 1
124
125
        /* Move to the next class.  */
126
182
        class_inst ++;
127
    }
128
#endif
129
130
    /* If trace is enabled, insert this event into the trace buffer.  */
131
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, class_instance, 0, 0, UX_TRACE_ERRORS, 0, 0)
132
133
    /* This class does not exist.  */
134
19
    return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
135
}