@@ -1861,14 +1861,21 @@ static u16 atl1_alloc_rx_buffers(struct atl1_adapter *adapter)
1861
1861
break ;
1862
1862
}
1863
1863
1864
- buffer_info -> alloced = 1 ;
1865
- buffer_info -> skb = skb ;
1866
- buffer_info -> length = (u16 ) adapter -> rx_buffer_len ;
1867
1864
page = virt_to_page (skb -> data );
1868
1865
offset = offset_in_page (skb -> data );
1869
1866
buffer_info -> dma = dma_map_page (& pdev -> dev , page , offset ,
1870
1867
adapter -> rx_buffer_len ,
1871
1868
DMA_FROM_DEVICE );
1869
+ if (dma_mapping_error (& pdev -> dev , buffer_info -> dma )) {
1870
+ kfree_skb (skb );
1871
+ adapter -> soft_stats .rx_dropped ++ ;
1872
+ break ;
1873
+ }
1874
+
1875
+ buffer_info -> alloced = 1 ;
1876
+ buffer_info -> skb = skb ;
1877
+ buffer_info -> length = (u16 )adapter -> rx_buffer_len ;
1878
+
1872
1879
rfd_desc -> buffer_addr = cpu_to_le64 (buffer_info -> dma );
1873
1880
rfd_desc -> buf_len = cpu_to_le16 (adapter -> rx_buffer_len );
1874
1881
rfd_desc -> coalese = 0 ;
@@ -2183,8 +2190,8 @@ static int atl1_tx_csum(struct atl1_adapter *adapter, struct sk_buff *skb,
2183
2190
return 0 ;
2184
2191
}
2185
2192
2186
- static void atl1_tx_map (struct atl1_adapter * adapter , struct sk_buff * skb ,
2187
- struct tx_packet_desc * ptpd )
2193
+ static bool atl1_tx_map (struct atl1_adapter * adapter , struct sk_buff * skb ,
2194
+ struct tx_packet_desc * ptpd )
2188
2195
{
2189
2196
struct atl1_tpd_ring * tpd_ring = & adapter -> tpd_ring ;
2190
2197
struct atl1_buffer * buffer_info ;
@@ -2194,13 +2201,15 @@ static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
2194
2201
unsigned int nr_frags ;
2195
2202
unsigned int f ;
2196
2203
int retval ;
2204
+ u16 first_mapped ;
2197
2205
u16 next_to_use ;
2198
2206
u16 data_len ;
2199
2207
u8 hdr_len ;
2200
2208
2201
2209
buf_len -= skb -> data_len ;
2202
2210
nr_frags = skb_shinfo (skb )-> nr_frags ;
2203
2211
next_to_use = atomic_read (& tpd_ring -> next_to_use );
2212
+ first_mapped = next_to_use ;
2204
2213
buffer_info = & tpd_ring -> buffer_info [next_to_use ];
2205
2214
BUG_ON (buffer_info -> skb );
2206
2215
/* put skb in last TPD */
@@ -2216,6 +2225,8 @@ static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
2216
2225
buffer_info -> dma = dma_map_page (& adapter -> pdev -> dev , page ,
2217
2226
offset , hdr_len ,
2218
2227
DMA_TO_DEVICE );
2228
+ if (dma_mapping_error (& adapter -> pdev -> dev , buffer_info -> dma ))
2229
+ goto dma_err ;
2219
2230
2220
2231
if (++ next_to_use == tpd_ring -> count )
2221
2232
next_to_use = 0 ;
@@ -2242,6 +2253,9 @@ static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
2242
2253
page , offset ,
2243
2254
buffer_info -> length ,
2244
2255
DMA_TO_DEVICE );
2256
+ if (dma_mapping_error (& adapter -> pdev -> dev ,
2257
+ buffer_info -> dma ))
2258
+ goto dma_err ;
2245
2259
if (++ next_to_use == tpd_ring -> count )
2246
2260
next_to_use = 0 ;
2247
2261
}
@@ -2254,6 +2268,8 @@ static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
2254
2268
buffer_info -> dma = dma_map_page (& adapter -> pdev -> dev , page ,
2255
2269
offset , buf_len ,
2256
2270
DMA_TO_DEVICE );
2271
+ if (dma_mapping_error (& adapter -> pdev -> dev , buffer_info -> dma ))
2272
+ goto dma_err ;
2257
2273
if (++ next_to_use == tpd_ring -> count )
2258
2274
next_to_use = 0 ;
2259
2275
}
@@ -2277,6 +2293,9 @@ static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
2277
2293
buffer_info -> dma = skb_frag_dma_map (& adapter -> pdev -> dev ,
2278
2294
frag , i * ATL1_MAX_TX_BUF_LEN ,
2279
2295
buffer_info -> length , DMA_TO_DEVICE );
2296
+ if (dma_mapping_error (& adapter -> pdev -> dev ,
2297
+ buffer_info -> dma ))
2298
+ goto dma_err ;
2280
2299
2281
2300
if (++ next_to_use == tpd_ring -> count )
2282
2301
next_to_use = 0 ;
@@ -2285,6 +2304,22 @@ static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
2285
2304
2286
2305
/* last tpd's buffer-info */
2287
2306
buffer_info -> skb = skb ;
2307
+
2308
+ return true;
2309
+
2310
+ dma_err :
2311
+ while (first_mapped != next_to_use ) {
2312
+ buffer_info = & tpd_ring -> buffer_info [first_mapped ];
2313
+ dma_unmap_page (& adapter -> pdev -> dev ,
2314
+ buffer_info -> dma ,
2315
+ buffer_info -> length ,
2316
+ DMA_TO_DEVICE );
2317
+ buffer_info -> dma = 0 ;
2318
+
2319
+ if (++ first_mapped == tpd_ring -> count )
2320
+ first_mapped = 0 ;
2321
+ }
2322
+ return false;
2288
2323
}
2289
2324
2290
2325
static void atl1_tx_queue (struct atl1_adapter * adapter , u16 count ,
@@ -2355,10 +2390,8 @@ static netdev_tx_t atl1_xmit_frame(struct sk_buff *skb,
2355
2390
2356
2391
len = skb_headlen (skb );
2357
2392
2358
- if (unlikely (skb -> len <= 0 )) {
2359
- dev_kfree_skb_any (skb );
2360
- return NETDEV_TX_OK ;
2361
- }
2393
+ if (unlikely (skb -> len <= 0 ))
2394
+ goto drop_packet ;
2362
2395
2363
2396
nr_frags = skb_shinfo (skb )-> nr_frags ;
2364
2397
for (f = 0 ; f < nr_frags ; f ++ ) {
@@ -2371,10 +2404,9 @@ static netdev_tx_t atl1_xmit_frame(struct sk_buff *skb,
2371
2404
if (mss ) {
2372
2405
if (skb -> protocol == htons (ETH_P_IP )) {
2373
2406
proto_hdr_len = skb_tcp_all_headers (skb );
2374
- if (unlikely (proto_hdr_len > len )) {
2375
- dev_kfree_skb_any (skb );
2376
- return NETDEV_TX_OK ;
2377
- }
2407
+ if (unlikely (proto_hdr_len > len ))
2408
+ goto drop_packet ;
2409
+
2378
2410
/* need additional TPD ? */
2379
2411
if (proto_hdr_len != len )
2380
2412
count += (len - proto_hdr_len +
@@ -2406,23 +2438,26 @@ static netdev_tx_t atl1_xmit_frame(struct sk_buff *skb,
2406
2438
}
2407
2439
2408
2440
tso = atl1_tso (adapter , skb , ptpd );
2409
- if (tso < 0 ) {
2410
- dev_kfree_skb_any (skb );
2411
- return NETDEV_TX_OK ;
2412
- }
2441
+ if (tso < 0 )
2442
+ goto drop_packet ;
2413
2443
2414
2444
if (!tso ) {
2415
2445
ret_val = atl1_tx_csum (adapter , skb , ptpd );
2416
- if (ret_val < 0 ) {
2417
- dev_kfree_skb_any (skb );
2418
- return NETDEV_TX_OK ;
2419
- }
2446
+ if (ret_val < 0 )
2447
+ goto drop_packet ;
2420
2448
}
2421
2449
2422
- atl1_tx_map (adapter , skb , ptpd );
2450
+ if (!atl1_tx_map (adapter , skb , ptpd ))
2451
+ goto drop_packet ;
2452
+
2423
2453
atl1_tx_queue (adapter , count , ptpd );
2424
2454
atl1_update_mailbox (adapter );
2425
2455
return NETDEV_TX_OK ;
2456
+
2457
+ drop_packet :
2458
+ adapter -> soft_stats .tx_errors ++ ;
2459
+ dev_kfree_skb_any (skb );
2460
+ return NETDEV_TX_OK ;
2426
2461
}
2427
2462
2428
2463
static int atl1_rings_clean (struct napi_struct * napi , int budget )
0 commit comments