* [PATCH v3] fs/proc/base.c: fix incorrect fmode_t casts
@ 2022-05-22 12:08 Vasily Averin
2022-05-22 12:09 ` Christoph Hellwig
2022-05-22 23:04 ` Matthew Wilcox
0 siblings, 2 replies; 6+ messages in thread
From: Vasily Averin @ 2022-05-22 12:08 UTC (permalink / raw)
To: Christoph Hellwig
Cc: kernel, linux-kernel, Christian Brauner, Jan Kara, linux-fsdevel
Fixes sparce warnings:
fs/proc/base.c:2240:25: sparse: warning: cast to restricted fmode_t
fs/proc/base.c:2297:42: sparse: warning: cast from restricted fmode_t
fs/proc/base.c:2394:48: sparse: warning: cast from restricted fmode_t
fmode_t is birwie type and requires __force attribute for any cast
Signed-off-by: Vasily Averin <vvs@openvz.org>
---
v3: split, reworked according to Christoph Hellwig recommendation
---
fs/proc/base.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index c1031843cc6a..4e4edf9db5f0 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2237,13 +2237,13 @@ static struct dentry *
proc_map_files_instantiate(struct dentry *dentry,
struct task_struct *task, const void *ptr)
{
- fmode_t mode = (fmode_t)(unsigned long)ptr;
+ const fmode_t *mode = ptr;
struct proc_inode *ei;
struct inode *inode;
inode = proc_pid_make_inode(dentry->d_sb, task, S_IFLNK |
- ((mode & FMODE_READ ) ? S_IRUSR : 0) |
- ((mode & FMODE_WRITE) ? S_IWUSR : 0));
+ ((*mode & FMODE_READ ) ? S_IRUSR : 0) |
+ ((*mode & FMODE_WRITE) ? S_IWUSR : 0));
if (!inode)
return ERR_PTR(-ENOENT);
@@ -2294,7 +2294,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
if (vma->vm_file)
result = proc_map_files_instantiate(dentry, task,
- (void *)(unsigned long)vma->vm_file->f_mode);
+ &vma->vm_file->f_mode);
out_no_vma:
mmap_read_unlock(mm);
@@ -2391,7 +2391,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
buf, len,
proc_map_files_instantiate,
task,
- (void *)(unsigned long)p->mode))
+ &p->mode))
break;
ctx->pos++;
}
--
2.36.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3] fs/proc/base.c: fix incorrect fmode_t casts
2022-05-22 12:08 [PATCH v3] fs/proc/base.c: fix incorrect fmode_t casts Vasily Averin
@ 2022-05-22 12:09 ` Christoph Hellwig
2022-05-22 23:04 ` Matthew Wilcox
1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2022-05-22 12:09 UTC (permalink / raw)
To: Vasily Averin
Cc: Christoph Hellwig, kernel, linux-kernel, Christian Brauner,
Jan Kara, linux-fsdevel
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] fs/proc/base.c: fix incorrect fmode_t casts
2022-05-22 12:08 [PATCH v3] fs/proc/base.c: fix incorrect fmode_t casts Vasily Averin
2022-05-22 12:09 ` Christoph Hellwig
@ 2022-05-22 23:04 ` Matthew Wilcox
2022-05-23 3:37 ` [PATCH v4] " Vasily Averin
1 sibling, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2022-05-22 23:04 UTC (permalink / raw)
To: Vasily Averin
Cc: Christoph Hellwig, kernel, linux-kernel, Christian Brauner,
Jan Kara, linux-fsdevel
On Sun, May 22, 2022 at 03:08:42PM +0300, Vasily Averin wrote:
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index c1031843cc6a..4e4edf9db5f0 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -2237,13 +2237,13 @@ static struct dentry *
> proc_map_files_instantiate(struct dentry *dentry,
> struct task_struct *task, const void *ptr)
> {
> - fmode_t mode = (fmode_t)(unsigned long)ptr;
> + const fmode_t *mode = ptr;
Why not ...
fmode_t mode = *(fmode_t *)ptr;
and then you don't need
> - ((mode & FMODE_READ ) ? S_IRUSR : 0) |
> - ((mode & FMODE_WRITE) ? S_IWUSR : 0));
> + ((*mode & FMODE_READ ) ? S_IRUSR : 0) |
> + ((*mode & FMODE_WRITE) ? S_IWUSR : 0));
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4] fs/proc/base.c: fix incorrect fmode_t casts
2022-05-22 23:04 ` Matthew Wilcox
@ 2022-05-23 3:37 ` Vasily Averin
2022-05-23 3:48 ` Matthew Wilcox
2022-05-23 9:40 ` Christian Brauner
0 siblings, 2 replies; 6+ messages in thread
From: Vasily Averin @ 2022-05-23 3:37 UTC (permalink / raw)
To: Matthew Wilcox
Cc: kernel, linux-kernel, Christoph Hellwig, Christian Brauner,
Jan Kara, linux-fsdevel
Fixes sparce warnings:
fs/proc/base.c:2240:25: sparse: warning: cast to restricted fmode_t
fs/proc/base.c:2297:42: sparse: warning: cast from restricted fmode_t
fs/proc/base.c:2394:48: sparse: warning: cast from restricted fmode_t
fmode_t is birwie type and requires __force attribute for any cast
Signed-off-by: Vasily Averin <vvs@openvz.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
v4: improved according to Matthew Wilcox's hint
v3: split, reworked according to Christoph Hellwig recommendation
---
fs/proc/base.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index c1031843cc6a..89521d3fc456 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2237,7 +2237,7 @@ static struct dentry *
proc_map_files_instantiate(struct dentry *dentry,
struct task_struct *task, const void *ptr)
{
- fmode_t mode = (fmode_t)(unsigned long)ptr;
+ fmode_t mode = *(fmode_t *)ptr;
struct proc_inode *ei;
struct inode *inode;
@@ -2294,7 +2294,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
if (vma->vm_file)
result = proc_map_files_instantiate(dentry, task,
- (void *)(unsigned long)vma->vm_file->f_mode);
+ &vma->vm_file->f_mode);
out_no_vma:
mmap_read_unlock(mm);
@@ -2391,7 +2391,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
buf, len,
proc_map_files_instantiate,
task,
- (void *)(unsigned long)p->mode))
+ &p->mode))
break;
ctx->pos++;
}
--
2.36.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v4] fs/proc/base.c: fix incorrect fmode_t casts
2022-05-23 3:37 ` [PATCH v4] " Vasily Averin
@ 2022-05-23 3:48 ` Matthew Wilcox
2022-05-23 9:40 ` Christian Brauner
1 sibling, 0 replies; 6+ messages in thread
From: Matthew Wilcox @ 2022-05-23 3:48 UTC (permalink / raw)
To: Vasily Averin
Cc: kernel, linux-kernel, Christoph Hellwig, Christian Brauner,
Jan Kara, linux-fsdevel
On Mon, May 23, 2022 at 06:37:29AM +0300, Vasily Averin wrote:
> Fixes sparce warnings:
> fs/proc/base.c:2240:25: sparse: warning: cast to restricted fmode_t
> fs/proc/base.c:2297:42: sparse: warning: cast from restricted fmode_t
> fs/proc/base.c:2394:48: sparse: warning: cast from restricted fmode_t
>
> fmode_t is birwie type and requires __force attribute for any cast
>
> Signed-off-by: Vasily Averin <vvs@openvz.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4] fs/proc/base.c: fix incorrect fmode_t casts
2022-05-23 3:37 ` [PATCH v4] " Vasily Averin
2022-05-23 3:48 ` Matthew Wilcox
@ 2022-05-23 9:40 ` Christian Brauner
1 sibling, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2022-05-23 9:40 UTC (permalink / raw)
To: Vasily Averin
Cc: Matthew Wilcox, kernel, linux-kernel, Christoph Hellwig,
Jan Kara, linux-fsdevel
On Mon, May 23, 2022 at 06:37:29AM +0300, Vasily Averin wrote:
> Fixes sparce warnings:
> fs/proc/base.c:2240:25: sparse: warning: cast to restricted fmode_t
> fs/proc/base.c:2297:42: sparse: warning: cast from restricted fmode_t
> fs/proc/base.c:2394:48: sparse: warning: cast from restricted fmode_t
>
> fmode_t is birwie type and requires __force attribute for any cast
>
> Signed-off-by: Vasily Averin <vvs@openvz.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> ---
Looks good to me,
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-05-23 9:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-22 12:08 [PATCH v3] fs/proc/base.c: fix incorrect fmode_t casts Vasily Averin
2022-05-22 12:09 ` Christoph Hellwig
2022-05-22 23:04 ` Matthew Wilcox
2022-05-23 3:37 ` [PATCH v4] " Vasily Averin
2022-05-23 3:48 ` Matthew Wilcox
2022-05-23 9:40 ` Christian Brauner
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.