All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: linux-fsdevel@vger.kernel.org, virtio-fs@redhat.com, miklos@szeredi.hu
Cc: vgoyal@redhat.com, dgilbert@redhat.com,
	linux-kernel@vger.kernel.org, dan.carpenter@oracle.com
Subject: [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift
Date: Thu,  6 May 2021 14:43:03 -0400	[thread overview]
Message-ID: <20210506184304.321645-2-vgoyal@redhat.com> (raw)
In-Reply-To: <20210506184304.321645-1-vgoyal@redhat.com>

Dan reported a smatch warning during potentential loss of info during
left shift if this code is compiled on 32bit systems.

New smatch warnings:
fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a
+64 bit type?

I ran smatch and found two more instances of similar warning. This patch
fixes all such instances.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
 fs/fuse/dax.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c
index ff99ab2a3c43..f06fdad3f7b1 100644
--- a/fs/fuse/dax.c
+++ b/fs/fuse/dax.c
@@ -186,7 +186,7 @@ static int fuse_setup_one_mapping(struct inode *inode, unsigned long start_idx,
 	struct fuse_conn_dax *fcd = fm->fc->dax;
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_setupmapping_in inarg;
-	loff_t offset = start_idx << FUSE_DAX_SHIFT;
+	loff_t offset = (loff_t)start_idx << FUSE_DAX_SHIFT;
 	FUSE_ARGS(args);
 	ssize_t err;
 
@@ -872,7 +872,7 @@ static int dmap_writeback_invalidate(struct inode *inode,
 				     struct fuse_dax_mapping *dmap)
 {
 	int ret;
-	loff_t start_pos = dmap->itn.start << FUSE_DAX_SHIFT;
+	loff_t start_pos = (loff_t)dmap->itn.start << FUSE_DAX_SHIFT;
 	loff_t end_pos = (start_pos + FUSE_DAX_SZ - 1);
 
 	ret = filemap_fdatawrite_range(inode->i_mapping, start_pos, end_pos);
@@ -966,7 +966,7 @@ inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode,
 	dmap = inode_lookup_first_dmap(inode);
 	if (dmap) {
 		start_idx = dmap->itn.start;
-		dmap_start = start_idx << FUSE_DAX_SHIFT;
+		dmap_start = (u64)start_idx << FUSE_DAX_SHIFT;
 		dmap_end = dmap_start + FUSE_DAX_SZ - 1;
 	}
 	up_read(&fi->dax->sem);
@@ -1118,7 +1118,7 @@ static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd,
 {
 	int ret;
 	struct fuse_inode *fi = get_fuse_inode(inode);
-	loff_t dmap_start = start_idx << FUSE_DAX_SHIFT;
+	loff_t dmap_start = (loff_t)start_idx << FUSE_DAX_SHIFT;
 	loff_t dmap_end = (dmap_start + FUSE_DAX_SZ) - 1;
 
 	down_write(&fi->i_mmap_sem);
-- 
2.25.4


WARNING: multiple messages have this Message-ID (diff)
From: Vivek Goyal <vgoyal@redhat.com>
To: linux-fsdevel@vger.kernel.org, virtio-fs@redhat.com, miklos@szeredi.hu
Cc: dan.carpenter@oracle.com, vgoyal@redhat.com,
	linux-kernel@vger.kernel.org
Subject: [Virtio-fs] [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift
Date: Thu,  6 May 2021 14:43:03 -0400	[thread overview]
Message-ID: <20210506184304.321645-2-vgoyal@redhat.com> (raw)
In-Reply-To: <20210506184304.321645-1-vgoyal@redhat.com>

Dan reported a smatch warning during potentential loss of info during
left shift if this code is compiled on 32bit systems.

New smatch warnings:
fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a
+64 bit type?

I ran smatch and found two more instances of similar warning. This patch
fixes all such instances.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
 fs/fuse/dax.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c
index ff99ab2a3c43..f06fdad3f7b1 100644
--- a/fs/fuse/dax.c
+++ b/fs/fuse/dax.c
@@ -186,7 +186,7 @@ static int fuse_setup_one_mapping(struct inode *inode, unsigned long start_idx,
 	struct fuse_conn_dax *fcd = fm->fc->dax;
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_setupmapping_in inarg;
-	loff_t offset = start_idx << FUSE_DAX_SHIFT;
+	loff_t offset = (loff_t)start_idx << FUSE_DAX_SHIFT;
 	FUSE_ARGS(args);
 	ssize_t err;
 
@@ -872,7 +872,7 @@ static int dmap_writeback_invalidate(struct inode *inode,
 				     struct fuse_dax_mapping *dmap)
 {
 	int ret;
-	loff_t start_pos = dmap->itn.start << FUSE_DAX_SHIFT;
+	loff_t start_pos = (loff_t)dmap->itn.start << FUSE_DAX_SHIFT;
 	loff_t end_pos = (start_pos + FUSE_DAX_SZ - 1);
 
 	ret = filemap_fdatawrite_range(inode->i_mapping, start_pos, end_pos);
@@ -966,7 +966,7 @@ inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode,
 	dmap = inode_lookup_first_dmap(inode);
 	if (dmap) {
 		start_idx = dmap->itn.start;
-		dmap_start = start_idx << FUSE_DAX_SHIFT;
+		dmap_start = (u64)start_idx << FUSE_DAX_SHIFT;
 		dmap_end = dmap_start + FUSE_DAX_SZ - 1;
 	}
 	up_read(&fi->dax->sem);
@@ -1118,7 +1118,7 @@ static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd,
 {
 	int ret;
 	struct fuse_inode *fi = get_fuse_inode(inode);
-	loff_t dmap_start = start_idx << FUSE_DAX_SHIFT;
+	loff_t dmap_start = (loff_t)start_idx << FUSE_DAX_SHIFT;
 	loff_t dmap_end = (dmap_start + FUSE_DAX_SZ) - 1;
 
 	down_write(&fi->i_mmap_sem);
-- 
2.25.4


  reply	other threads:[~2021-05-06 18:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 18:43 [PATCH 0/2] virtiofs, dax: Fix couple of smatch warnings Vivek Goyal
2021-05-06 18:43 ` [Virtio-fs] " Vivek Goyal
2021-05-06 18:43 ` Vivek Goyal [this message]
2021-05-06 18:43   ` [Virtio-fs] [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift Vivek Goyal
2021-05-06 19:07   ` Dr. David Alan Gilbert
2021-05-06 19:07     ` [Virtio-fs] " Dr. David Alan Gilbert
2021-05-06 19:35     ` Matthew Wilcox
2021-05-06 19:35       ` [Virtio-fs] " Matthew Wilcox
2021-05-10 18:16       ` Vivek Goyal
2021-05-10 18:16         ` [Virtio-fs] " Vivek Goyal
2021-05-06 18:43 ` [PATCH 2/2] virtiofs, dax: Fixed smatch warning about ret being uninitialized Vivek Goyal
2021-05-06 18:43   ` [Virtio-fs] " Vivek Goyal

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=20210506184304.321645-2-vgoyal@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dgilbert@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=virtio-fs@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.