History

i2c: smbus: kill memory leak on emulated and failed DMA SMBus xfers

If DMA safe memory was allocated, but the subsequent I2C transfer fails the memory is leaked. Plug this leak.

Peter Rosin committed 8 years ago

Commit 9aa61361 parent 2173ed01 file · +9 −5Browse files

Unified · Split

drivers/i2c/i2c-core-smbus.c+9−5
@@ -465,15 +465,18 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, · 464 unmodified lines
465 465
466 status = i2c_transfer(adapter, msg, num);466 status = i2c_transfer(adapter, msg, num);
467 if (status < 0)467 if (status < 0)
468 return status;468 goto cleanup;
469 if (status != num)469 if (status != num) {
470 return -EIO;470 status = -EIO;
471 goto cleanup;
472 }
473 status = 0;
471 474
472 /* Check PEC if last message is a read */475 /* Check PEC if last message is a read */
473 if (i && (msg[num-1].flags & I2C_M_RD)) {476 if (i && (msg[num-1].flags & I2C_M_RD)) {
474 status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);477 status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
475 if (status < 0)478 if (status < 0)
476 return status;479 goto cleanup;
477 }480 }
478 481
479 if (read_write == I2C_SMBUS_READ)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 break;502 break;
500 }503 }
501 504
505cleanup:
502 if (msg[0].flags & I2C_M_DMA_SAFE)506 if (msg[0].flags & I2C_M_DMA_SAFE)
503 kfree(msg[0].buf);507 kfree(msg[0].buf);
504 if (msg[1].flags & I2C_M_DMA_SAFE)508 if (msg[1].flags & I2C_M_DMA_SAFE)
505 kfree(msg[1].buf);509 kfree(msg[1].buf);
506 510
507 return 0;511 return status;
508}512}
509 513
510/**514/**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t