From patchwork Thu Jul 27 09:05:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9866463 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 D8C01603F9 for ; Thu, 27 Jul 2017 09:05:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA6E028662 for ; Thu, 27 Jul 2017 09:05:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF583287EE; Thu, 27 Jul 2017 09:05:18 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI 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 48DC928662 for ; Thu, 27 Jul 2017 09:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751517AbdG0JFP (ORCPT ); Thu, 27 Jul 2017 05:05:15 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33972 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750836AbdG0JFN (ORCPT ); Thu, 27 Jul 2017 05:05:13 -0400 Received: by mail-wr0-f193.google.com with SMTP id o33so16385094wrb.1 for ; Thu, 27 Jul 2017 02:05:12 -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:in-reply-to:references; bh=7Zrv9VLZp0IkzVaNOTmQf3Hg5eZ4UDfWKwoAevLKcDA=; b=YVWBN594BTE0fpGogGaqPAuuPo6wohlNz4xIABQVGD669NqmSiR0blHioP3LKy8tAt 2hmr7grBHn/vRTRXCUci6pw2E5BRQLqGGYKqanxBfY/m+CqEaMblXo1v8/gfLLZuU02o NTPn6qeCaIDYOEr1yKtisjlMNcIFYyu44OAUdh02331Tzpvt/pw2XuDpArTj27CpuMeL ouYIoZcUY5NXNQsp2qxjFHoBSI9PcoVRGe0HNeWeCbjFYsYSZu3HoRjJcnLojfc+nTpK rcOtqkyd24h2jJBXMpS60ZPoqqnUvPGyOOr9vvGRgRho4YIzVnH1SHSRBItsqctuF6Zy hz+g== 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:in-reply-to :references; bh=7Zrv9VLZp0IkzVaNOTmQf3Hg5eZ4UDfWKwoAevLKcDA=; b=k3RWpvBedk36q9p9xaYpccssCjNBdtYMsY/c8kQ5xKjFE1AmdnrscydG7X+LtS9yRd ywQ8pGB1VfGAf+FQKzl+gnlRlTsnSRpIzlu93rHPGAjtzXb0CLDxzgvhs+DJEF4j3FcO zXPXXkn7iiUqn9NKoRBFypzhPy0PmBS5PCbw7amF+FXXMZ/WMA6w4adK5YPFD9eJnjZA WOeMnUZdTItNhKdFQ/YBtUcP8j74Us6nV77EiJNlesPWzQHOZ1rqH67sTEfnXdqGb1xh 99xMAGtpj1Jld/5PK0WcGfyenhf2IhFBiKelYe7/PeF+7OvLU9eLjaN5OTFMYKndSXPW TlLA== X-Gm-Message-State: AIVw113f5haEFoEFn2A58vgDvnMZWs5Qrfkt4bITiyyM7QygxsmPuE5z PybFDMDw8P2fVrMM X-Received: by 10.223.163.199 with SMTP id m7mr2984317wrb.128.1501146312091; Thu, 27 Jul 2017 02:05:12 -0700 (PDT) Received: from t460p.intel ([95.146.144.225]) by smtp.gmail.com with ESMTPSA id 39sm25653524wrc.84.2017.07.27.02.05.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jul 2017 02:05:11 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: Ben Widawsky , Jason Ekstrand , 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, 27 Jul 2017 10:05:01 +0100 Message-Id: <20170727090504.15812-2-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170727090504.15812-1-tvrtko.ursulin@linux.intel.com> References: <20170727090504.15812-1-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 4f246d166111..2405077fdc71 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -479,7 +479,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; @@ -507,7 +507,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 5beb0c361076..5c1b6388122a 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 4b3286ac60c8..205aefb4ed93 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 be7b4dd6b68d..dee0c5004e2f 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;