@@ -157,49 +157,42 @@ static int lb_request_handler(struct usbd_class_data *const c_data,
157
157
{
158
158
struct udc_buf_info * bi = (struct udc_buf_info * )net_buf_user_data (buf );
159
159
struct lb_data * data = usbd_class_get_private (c_data );
160
-
161
- LOG_DBG ( "Transfer finished %s -> ep 0x%02x, len %u, err %d" ,
162
- c_data -> name , bi -> ep , buf -> len , err ) ;
160
+ const size_t len = buf -> len ;
161
+ const uint8_t ep = bi -> ep ;
162
+ int ret = 0 ;
163
163
164
164
if (bi -> ep == lb_get_bulk_out (c_data )) {
165
165
atomic_clear_bit (& data -> state , LB_FUNCTION_OUT_ENGAGED );
166
+ if (err == 0 ) {
167
+ memcpy (lb_buf , buf -> data , MIN (sizeof (lb_buf ), buf -> len ));
168
+ }
166
169
}
167
170
168
171
if (bi -> ep == lb_get_bulk_in (c_data )) {
169
172
atomic_clear_bit (& data -> state , LB_FUNCTION_IN_ENGAGED );
170
173
}
171
174
172
- if (err ) {
173
- if (err == - ECONNABORTED ) {
174
- LOG_INF ("request ep 0x%02x, len %u cancelled" ,
175
- bi -> ep , buf -> len );
176
- } else {
177
- LOG_ERR ("request ep 0x%02x, len %u failed" ,
178
- bi -> ep , buf -> len );
179
- }
180
-
181
- net_buf_unref (buf );
182
-
183
- return err ;
175
+ net_buf_unref (buf );
176
+ if (err == - ECONNABORTED ) {
177
+ LOG_INF ("Transfer ep 0x%02x, len %u cancelled" , ep , len );
178
+ } else if (err != 0 ) {
179
+ LOG_ERR ("Transfer ep 0x%02x, len %u failed" , ep , len );
180
+ ret = err ;
181
+ } else {
182
+ LOG_DBG ("Transfer ep 0x%02x, len %u finished" , ep , len );
184
183
}
185
184
186
- if (bi -> ep == lb_get_bulk_out (c_data )) {
187
- memcpy (lb_buf , buf -> data , MIN (sizeof (lb_buf ), buf -> len ));
188
- net_buf_unref (buf );
189
- if (!atomic_test_bit (& data -> state , LB_FUNCTION_BULK_MANUAL )) {
185
+ if (!atomic_test_bit (& data -> state , LB_FUNCTION_BULK_MANUAL )) {
186
+ if (ep == lb_get_bulk_out (c_data )) {
190
187
lb_submit_bulk_out (c_data );
191
188
}
192
- }
193
189
194
- if (bi -> ep == lb_get_bulk_in (c_data )) {
195
- bi -> ep = lb_get_bulk_out (c_data );
196
- net_buf_unref (buf );
197
- if (!atomic_test_bit (& data -> state , LB_FUNCTION_BULK_MANUAL )) {
190
+ if (ep == lb_get_bulk_in (c_data )) {
198
191
lb_submit_bulk_in (c_data );
199
192
}
200
193
}
201
194
202
- return 0 ;
195
+ return ret ;
203
196
}
204
197
205
198
static void lb_update (struct usbd_class_data * c_data ,
0 commit comments