参照元

説明

引数

返り値

参考

実装

/**
 * dma_buf_mmap - Setup up a userspace mmap with the given vma
 * @dmabuf:     [in]    buffer that should back the vma
 * @vma:        [in]    vma for the mmap
 * @pgoff:      [in]    offset in pages where this mmap should start within the
 *                      dma-buf buffer.
 *
 * This function adjusts the passed in vma so that it points at the file of the
 * dma_buf operation. It also adjusts the starting pgoff and does bounds
 * checking on the size of the vma. Then it calls the exporters mmap function to
 * set up the mapping.
 *
 * Can return negative error values, returns 0 on success.
 */
int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
                 unsigned long pgoff)
{
        struct file *oldfile;
        int ret;
        if (WARN_ON(!dmabuf || !vma))
                return -EINVAL;
        /* check for offset overflow */
        if (pgoff + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) < pgoff)
                return -EOVERFLOW;

        /* check for overflowing the buffer's size */
        if (pgoff + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) >
            dmabuf->size >> PAGE_SHIFT)
                return -EINVAL;
        /* readjust the vma */
        get_file(dmabuf->file);
        oldfile = vma->vm_file;
        vma->vm_file = dmabuf->file;
        vma->vm_pgoff = pgoff;
        ret = dmabuf->ops->mmap(dmabuf, vma);
        if (ret) {
                /* restore old parameters on failure */
                vma->vm_file = oldfile;
                fput(dmabuf->file);
        } else {
                if (oldfile)
                        fput(oldfile);
        }
        return ret;

}
EXPORT_SYMBOL_GPL(dma_buf_mmap);

コメント


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-02-26 (金) 11:54:31