From 89949decfd9a0f86427b502aae4fbc3a3ef399f0 Mon Sep 17 00:00:00 2001 From: Ansuel Smith Date: Tue, 23 Jun 2020 19:50:28 +0200 Subject: [PATCH] Fix Kernel Panic dma with NULL dev --- nss_coredump.c | 4 ++-- nss_log.c | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/nss_coredump.c b/nss_coredump.c index aa4ba82..957eca0 100644 --- a/nss_coredump.c +++ b/nss_coredump.c @@ -154,7 +154,7 @@ void nss_fw_coredump_notify(struct nss_ctx_instance *nss_own, dma_addr = nss_own->meminfo_ctx.logbuffer_dma; } - dma_sync_single_for_cpu(NULL, dma_addr, sizeof(struct nss_log_descriptor), DMA_FROM_DEVICE); + dma_sync_single_for_cpu(nss_own->dev, dma_addr, sizeof(struct nss_log_descriptor), DMA_FROM_DEVICE); /* * If the current entry is smaller than or equal to the number of NSS_LOG_COREDUMP_LINE_NUM, @@ -181,7 +181,7 @@ void nss_fw_coredump_notify(struct nss_ctx_instance *nss_own, offset = (index * sizeof(struct nss_log_entry)) + offsetof(struct nss_log_descriptor, log_ring_buffer); - dma_sync_single_for_cpu(NULL, dma_addr + offset, + dma_sync_single_for_cpu(nss_own->dev, dma_addr + offset, sizeof(struct nss_log_entry), DMA_FROM_DEVICE); nss_info_always("%p: %s\n", nss_own, nle_print->message); nle_print++; diff --git a/nss_log.c b/nss_log.c index 06ebba4..f9bd6c8 100644 --- a/nss_log.c +++ b/nss_log.c @@ -44,6 +44,7 @@ struct nss_log_data { uint32_t last_entry; /* Last known sampled entry (or index) */ uint32_t nentries; /* Caches the total number of entries of log buffer */ int nss_id; /* NSS Core id being used */ + struct device *nss_dev; }; struct nss_log_ring_buffer_addr nss_rbe[NSS_MAX_CORES]; @@ -125,6 +126,7 @@ static int nss_log_open(struct inode *inode, struct file *filp) data->last_entry = 0; data->nentries = nss_rbe[nss_id].nentries; data->dma_addr = nss_rbe[nss_id].dma_addr; + data->nss_dev = nss_ctx->dev; /* * Increment the reference count so that we don't free @@ -207,7 +209,7 @@ static ssize_t nss_log_read(struct file *filp, char __user *buf, size_t size, lo /* * Get the current index */ - dma_sync_single_for_cpu(NULL, data->dma_addr, sizeof(struct nss_log_descriptor), DMA_FROM_DEVICE); + dma_sync_single_for_cpu(data->nss_dev, data->dma_addr, sizeof(struct nss_log_descriptor), DMA_FROM_DEVICE); entry = nss_log_current_entry(desc); /* @@ -251,7 +253,7 @@ static ssize_t nss_log_read(struct file *filp, char __user *buf, size_t size, lo offset = (offset * sizeof(struct nss_log_entry)) + offsetof(struct nss_log_descriptor, log_ring_buffer); - dma_sync_single_for_cpu(NULL, data->dma_addr + offset, + dma_sync_single_for_cpu(data->nss_dev, data->dma_addr + offset, sizeof(struct nss_log_entry), DMA_FROM_DEVICE); rb = &desc->log_ring_buffer[index]; @@ -510,7 +512,7 @@ bool nss_debug_log_buffer_alloc(uint8_t nss_id, uint32_t nentry) return true; fail: - dma_unmap_single(NULL, dma_addr, size, DMA_FROM_DEVICE); + dma_unmap_single(nss_ctx->dev, dma_addr, size, DMA_FROM_DEVICE); kfree(addr); wake_up(&nss_log_wq); return false; -- 2.27.0