Skip to content

Commit e680970

Browse files
committed
Merge tag 'thunderbolt-for-v5.13-rc4' of git://git.kernel.org/pub/scm/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
2 parents e752dbc + 22c7a18 commit e680970

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

drivers/thunderbolt/dma_port.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,15 @@ int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
366366
void *buf, size_t size)
367367
{
368368
unsigned int retries = DMA_PORT_RETRIES;
369-
unsigned int offset;
370-
371-
offset = address & 3;
372-
address = address & ~3;
373369

374370
do {
375-
u32 nbytes = min_t(u32, size, MAIL_DATA_DWORDS * 4);
371+
unsigned int offset;
372+
size_t nbytes;
376373
int ret;
377374

375+
offset = address & 3;
376+
nbytes = min_t(size_t, size + offset, MAIL_DATA_DWORDS * 4);
377+
378378
ret = dma_port_flash_read_block(dma, address, dma->buf,
379379
ALIGN(nbytes, 4));
380380
if (ret) {
@@ -386,6 +386,7 @@ int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
386386
return ret;
387387
}
388388

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

391392
size -= nbytes;

drivers/thunderbolt/usb4.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ static int usb4_do_read_data(u16 address, void *buf, size_t size,
6868
unsigned int retries = USB4_DATA_RETRIES;
6969
unsigned int offset;
7070

71-
offset = address & 3;
72-
address = address & ~3;
73-
7471
do {
75-
size_t nbytes = min_t(size_t, size, USB4_DATA_DWORDS * 4);
7672
unsigned int dwaddress, dwords;
7773
u8 data[USB4_DATA_DWORDS * 4];
74+
size_t nbytes;
7875
int ret;
7976

77+
offset = address & 3;
78+
nbytes = min_t(size_t, size + offset, USB4_DATA_DWORDS * 4);
79+
8080
dwaddress = address / 4;
8181
dwords = ALIGN(nbytes, 4) / 4;
8282

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

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

9293
size -= nbytes;

0 commit comments

Comments
 (0)