linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] virtiofs, dax: Fix couple of smatch warnings
@ 2021-05-06 18:43 Vivek Goyal
  2021-05-06 18:43 ` [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift Vivek Goyal
  2021-05-06 18:43 ` [PATCH 2/2] virtiofs, dax: Fixed smatch warning about ret being uninitialized Vivek Goyal
  0 siblings, 2 replies; 6+ messages in thread
From: Vivek Goyal @ 2021-05-06 18:43 UTC (permalink / raw)
  To: linux-fsdevel, virtio-fs, miklos
  Cc: vgoyal, dgilbert, linux-kernel, dan.carpenter

Hi,

Dan Carpenter reported couple of smatch warning in fs/fuse/dax.c code.
These patches fix the warnings.

Thanks Dan.

Vivek

Vivek Goyal (2):
  virtiofs, dax: Fix smatch warning about loss of info during shift
  virtiofs, dax: Fixed smatch warning about ret being uninitialized

 fs/fuse/dax.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

-- 
2.25.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift
  2021-05-06 18:43 [PATCH 0/2] virtiofs, dax: Fix couple of smatch warnings Vivek Goyal
@ 2021-05-06 18:43 ` Vivek Goyal
  2021-05-06 19:07   ` Dr. David Alan Gilbert
  2021-05-06 18:43 ` [PATCH 2/2] virtiofs, dax: Fixed smatch warning about ret being uninitialized Vivek Goyal
  1 sibling, 1 reply; 6+ messages in thread
From: Vivek Goyal @ 2021-05-06 18:43 UTC (permalink / raw)
  To: linux-fsdevel, virtio-fs, miklos
  Cc: vgoyal, dgilbert, linux-kernel, dan.carpenter

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] virtiofs, dax: Fixed smatch warning about ret being uninitialized
  2021-05-06 18:43 [PATCH 0/2] virtiofs, dax: Fix couple of smatch warnings Vivek Goyal
  2021-05-06 18:43 ` [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift Vivek Goyal
@ 2021-05-06 18:43 ` Vivek Goyal
  1 sibling, 0 replies; 6+ messages in thread
From: Vivek Goyal @ 2021-05-06 18:43 UTC (permalink / raw)
  To: linux-fsdevel, virtio-fs, miklos
  Cc: vgoyal, dgilbert, linux-kernel, dan.carpenter

Dan reported a smatch warning about "ret" being uninitialized. Fix it.

fs/fuse/dax.c:197 dmap_removemapping_list() error: uninitialized symbol 'ret'.

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

diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c
index f06fdad3f7b1..1608b6606ef0 100644
--- a/fs/fuse/dax.c
+++ b/fs/fuse/dax.c
@@ -253,7 +253,10 @@ static int dmap_removemapping_list(struct inode *inode, unsigned int num,
 	struct fuse_removemapping_one *remove_one, *ptr;
 	struct fuse_removemapping_in inarg;
 	struct fuse_dax_mapping *dmap;
-	int ret, i = 0, nr_alloc;
+	int ret = 0, i = 0, nr_alloc;
+
+	if (!num)
+		return ret;
 
 	nr_alloc = min_t(unsigned int, num, FUSE_REMOVEMAPPING_MAX_ENTRY);
 	remove_one = kmalloc_array(nr_alloc, sizeof(*remove_one), GFP_NOFS);
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift
  2021-05-06 18:43 ` [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:35     ` Matthew Wilcox
  0 siblings, 1 reply; 6+ messages in thread
From: Dr. David Alan Gilbert @ 2021-05-06 19:07 UTC (permalink / raw)
  To: Vivek Goyal; +Cc: linux-fsdevel, virtio-fs, miklos, linux-kernel, dan.carpenter

* Vivek Goyal (vgoyal@redhat.com) wrote:
> 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;

I've not followed the others back, but isn't it easier to change
the start_idx parameter to be a loff_t, since the places it's called
from are poth loff_t pos?

Dave

>  	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
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift
  2021-05-06 19:07   ` Dr. David Alan Gilbert
@ 2021-05-06 19:35     ` Matthew Wilcox
  2021-05-10 18:16       ` Vivek Goyal
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2021-05-06 19:35 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: Vivek Goyal, linux-fsdevel, virtio-fs, miklos, linux-kernel,
	dan.carpenter

On Thu, May 06, 2021 at 08:07:39PM +0100, Dr. David Alan Gilbert wrote:
> > @@ -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;
> 
> I've not followed the others back, but isn't it easier to change
> the start_idx parameter to be a loff_t, since the places it's called
> from are poth loff_t pos?

But an index isn't a file offset, and shouldn't be typed as such.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] virtiofs, dax: Fix smatch warning about loss of info during shift
  2021-05-06 19:35     ` Matthew Wilcox
@ 2021-05-10 18:16       ` Vivek Goyal
  0 siblings, 0 replies; 6+ messages in thread
From: Vivek Goyal @ 2021-05-10 18:16 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Dr. David Alan Gilbert, linux-fsdevel, virtio-fs, miklos,
	linux-kernel, dan.carpenter

On Thu, May 06, 2021 at 12:35:17PM -0700, Matthew Wilcox wrote:
> On Thu, May 06, 2021 at 08:07:39PM +0100, Dr. David Alan Gilbert wrote:
> > > @@ -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;
> > 
> > I've not followed the others back, but isn't it easier to change
> > the start_idx parameter to be a loff_t, since the places it's called
> > from are poth loff_t pos?
> 
> But an index isn't a file offset, and shouldn't be typed as such.

Agreed. This is index, so it seems better to not use "loff_t" to
represent it.

Vivek


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-10 18:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06 18:43 [PATCH 0/2] virtiofs, dax: Fix couple of smatch warnings Vivek Goyal
2021-05-06 18:43 ` [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:35     ` Matthew Wilcox
2021-05-10 18:16       ` Vivek Goyal
2021-05-06 18:43 ` [PATCH 2/2] virtiofs, dax: Fixed smatch warning about ret being uninitialized Vivek Goyal

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).