hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/net/usb/cdc_ncm.c
....@@ -180,9 +180,12 @@
180180 else
181181 min = ctx->max_datagram_size + ctx->max_ndp_size + sizeof(struct usb_cdc_ncm_nth32);
182182
183
- max = min_t(u32, CDC_NCM_NTB_MAX_SIZE_TX, le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize));
184
- if (max == 0)
183
+ if (le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) == 0)
185184 max = CDC_NCM_NTB_MAX_SIZE_TX; /* dwNtbOutMaxSize not set */
185
+ else
186
+ max = clamp_t(u32, le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize),
187
+ USB_CDC_NCM_NTB_MIN_OUT_SIZE,
188
+ CDC_NCM_NTB_MAX_SIZE_TX);
186189
187190 /* some devices set dwNtbOutMaxSize too low for the above default */
188191 min = min(min, max);
....@@ -1230,6 +1233,9 @@
12301233 * further.
12311234 */
12321235 if (skb_out == NULL) {
1236
+ /* If even the smallest allocation fails, abort. */
1237
+ if (ctx->tx_curr_size == USB_CDC_NCM_NTB_MIN_OUT_SIZE)
1238
+ goto alloc_failed;
12331239 ctx->tx_low_mem_max_cnt = min(ctx->tx_low_mem_max_cnt + 1,
12341240 (unsigned)CDC_NCM_LOW_MEM_MAX_CNT);
12351241 ctx->tx_low_mem_val = ctx->tx_low_mem_max_cnt;
....@@ -1248,13 +1254,8 @@
12481254 skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC);
12491255
12501256 /* No allocation possible so we will abort */
1251
- if (skb_out == NULL) {
1252
- if (skb != NULL) {
1253
- dev_kfree_skb_any(skb);
1254
- dev->net->stats.tx_dropped++;
1255
- }
1256
- goto exit_no_skb;
1257
- }
1257
+ if (!skb_out)
1258
+ goto alloc_failed;
12581259 ctx->tx_low_mem_val--;
12591260 }
12601261 if (ctx->is_ndp16) {
....@@ -1447,6 +1448,11 @@
14471448
14481449 return skb_out;
14491450
1451
+alloc_failed:
1452
+ if (skb) {
1453
+ dev_kfree_skb_any(skb);
1454
+ dev->net->stats.tx_dropped++;
1455
+ }
14501456 exit_no_skb:
14511457 /* Start timer, if there is a remaining non-empty skb */
14521458 if (ctx->tx_curr_skb != NULL && n > 0)