From patchwork Wed Jan 11 09:00:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9509563 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 1949E60231 for ; Wed, 11 Jan 2017 09:01:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 090012029C for ; Wed, 11 Jan 2017 09:01:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1A8A2756B; Wed, 11 Jan 2017 09:01:09 +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 6E7962041F for ; Wed, 11 Jan 2017 09:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936796AbdAKJAv (ORCPT ); Wed, 11 Jan 2017 04:00:51 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36447 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755341AbdAKJAr (ORCPT ); Wed, 11 Jan 2017 04:00:47 -0500 Received: by mail-wm0-f68.google.com with SMTP id r126so15124282wmr.3 for ; Wed, 11 Jan 2017 01:00:46 -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=dWLHABGQI5mnTuSXKxfZ+1ECZB10kRLP0YPn2gbkAykm/dLffiQrEAZ23cKDassV9N MUWw83kzq7TdIqpHLPjuOyk0qd/r4/++JMcJwU6pj16/AW8O+VZtwTm2DLZOHbYzPKF7 01wLPnWZ05dcunPclj2d0CiOi6dD4xog3ixjoGzAyqYb5A+ZpxVBrUuBkkz0jI/tzYsg THJZqDVKus5FyRCck8lF7DBkI4w6kUNCh+HjPOeaVM0EN/6PPzJgMwO2T+Gib8Ce77H6 q8GHl0Gpcp8txbMZzqXH7ihHoYPtCRW85DDjsaV5jh2Ls/TMQ2k2eS0WUS+im767IfaA v+9g== 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=oLYTIqhT8YS3c1BCsFCGygO6/X4nmNQLb4fUhVSgecqXsTIWSIUq7w9Tdf2wYVQ60Q TZ3TJyPfxfeVEMLYGKr1sEaKtOC1b94w2edXAL5f97S1koJbXJ7nlEjfpd9zN3nTcnSy s3ZpBg+cFUHAXPWPZPyPU/XfW1AbDotZ+gzlADIPlJTzo4rZ/2DweGX5ThB6FDWKxNDq 9hbSnLQw8bl2htSlbqWAg60ZmqZeE5lOGQ0LTkBs+xfh6t4o+vewpEsCUdlC7y+Hltfh sygbf6owc8385D+nOJayyUyh4SnWCYSUGuUONyYdkZk8/AeFoNHfN9GMrs6T36+Y4W9s CG2w== X-Gm-Message-State: AIkVDXIi9LFd6yYmiYCeej5cUH/b3xIDZLkOGLvUuUs8T2M8Hp0xYWcCTA/zSOz1W8E/Sw== X-Received: by 10.28.100.70 with SMTP id y67mr740886wmb.45.1484125246153; Wed, 11 Jan 2017 01:00:46 -0800 (PST) Received: from t460p.intel ([2a02:c7d:9bd6:b000:f37e:1e07:a7d8:46cd]) by smtp.gmail.com with ESMTPSA id g6sm7407105wjp.28.2017.01.11.01.00.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 01:00:45 -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: Wed, 11 Jan 2017 09:00:35 +0000 Message-Id: <1484125238-2539-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;