linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: unlisted-recipients:; (no To-header on input)
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	John Hubbard <jhubbard@nvidia.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Michel Lespinasse <walken@google.com>,
	Mike Rapoport <rppt@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 16/38] media: videobuf-dma-sg: number of pages should be unsigned long
Date: Wed,  2 Sep 2020 18:10:19 +0200	[thread overview]
Message-ID: <a57a3584ccc16f33b2e6e8a850b7cb7cf029dfb6.1599062230.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1599062230.git.mchehab+huawei@kernel.org>

As reported by smatch:

	drivers/media/v4l2-core/videobuf-dma-sg.c:245 videobuf_dma_init_kernel() warn: should 'nr_pages << 12' be a 64 bit type?

The printk should not be using %d for the number of pages.

After looking better, the real problem here is that the
number of pages should be long int.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/v4l2-core/videobuf-dma-sg.c | 22 ++++++++++++----------
 include/media/videobuf-dma-sg.h           |  2 +-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c
index 46ff19df9f53..8dd0562de287 100644
--- a/drivers/media/v4l2-core/videobuf-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf-dma-sg.c
@@ -180,7 +180,7 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
 	if (rw == READ)
 		flags |= FOLL_WRITE;
 
-	dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
+	dprintk(1, "init user [0x%lx+0x%lx => %lu pages]\n",
 		data, size, dma->nr_pages);
 
 	err = pin_user_pages(data & PAGE_MASK, dma->nr_pages,
@@ -188,7 +188,7 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
 
 	if (err != dma->nr_pages) {
 		dma->nr_pages = (err >= 0) ? err : 0;
-		dprintk(1, "pin_user_pages: err=%d [%d]\n", err,
+		dprintk(1, "pin_user_pages: err=%d [%lu]\n", err,
 			dma->nr_pages);
 		return err < 0 ? err : -EINVAL;
 	}
@@ -208,11 +208,11 @@ static int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
 }
 
 static int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
-			     int nr_pages)
+				    unsigned long nr_pages)
 {
 	int i;
 
-	dprintk(1, "init kernel [%d pages]\n", nr_pages);
+	dprintk(1, "init kernel [%lu pages]\n", nr_pages);
 
 	dma->direction = direction;
 	dma->vaddr_pages = kcalloc(nr_pages, sizeof(*dma->vaddr_pages),
@@ -238,11 +238,11 @@ static int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
 	dma->vaddr = vmap(dma->vaddr_pages, nr_pages, VM_MAP | VM_IOREMAP,
 			  PAGE_KERNEL);
 	if (NULL == dma->vaddr) {
-		dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
+		dprintk(1, "vmalloc_32(%lu pages) failed\n", nr_pages);
 		goto out_free_pages;
 	}
 
-	dprintk(1, "vmalloc is at addr %p, size=%d\n",
+	dprintk(1, "vmalloc is at addr %p, size=%lu\n",
 		dma->vaddr, nr_pages << PAGE_SHIFT);
 
 	memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT);
@@ -267,9 +267,9 @@ static int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
 }
 
 static int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
-			      dma_addr_t addr, int nr_pages)
+			      dma_addr_t addr, unsigned long nr_pages)
 {
-	dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
+	dprintk(1, "init overlay [%lu pages @ bus 0x%lx]\n",
 		nr_pages, (unsigned long)addr);
 	dma->direction = direction;
 
@@ -500,9 +500,11 @@ static int __videobuf_iolock(struct videobuf_queue *q,
 			     struct videobuf_buffer *vb,
 			     struct v4l2_framebuffer *fbuf)
 {
-	int err, pages;
-	dma_addr_t bus;
 	struct videobuf_dma_sg_memory *mem = vb->priv;
+	unsigned long pages;
+	dma_addr_t bus;
+	int err;
+
 	BUG_ON(!mem);
 
 	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
diff --git a/include/media/videobuf-dma-sg.h b/include/media/videobuf-dma-sg.h
index 34450f7ad510..930ff8d454fc 100644
--- a/include/media/videobuf-dma-sg.h
+++ b/include/media/videobuf-dma-sg.h
@@ -60,7 +60,7 @@ struct videobuf_dmabuf {
 	/* common */
 	struct scatterlist  *sglist;
 	int                 sglen;
-	int                 nr_pages;
+	unsigned long       nr_pages;
 	int                 direction;
 };
 
-- 
2.26.2


  parent reply	other threads:[~2020-09-02 16:17 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 16:10 [PATCH 00/38] media sparse/smatch warn fixes Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 01/38] media: tda10086: cleanup symbol_rate setting logic Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 02/38] media: v4l2-ioctl: avoid memory leaks on some time32 compat functions Mauro Carvalho Chehab
2020-09-02 16:26   ` Laurent Pinchart
2020-09-02 18:45   ` Arnd Bergmann
2020-09-03  6:01     ` Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 03/38] media: qt1010: fix usage of unititialized value Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 04/38] media: av7110_v4l: avoid a typecast Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 05/38] media: wl128x: get rid of a potential spectre issue Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 06/38] media: venus: place extern venus_fw_debug on a header file Mauro Carvalho Chehab
2020-09-10 10:45   ` Stanimir Varbanov
2020-09-02 16:10 ` [PATCH 07/38] media: tda10021: avoid casts when using symbol_rate Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 08/38] media: serial_ir: use the right type for a dma address Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 09/38] media: vivid: move the detection part out of vivid_create_instance Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 10/38] media: vivid: place the logic which disables ioctl on a separate function Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 11/38] media: vivid: move set_capabilities logic to " Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 12/38] media: vivid: place dt timings init code on " Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 13/38] media: vivid: move the create queues to " Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 14/38] media: vivid: move the devnode creation logic " Mauro Carvalho Chehab
2020-09-02 21:57   ` kernel test robot
2020-09-03  0:31   ` kernel test robot
2020-09-02 16:10 ` [PATCH 15/38] media: vivid: fix error path Mauro Carvalho Chehab
2020-09-02 16:10 ` Mauro Carvalho Chehab [this message]
2020-09-03  7:49   ` [PATCH 16/38] media: videobuf-dma-sg: number of pages should be unsigned long John Hubbard
2020-09-02 16:10 ` [PATCH 17/38] media: cx25821-alsa: " Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 18/38] media: cx23885-alsa: " Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 19/38] media: cx88-alsa: " Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 20/38] media: saa7134-alsa.c: " Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 21/38] media: dvb-ttusb-budget: don't use stack for USB transfers Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 22/38] media: dvb-ttusb-budget: cleanup printk logic Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 23/38] media: saa7134: avoid a shift overflow Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 24/38] media: atomisp: fix casts at atomisp_compat_ioctl32.c Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 25/38] media: atomisp: get rid of some unused code Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 26/38] media: atomisp: cleanup ifdefs from ia_css_debug.c Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 27/38] media: atomisp: get rid of version-dependent globals Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 28/38] media: atomisp: get rid of isys_dma.h and isys_dma_local.h Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 29/38] media: atomisp: get rid of ibuf_ctrl abstraction Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 30/38] media: atomisp: don't check for ISP version for includes Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 31/38] media: atomisp: unify INPUT error return type Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 32/38] media: atomisp: de-duplicate names at *_input_system_global.h Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 33/38] media: atomisp: reorder functions at pixelgen_private.h Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 34/38] media: atomisp: remove compile-time tests from input_system_global.h Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 35/38] media: atomisp: fix some bad indents Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 36/38] media: atomisp: csi_rx.c: add a missing includes Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 37/38] media: atomisp: atomisp_gmin_platform: check before use Mauro Carvalho Chehab
2020-09-02 16:10 ` [PATCH 38/38] media: atomisp: cleanup isys_irq headers Mauro Carvalho Chehab
2020-09-07 10:17 ` [PATCH 00/38] media sparse/smatch warn fixes Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a57a3584ccc16f33b2e6e8a850b7cb7cf029dfb6.1599062230.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=rppt@kernel.org \
    --cc=walken@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).