From patchwork Thu May 4 15:54:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9712257 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 71B3460235 for ; Thu, 4 May 2017 15:56:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 645F1262FF for ; Thu, 4 May 2017 15:56:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 594F128174; Thu, 4 May 2017 15:56:48 +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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 3B26B262FF for ; Thu, 4 May 2017 15:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753177AbdEDPy7 (ORCPT ); Thu, 4 May 2017 11:54:59 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36347 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751474AbdEDPyP (ORCPT ); Thu, 4 May 2017 11:54:15 -0400 Received: by mail-wm0-f66.google.com with SMTP id u65so4217932wmu.3 for ; Thu, 04 May 2017 08:54:14 -0700 (PDT) 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=8dPVsCf5LcLFFWn5hCqNZTbvqvkdmaqAwnxZmdnJA6E=; b=XZQg+NKT+UxgPMh53ZvLmuH1UzC30V8+VOdTfpq2L23bCYIM9I643HThCyLaydIZcO lyBbjOxfQ0+B9hEK1ct7r2eCWW3yRD/25LkHJna+oQ8X+J/HhMI6S19exckreAi6XT7a cnly7/0YmJRZqqIpOcok3tuCZIMEhinrFYdc6I62uFIFbRtVdobczAn5hDlbkCzU2zWI jtpjN6pNLq4L9OC7LhTFfhiII0dGCjg+sD6Ou6OofVy7PHeNFpp31O+1tfOJYPHE50kM CS5EjihJaKeE+lXKzMS69suqDmif4mBplbkjDraVlR8SIXvJz9TBZdgoz3xPZuiXlgxi zRXQ== 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=8dPVsCf5LcLFFWn5hCqNZTbvqvkdmaqAwnxZmdnJA6E=; b=LGdw+W1e7VqF4QdfmgeBzjEWpSIya3eFYgSYrbJRlzcPWLe4dEsFfTOgoHzyYomJ8M YYBuWT4gHt11BULOugUTDAS10LB3I7tBREHjF/6DIKjsYOKvg/MXl1lO/1MFNA1T5tNJ BgcA04CeFhe6M8uDbL5YUbUu3zx+GetuggJxJDS51KLH6+crTbdbobopK3RJ8zYG2zNy g048baxQ9gXDdBATPFHwILEuOJ9SZc5qtOReU0r4O1SSZhodZqiIIQimRWDw6JP5DtWE 7zqlm1SK1czaVJ7sUiN/A5NYiuuhAq4+rvR9C6/kaXxdhWnd1jiuPIkl7bnpKnkTJdQA 5kPw== X-Gm-Message-State: AODbwcBIYx2bUyTKkRq5IUJ641hAxkSpn5796HSRPBjAtqXn0993ICx4 oBEhH38mmXA0+A== X-Received: by 10.28.35.207 with SMTP id j198mr2408416wmj.17.1493913253896; Thu, 04 May 2017 08:54:13 -0700 (PDT) Received: from t460p.intel ([94.15.199.60]) by smtp.gmail.com with ESMTPSA id y3sm2064342wrd.23.2017.05.04.08.54.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 08:54:13 -0700 (PDT) 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: Thu, 4 May 2017 16:54:02 +0100 Message-Id: <20170504155405.7425-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.9.3 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 2db0413f5d57..b5009c1649bc 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 50b617af81bd..a8b6696ab6cb 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 c6cf82242d65..11f172c383cb 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;