From patchwork Mon Jan 16 14:12:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9518891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 577E06020B for ; Mon, 16 Jan 2017 14:12:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 364412848E for ; Mon, 16 Jan 2017 14:12:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AF3F2848F; Mon, 16 Jan 2017 14:12:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E3B4276D6 for ; Mon, 16 Jan 2017 14:12:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751125AbdAPOMW (ORCPT ); Mon, 16 Jan 2017 09:12:22 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35006 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751081AbdAPOMV (ORCPT ); Mon, 16 Jan 2017 09:12:21 -0500 Received: by mail-wm0-f67.google.com with SMTP id d140so14702411wmd.2 for ; Mon, 16 Jan 2017 06:12:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=LDRzOxgRt7OQhvqs+t9WeQtKytoDSCOPw5wferg/628=; b=0L4X+1UX8/EdHxwAUM9tu8d1ac93qXfMicsQdqlnUeGLpAqUGE8uL3XOVpDk96D8NY VfoXulORB5qFQJrOK6gIVhZ5Km/TIdXX6jBWpYYynZhhjfU58zBDKdJXEqP8gw1FrpN0 lz9hYOvYu9qHFidqmkeHUReQpdAA0N/s2faSkJPTeOV3KojIWFgjAVKAOuyxniBnyqxx /zCmfNojzNHDhJ9Pc5+YHdDaGkmr9kXp5tAGG6tGdqt3ubtJQY7dv6xTsnJ0jHto6LVc FFANdX9AKyKIjjDNOk9sUP6s9YgOJO5Q6Dla5C6qlFwo7FVMnSngTVuBDqk9EB1MvMLw MXOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LDRzOxgRt7OQhvqs+t9WeQtKytoDSCOPw5wferg/628=; b=m5jlaJ8B070jPx19dC8uxu34yhKJdl/xZ1SJy/8DsQa5sP7ivC4P9392cu1/IAY1xW qYGnc1zVRH7HyL42I7MI4L3Ii7HHuJhmxLcb1/1xQtziky2KYNzg9neXkFZJmhYfmjhR SnZVBYyY7tAu3W57DjOZPcgr+FS9W63btsjFfcHc9h8+SRNC1MqawfD6OrJBqe9WUcoM H6vXff+AqDfsHh3gOzNEoo+4LEpf+dMoVyrUVbEBQvLkiGGdwwQV9vUsnxTTzNOGsfDo IRQ9RRt8u6Q+Uh8WGcM9eeq/mEZ2bH9k7sInYrw9yfg5t7KTR/ecnsG6rplNgTrD8ofr RySQ== X-Gm-Message-State: AIkVDXJGfcm7l8+Z3a3k80kpgyKqwhhYnUGveLFcY5WanrmPmlHzKVxCjCrC8aM16Du5TA== X-Received: by 10.28.86.131 with SMTP id k125mr13009979wmb.89.1484575939796; Mon, 16 Jan 2017 06:12:19 -0800 (PST) Received: from t460p.intel ([2a02:c7d:9bd6:b000:f37e:1e07:a7d8:46cd]) by smtp.gmail.com with ESMTPSA id c202sm29123067wmd.10.2017.01.16.06.12.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jan 2017 06:12:18 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: tursulin@ursulin.net, Tvrtko Ursulin , Masahiro Yamada , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Tomasz Stanislawski , Matt Porter , Alexandre Bounine , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] lib/scatterlist: Fix offset type in sg_alloc_table_from_pages Date: Mon, 16 Jan 2017 14:12:07 +0000 Message-Id: <1484575930-6810-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Scatterlist entries have an unsigned int for the offset so correct the sg_alloc_table_from_pages function accordingly. Since these are offsets withing a page, unsigned int is wide enough. Also converts callers which were using unsigned long locally with the lower_32_bits annotation to make it explicitly clear what is happening. v2: Use offset_in_page. (Chris Wilson) Signed-off-by: Tvrtko Ursulin Cc: Masahiro Yamada Cc: Pawel Osciak Cc: Marek Szyprowski Cc: Kyungmin Park Cc: Tomasz Stanislawski Cc: Matt Porter Cc: Alexandre Bounine Cc: linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org Acked-by: Marek Szyprowski (v1) Reviewed-by: Chris Wilson Reviewed-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 4 ++-- drivers/rapidio/devices/rio_mport_cdev.c | 4 ++-- include/linux/scatterlist.h | 2 +- lib/scatterlist.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index fb6a177be461..51e8765bc3c6 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -478,7 +478,7 @@ static void *vb2_dc_get_userptr(struct device *dev, unsigned long vaddr, { struct vb2_dc_buf *buf; struct frame_vector *vec; - unsigned long offset; + unsigned int offset; int n_pages, i; int ret = 0; struct sg_table *sgt; @@ -506,7 +506,7 @@ static void *vb2_dc_get_userptr(struct device *dev, unsigned long vaddr, buf->dev = dev; buf->dma_dir = dma_dir; - offset = vaddr & ~PAGE_MASK; + offset = lower_32_bits(offset_in_page(vaddr)); vec = vb2_create_framevec(vaddr, size, dma_dir == DMA_FROM_DEVICE); if (IS_ERR(vec)) { ret = PTR_ERR(vec); diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c index 9013a585507e..0fae29ff47ba 100644 --- a/drivers/rapidio/devices/rio_mport_cdev.c +++ b/drivers/rapidio/devices/rio_mport_cdev.c @@ -876,10 +876,10 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode, * offset within the internal buffer specified by handle parameter. */ if (xfer->loc_addr) { - unsigned long offset; + unsigned int offset; long pinned; - offset = (unsigned long)(uintptr_t)xfer->loc_addr & ~PAGE_MASK; + offset = lower_32_bits(offset_in_page(xfer->loc_addr)); nr_pages = PAGE_ALIGN(xfer->length + offset) >> PAGE_SHIFT; page_list = kmalloc_array(nr_pages, diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index cb3c8fe6acd7..c981bee1a3ae 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -263,7 +263,7 @@ int __sg_alloc_table(struct sg_table *, unsigned int, unsigned int, int sg_alloc_table(struct sg_table *, unsigned int, gfp_t); int sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages, unsigned int n_pages, - unsigned long offset, unsigned long size, + unsigned int offset, unsigned long size, gfp_t gfp_mask); size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, void *buf, diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 004fc70fc56a..e05e7fc98892 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -391,7 +391,7 @@ EXPORT_SYMBOL(sg_alloc_table); */ int sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages, unsigned int n_pages, - unsigned long offset, unsigned long size, + unsigned int offset, unsigned long size, gfp_t gfp_mask) { unsigned int chunks;