[module] cosmetics

This commit is contained in:
Geoffrey McRae 2022-11-07 11:46:35 +11:00
parent 8e706636d3
commit d09a10299e

View File

@ -124,7 +124,8 @@ err:
return ERR_PTR(ret); return ERR_PTR(ret);
} }
static void unmap_kvmfrbuf(struct dma_buf_attachment * at, struct sg_table * sg, enum dma_data_direction direction) static void unmap_kvmfrbuf(struct dma_buf_attachment * at, struct sg_table * sg,
enum dma_data_direction direction)
{ {
dma_unmap_sg(at->dev, sg->sgl, sg->nents, direction); dma_unmap_sg(at->dev, sg->sgl, sg->nents, direction);
sg_free_table(sg); sg_free_table(sg);
@ -144,7 +145,8 @@ static int mmap_kvmfrbuf(struct dma_buf * buf, struct vm_area_struct * vma)
unsigned long size = vma->vm_end - vma->vm_start; unsigned long size = vma->vm_end - vma->vm_start;
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
if ((offset + size > (kbuf->pagecount << PAGE_SHIFT)) || (offset + size < offset)) if ((offset + size > (kbuf->pagecount << PAGE_SHIFT))
|| (offset + size < offset))
return -EINVAL; return -EINVAL;
if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
@ -158,7 +160,8 @@ static int mmap_kvmfrbuf(struct dma_buf * buf, struct vm_area_struct * vma)
return 0; return 0;
case KVMFR_TYPE_STATIC: case KVMFR_TYPE_STATIC:
return remap_vmalloc_range(vma, kbuf->kdev->addr + kbuf->offset, vma->vm_pgoff); return remap_vmalloc_range(vma, kbuf->kdev->addr + kbuf->offset,
vma->vm_pgoff);
default: default:
return -EINVAL; return -EINVAL;
@ -173,7 +176,8 @@ static const struct dma_buf_ops kvmfrbuf_ops =
.mmap = mmap_kvmfrbuf .mmap = mmap_kvmfrbuf
}; };
static long kvmfr_dmabuf_create(struct kvmfr_dev * kdev, struct file * filp, unsigned long arg) static long kvmfr_dmabuf_create(struct kvmfr_dev * kdev, struct file * filp,
unsigned long arg)
{ {
struct kvmfr_dmabuf_create create; struct kvmfr_dmabuf_create create;
DEFINE_DMA_BUF_EXPORT_INFO(exp_kdev); DEFINE_DMA_BUF_EXPORT_INFO(exp_kdev);
@ -194,7 +198,8 @@ static long kvmfr_dmabuf_create(struct kvmfr_dev * kdev, struct file * filp, uns
return -EINVAL; return -EINVAL;
} }
if ((create.offset + create.size > kdev->size) || (create.offset + create.size < create.offset)) if ((create.offset + create.size > kdev->size) ||
(create.offset + create.size < create.offset))
return -EINVAL; return -EINVAL;
kbuf = kzalloc(sizeof(struct kvmfrbuf), GFP_KERNEL); kbuf = kzalloc(sizeof(struct kvmfrbuf), GFP_KERNEL);
@ -204,7 +209,8 @@ static long kvmfr_dmabuf_create(struct kvmfr_dev * kdev, struct file * filp, uns
kbuf->kdev = kdev; kbuf->kdev = kdev;
kbuf->pagecount = create.size >> PAGE_SHIFT; kbuf->pagecount = create.size >> PAGE_SHIFT;
kbuf->offset = create.offset; kbuf->offset = create.offset;
kbuf->pages = kmalloc_array(kbuf->pagecount, sizeof(*kbuf->pages), GFP_KERNEL); kbuf->pages = kmalloc_array(kbuf->pagecount, sizeof(*kbuf->pages),
GFP_KERNEL);
if (!kbuf->pages) if (!kbuf->pages)
{ {
ret = -ENOMEM; ret = -ENOMEM;
@ -244,7 +250,8 @@ static long kvmfr_dmabuf_create(struct kvmfr_dev * kdev, struct file * filp, uns
goto err; goto err;
} }
printk("kvmfr_dmabuf_create: offset: %llu, size: %llu\n", create.offset, create.size); printk("kvmfr_dmabuf_create: offset: %llu, size: %llu\n",
create.offset, create.size);
return dma_buf_fd(buf, create.flags & KVMFR_DMABUF_FLAG_CLOEXEC ? O_CLOEXEC : 0); return dma_buf_fd(buf, create.flags & KVMFR_DMABUF_FLAG_CLOEXEC ? O_CLOEXEC : 0);
err: err:
@ -253,7 +260,8 @@ err:
return ret; return ret;
} }
static long device_ioctl(struct file * filp, unsigned int ioctl, unsigned long arg) static long device_ioctl(struct file * filp, unsigned int ioctl,
unsigned long arg)
{ {
struct kvmfr_dev * kdev; struct kvmfr_dev * kdev;
long ret; long ret;
@ -359,7 +367,8 @@ static int kvmfr_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
mutex_unlock(&minor_lock); mutex_unlock(&minor_lock);
kdev->devNo = MKDEV(kvmfr->major, kdev->minor); kdev->devNo = MKDEV(kvmfr->major, kdev->minor);
kdev->pDev = device_create(kvmfr->pClass, NULL, kdev->devNo, NULL, KVMFR_DEV_NAME "%d", kdev->minor); kdev->pDev = device_create(kvmfr->pClass, NULL, kdev->devNo, NULL,
KVMFR_DEV_NAME "%d", kdev->minor);
if (IS_ERR(kdev->pDev)) if (IS_ERR(kdev->pDev))
goto out_unminor; goto out_unminor;
@ -451,7 +460,9 @@ static int create_static_device_unlocked(int size_mb)
kdev->addr = vmalloc_user(kdev->size); kdev->addr = vmalloc_user(kdev->size);
if (!kdev->addr) if (!kdev->addr)
{ {
printk(KERN_ERR "kvmfr: failed to allocate memory for static device: %d MiB\n", size_mb); printk(
KERN_ERR "kvmfr: failed to allocate memory for static device: %d MiB\n",
size_mb);
ret = -ENOMEM; ret = -ENOMEM;
goto out_free; goto out_free;
} }
@ -461,7 +472,8 @@ static int create_static_device_unlocked(int size_mb)
goto out_release; goto out_release;
kdev->devNo = MKDEV(kvmfr->major, kdev->minor); kdev->devNo = MKDEV(kvmfr->major, kdev->minor);
kdev->pDev = device_create(kvmfr->pClass, NULL, kdev->devNo, NULL, KVMFR_DEV_NAME "%d", kdev->minor); kdev->pDev = device_create(kvmfr->pClass, NULL, kdev->devNo, NULL,
KVMFR_DEV_NAME "%d", kdev->minor);
if (IS_ERR(kdev->pDev)) if (IS_ERR(kdev->pDev))
goto out_unminor; goto out_unminor;