2014-07-15 19:17:07

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH 1/1] Btrfs: fix sparse warning

Fix the following sparse warning:
fs/btrfs/send.c:518:51: warning: incorrect type in argument 2 (different address spaces)
fs/btrfs/send.c:518:51: expected char const [noderef] <asn:1>*<noident>
fs/btrfs/send.c:518:51: got char *

We can safely use (const char __user *) with set_fs(KERNEL_DS)

__force added to avoid sparse-all warning:
fs/btrfs/send.c:518:40: warning: cast adds address space to expression (<asn:1>)

Signed-off-by: Fabian Frederick <[email protected]>
---

This is untested.

fs/btrfs/send.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 6528aa6..b67e12e 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -515,7 +515,8 @@ static int write_buf(struct file *filp, const void *buf, u32 len, loff_t *off)
set_fs(KERNEL_DS);

while (pos < len) {
- ret = vfs_write(filp, (char *)buf + pos, len - pos, off);
+ ret = vfs_write(filp, (__force const char __user *)buf + pos,
+ len - pos, off);
/* TODO handle that correctly */
/*if (ret == -ERESTARTSYS) {
continue;
--
1.8.4.5


2014-07-16 17:27:37

by Zach Brown

[permalink] [raw]
Subject: Re: [PATCH 1/1] Btrfs: fix sparse warning

On Tue, Jul 15, 2014 at 09:17:17PM +0200, Fabian Frederick wrote:
> Fix the following sparse warning:
> fs/btrfs/send.c:518:51: warning: incorrect type in argument 2 (different address spaces)
> fs/btrfs/send.c:518:51: expected char const [noderef] <asn:1>*<noident>
> fs/btrfs/send.c:518:51: got char *
>
> We can safely use (const char __user *) with set_fs(KERNEL_DS)

Yeah, that cast is correct.

Reviewed-by: Zach Brown <[email protected]>

> @@ -515,7 +515,8 @@ static int write_buf(struct file *filp, const void *buf, u32 len, loff_t *off)

Though this probably wants to be rewritten in terms of kernel_write().
That'd give an opportunity to get rid of the sctx->send_off and have it
use f_pos in the filp.

- z

2014-07-17 18:37:38

by Fabian Frédérick

[permalink] [raw]
Subject: Re: [PATCH 1/1] Btrfs: fix sparse warning



> On 16 July 2014 at 19:20 Zach Brown <[email protected]> wrote:
>
>
> On Tue, Jul 15, 2014 at 09:17:17PM +0200, Fabian Frederick wrote:
> > Fix the following sparse warning:
> > fs/btrfs/send.c:518:51: warning: incorrect type in argument 2 (different
> > address spaces)
> > fs/btrfs/send.c:518:51:    expected char const [noderef] *
> > fs/btrfs/send.c:518:51:    got char *
> >
> > We can safely use (const char __user *) with set_fs(KERNEL_DS)
>
> Yeah, that cast is correct.
>
> Reviewed-by: Zach Brown <[email protected]>
>
> > @@ -515,7 +515,8 @@ static int write_buf(struct file *filp, const void *buf,
> > u32 len, loff_t *off)
>
> Though this probably wants to be rewritten in terms of kernel_write().
> That'd give an opportunity to get rid of the sctx->send_off and have it
> use f_pos in the filp.

Do you mean directly call kernel_write from send_cmd/send_header ?
I guess that loop around vfs_write in write_buf is there for something ...

Fabian

>
> - z

2014-07-17 19:01:55

by Zach Brown

[permalink] [raw]
Subject: Re: [PATCH 1/1] Btrfs: fix sparse warning

> > > @@ -515,7 +515,8 @@ static int write_buf(struct file *filp, const void *buf,
> > > u32 len, loff_t *off)
> >
> > Though this probably wants to be rewritten in terms of kernel_write().
> > That'd give an opportunity to get rid of the sctx->send_off and have it
> > use f_pos in the filp.
>
> Do you mean directly call kernel_write from send_cmd/send_header ?
> I guess that loop around vfs_write in write_buf is there for something ...

write_buf() could still exist to iterate over the buffer in the case of
partial writes but it doesn't need to muck around with set_fs() and
forcing casts.

- z