From patchwork Fri Nov 11 08:50:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9422597 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 5A114601C0 for ; Fri, 11 Nov 2016 08:51:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 537AD29981 for ; Fri, 11 Nov 2016 08:51:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4801C29983; Fri, 11 Nov 2016 08:51:33 +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=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 AD92529981 for ; Fri, 11 Nov 2016 08:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965689AbcKKIuv (ORCPT ); Fri, 11 Nov 2016 03:50:51 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35767 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965499AbcKKIus (ORCPT ); Fri, 11 Nov 2016 03:50:48 -0500 Received: by mail-wm0-f67.google.com with SMTP id a20so7919220wme.2 for ; Fri, 11 Nov 2016 00:50:42 -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:in-reply-to:references; bh=uE6BKMW4ScvJNC2OQYbUGDX/o/uqFtSJFE+82tiuNDc=; b=A6xM8F9yEm1fA++P8pntlBV6TGAzjBjhqTC9Tvkp3ssz5CFGAAraNyp4TBLC5oLnU+ /569BlD8qqGYgbhqYZjaUaG00DroMEvMJNS0Yg8DPJpRRgxHepW2UylKwq2Qg1AReFzk lYZuFZgKlaAdzPG4FT5Z84d4+yia/f1K650E5v0oH962FjXYCsv/1dGOMsRt33ypYxhM ECq46UmhoRmYnTCBCTPSQJapJMHgiALekDfP0sayx56QwGBJqr+YQKbKyWoOAqI6BDgE UnV8CL4oFXZR9Cd0e6Bd+rcG44nqhxKSGDKZkI9hGL9uqUbgXd1vaNrWHJKmq8tp6f7g Bfyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uE6BKMW4ScvJNC2OQYbUGDX/o/uqFtSJFE+82tiuNDc=; b=EQLQW4TnuuhYUWyzB0Yv4NxK6rfQSSrOtd+1H34wR3NYAPuUdovFsGaiHwy9j/zmnE yr+FgQQKprUcmY7n2T5QN9oc7NrTqtk0/J59TyWYochdMkbBu+ghecmmQrzXRII9Oz4u gETLDj2spa7yzzRgtFyOZnTF34Ce5drL4fQebE670ljo3do8TgJHxEw9BaE2N6c3OTq3 6GjUnPm4HYqFpZXthAD+hRH9ehrH71Ve9lqcQuBuRqT+xDCz4tPBLKbJurYHhCEgZDar CcYD0FqzY3yOrropd0tabARZv0QhfCZjUvSV8ut8rWMT/Ml4lsXQQfA2qN7pkDQf83I8 BApQ== X-Gm-Message-State: ABUngvdsDS/kjDxyFSOegYf8em12/jovalhrNZAQrodllr/PfBv3DzjG9i1lY/9MwHDDkw== X-Received: by 10.28.210.1 with SMTP id j1mr10765091wmg.86.1478854241488; Fri, 11 Nov 2016 00:50:41 -0800 (PST) Received: from t460p.intel ([2a02:c7d:9bd6:b000:f37e:1e07:a7d8:46cd]) by smtp.gmail.com with ESMTPSA id l6sm10218684wjc.7.2016.11.11.00.50.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 00:50:41 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Tvrtko Ursulin , Masahiro Yamada , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Tomasz Stanislawski , Matt Porter , Alexandre Bounine , linux-media@vger.kernel.org Subject: [PATCH 1/4] lib/scatterlist: Fix offset type in sg_alloc_table_from_pages Date: Fri, 11 Nov 2016 08:50:17 +0000 Message-Id: <1478854220-3255-2-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478854220-3255-1-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1478854220-3255-1-git-send-email-tvrtko.ursulin@linux.intel.com> 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;