If DMA safe memory was allocated, but the subsequent I2C transfer fails the memory is leaked. Plug this leak.
Unified · Split
| @@ -465,15 +465,18 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, · 464 unmodified lines | ||
| 465 | 465 | |
| 466 | 466 | status = i2c_transfer(adapter, msg, num); |
| 467 | 467 | if (status < 0) |
| 468 | − return status; | |
| 469 | − if (status != num) | |
| 470 | − return -EIO; | |
| 468 | + goto cleanup; | |
| 469 | + if (status != num) { | |
| 470 | + status = -EIO; | |
| 471 | + goto cleanup; | |
| 472 | + } | |
| 473 | + status = 0; | |
| 471 | 474 | |
| 472 | 475 | /* Check PEC if last message is a read */ |
| 473 | 476 | if (i && (msg[num-1].flags & I2C_M_RD)) { |
| 474 | 477 | status = i2c_smbus_check_pec(partial_pec, &msg[num-1]); |
| 475 | 478 | if (status < 0) |
| 476 | − return status; | |
| 479 | + goto cleanup; | |
| 477 | 480 | } |
| 478 | 481 | |
| 479 | 482 | if (read_write == I2C_SMBUS_READ) |
| @@ -499,12 +502,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, · 19 unmodified lines | ||
| 499 | 502 | break; |
| 500 | 503 | } |
| 501 | 504 | |
| 505 | +cleanup: | |
| 502 | 506 | if (msg[0].flags & I2C_M_DMA_SAFE) |
| 503 | 507 | kfree(msg[0].buf); |
| 504 | 508 | if (msg[1].flags & I2C_M_DMA_SAFE) |
| 505 | 509 | kfree(msg[1].buf); |
| 506 | 510 | |
| 507 | − return 0; | |
| 511 | + return status; | |
| 508 | 512 | } |
| 509 | 513 | |
| 510 | 514 | /** |