From de82a50b4e308af9d449fc77fc131bda0135ffb6 Mon Sep 17 00:00:00 2001 From: none Date: Mon, 1 Mar 2021 12:57:20 +0100 Subject: [PATCH 1/4] Set allocated memory to zero. --- ddbridge/ddbridge-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ddbridge/ddbridge-core.c b/ddbridge/ddbridge-core.c index 40f7cbc..4105c81 100644 --- a/ddbridge/ddbridge-core.c +++ b/ddbridge/ddbridge-core.c @@ -281,9 +281,9 @@ static int dma_alloc(struct pci_dev *pdev, struct ddb_dma *dma, int dir) for (i = 0; i < dma->num; i++) { if (alt_dma) { #if (KERNEL_VERSION(4, 13, 0) > LINUX_VERSION_CODE) - dma->vbuf[i] = kmalloc(dma->size, __GFP_REPEAT); + dma->vbuf[i] = kzalloc(dma->size, __GFP_REPEAT); #else - dma->vbuf[i] = kmalloc(dma->size, __GFP_RETRY_MAYFAIL); + dma->vbuf[i] = kzalloc(dma->size, __GFP_RETRY_MAYFAIL); #endif if (!dma->vbuf[i]) return -ENOMEM; @@ -301,7 +301,7 @@ static int dma_alloc(struct pci_dev *pdev, struct ddb_dma *dma, int dir) dma->vbuf[i] = dma_alloc_coherent(&pdev->dev, dma->size, &dma->pbuf[i], - GFP_KERNEL); + GFP_KERNEL | __GFP_ZERO); if (!dma->vbuf[i]) return -ENOMEM; } From 177e6b0fd6a96e7bc6d0db89cfc600c7fe96025e Mon Sep 17 00:00:00 2001 From: none Date: Mon, 1 Mar 2021 12:57:45 +0100 Subject: [PATCH 2/4] check if memory is aligned to 4K --- ddbridge/ddbridge-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ddbridge/ddbridge-core.c b/ddbridge/ddbridge-core.c index 4105c81..e29ecc4 100644 --- a/ddbridge/ddbridge-core.c +++ b/ddbridge/ddbridge-core.c @@ -305,6 +305,8 @@ static int dma_alloc(struct pci_dev *pdev, struct ddb_dma *dma, int dir) if (!dma->vbuf[i]) return -ENOMEM; } + if (((u64)dma->vbuf[i] & 0xfff)) + dev_err(&pdev->dev, "DMA memory at %px not aligned!\n", dma->vbuf[i]); } return 0; } From 9028e75f63858d28257e75b96322c99fd55b03ce Mon Sep 17 00:00:00 2001 From: none Date: Mon, 1 Mar 2021 12:58:21 +0100 Subject: [PATCH 3/4] always use unaligned processing if detected once --- ddbridge/ddbridge-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddbridge/ddbridge-core.c b/ddbridge/ddbridge-core.c index e29ecc4..af81e2e 100644 --- a/ddbridge/ddbridge-core.c +++ b/ddbridge/ddbridge-core.c @@ -2307,7 +2307,7 @@ static void input_write_dvb(struct ddb_input *input, dma2->vbuf[dma->cbuf], dma2->size); } else { - if (dma2->vbuf[dma->cbuf][0] != 0x47) { + if (dma2->unaligned || (dma2->vbuf[dma->cbuf][0] != 0x47)) { if (!dma2->unaligned) { dma2->unaligned++; dev_warn(dev->dev, "Input %u dma buffer unaligned, " From b025599e9f8ad1e725a449239fc7dd4029659324 Mon Sep 17 00:00:00 2001 From: none Date: Mon, 1 Mar 2021 12:58:54 +0100 Subject: [PATCH 4/4] dump more buffer bytes in case of misalignment --- ddbridge/ddbridge-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddbridge/ddbridge-core.c b/ddbridge/ddbridge-core.c index af81e2e..aeb6c08 100644 --- a/ddbridge/ddbridge-core.c +++ b/ddbridge/ddbridge-core.c @@ -2315,7 +2315,7 @@ static void input_write_dvb(struct ddb_input *input, input->nr); print_hex_dump(KERN_INFO, "TS: ", DUMP_PREFIX_OFFSET, 32, 1, dma2->vbuf[dma->cbuf], - 256, false); + 512, false); } dvb_dmx_swfilter(&dvb->demux, dma2->vbuf[dma->cbuf],