Skip to content

Commit

Permalink
Merge tag 'thunderbolt-for-v5.13-rc4' of git://git.kernel.org/pub/scm…
Browse files Browse the repository at this point in the history
…/linux/kernel/git/westeri/thunderbolt into usb-linus

Mika writes:

thunderbolt: Fixes for v5.13-rc4

This includes two fixes from Mathias to handle NVM read side properly in
certain situations.

Both have been in linux-next with no reported issues.

* tag 'thunderbolt-for-v5.13-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt:
  thunderbolt: usb4: Fix NVM read buffer bounds and offset issue
  thunderbolt: dma_port: Fix NVM read buffer bounds and offset issue
  • Loading branch information
Greg Kroah-Hartman committed May 24, 2021
2 parents e752dbc + 22c7a18 commit e680970
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions drivers/thunderbolt/dma_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
void *buf, size_t size)
{
unsigned int retries = DMA_PORT_RETRIES;
unsigned int offset;

offset = address & 3;
address = address & ~3;

do {
u32 nbytes = min_t(u32, size, MAIL_DATA_DWORDS * 4);
unsigned int offset;
size_t nbytes;
int ret;

offset = address & 3;
nbytes = min_t(size_t, size + offset, MAIL_DATA_DWORDS * 4);

ret = dma_port_flash_read_block(dma, address, dma->buf,
ALIGN(nbytes, 4));
if (ret) {
Expand All @@ -386,6 +386,7 @@ int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
return ret;
}

nbytes -= offset;
memcpy(buf, dma->buf + offset, nbytes);

size -= nbytes;
Expand Down
9 changes: 5 additions & 4 deletions drivers/thunderbolt/usb4.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ static int usb4_do_read_data(u16 address, void *buf, size_t size,
unsigned int retries = USB4_DATA_RETRIES;
unsigned int offset;

offset = address & 3;
address = address & ~3;

do {
size_t nbytes = min_t(size_t, size, USB4_DATA_DWORDS * 4);
unsigned int dwaddress, dwords;
u8 data[USB4_DATA_DWORDS * 4];
size_t nbytes;
int ret;

offset = address & 3;
nbytes = min_t(size_t, size + offset, USB4_DATA_DWORDS * 4);

dwaddress = address / 4;
dwords = ALIGN(nbytes, 4) / 4;

Expand All @@ -87,6 +87,7 @@ static int usb4_do_read_data(u16 address, void *buf, size_t size,
return ret;
}

nbytes -= offset;
memcpy(buf, data + offset, nbytes);

size -= nbytes;
Expand Down

0 comments on commit e680970

Please sign in to comment.