.. | .. |
---|
180 | 180 | else |
---|
181 | 181 | min = ctx->max_datagram_size + ctx->max_ndp_size + sizeof(struct usb_cdc_ncm_nth32); |
---|
182 | 182 | |
---|
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) |
---|
185 | 184 | 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); |
---|
186 | 189 | |
---|
187 | 190 | /* some devices set dwNtbOutMaxSize too low for the above default */ |
---|
188 | 191 | min = min(min, max); |
---|
.. | .. |
---|
1230 | 1233 | * further. |
---|
1231 | 1234 | */ |
---|
1232 | 1235 | 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; |
---|
1233 | 1239 | ctx->tx_low_mem_max_cnt = min(ctx->tx_low_mem_max_cnt + 1, |
---|
1234 | 1240 | (unsigned)CDC_NCM_LOW_MEM_MAX_CNT); |
---|
1235 | 1241 | ctx->tx_low_mem_val = ctx->tx_low_mem_max_cnt; |
---|
.. | .. |
---|
1248 | 1254 | skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC); |
---|
1249 | 1255 | |
---|
1250 | 1256 | /* 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; |
---|
1258 | 1259 | ctx->tx_low_mem_val--; |
---|
1259 | 1260 | } |
---|
1260 | 1261 | if (ctx->is_ndp16) { |
---|
.. | .. |
---|
1447 | 1448 | |
---|
1448 | 1449 | return skb_out; |
---|
1449 | 1450 | |
---|
| 1451 | +alloc_failed: |
---|
| 1452 | + if (skb) { |
---|
| 1453 | + dev_kfree_skb_any(skb); |
---|
| 1454 | + dev->net->stats.tx_dropped++; |
---|
| 1455 | + } |
---|
1450 | 1456 | exit_no_skb: |
---|
1451 | 1457 | /* Start timer, if there is a remaining non-empty skb */ |
---|
1452 | 1458 | if (ctx->tx_curr_skb != NULL && n > 0) |
---|