Skip to contentSkip to conversation

fsdax: dax_unshare_iter() should return a valid length

PATCH Applied Shiyang Ruan 4 participants 4 messages Feb 2, 2023 – Feb 3, 2023

Subsystems (3)

v1 of 2 Applied 1/1 Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsdax: dax_unshare_iter() should return a valid length

The copy_mc_to_kernel() will return 0 if it executed successfully. Then the return value should be set to the length it copied.

Fixes d984648e428b ("fsdax,xfs: port unshare to fsdax")
---
 fs/dax.c | 1 +
 1 file changed, 1 insertion(+)
fs/dax.c +1 -0
index c48a3a93ab29..a5b4deb5def3 100644
@@ -1274,6 +1274,7 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
 	ret = copy_mc_to_kernel(daddr, saddr, length);
 	if (ret)
 		ret = -EIO;
+	ret = length;
 
 out_unlock:
 	dax_read_unlock(id);
Signature · 1 line
2.39.1
#1 lore raw
Quoted 14 lines · Shiyang Ruan

The copy_mc_to_kernel() will return 0 if it executed successfully. Then the return value should be set to the length it copied.

Fixes d984648e428b ("fsdax,xfs: port unshare to fsdax")
---
 fs/dax.c | 1 +
 1 file changed, 1 insertion(+)
fs/dax.c +0 -0
index c48a3a93ab29..a5b4deb5def3 100644

fs/dax.c static s64 dax_unshare_iter(struct iomap_iter *iter) · line 1277

Quoted 4 lines
fs/dax.c +1 -0
@@ -1274,6 +1274,7 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
 	ret = copy_mc_to_kernel(daddr, saddr, length);
 	if (ret)
 		ret = -EIO;
+	ret = length;

Umm. Surely should be:

	else
		ret = length;

otherwise you've just overwritten the -EIO.

And maybe this should be:

	ret = length - copy_mc_to_kernel(daddr, saddr, length);
	if (ret < length)
		ret = -EIO;

What do you think?

#2 lore raw
Quoted 22 lines · On Thu, 2 Feb 2023 23:01:23 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 14 lines · Shiyang Ruan

The copy_mc_to_kernel() will return 0 if it executed successfully. Then the return value should be set to the length it copied.

Fixes d984648e428b ("fsdax,xfs: port unshare to fsdax")
---
 fs/dax.c | 1 +
 1 file changed, 1 insertion(+)
fs/dax.c +0 -0
index c48a3a93ab29..a5b4deb5def3 100644

fs/dax.c static s64 dax_unshare_iter(struct iomap_iter *iter) · line 1277

Quoted 4 lines
fs/dax.c +1 -0
@@ -1274,6 +1274,7 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
 	ret = copy_mc_to_kernel(daddr, saddr, length);
 	if (ret)
 		ret = -EIO;
+	ret = length;

Umm. Surely should be:

Quoted 4 lines
	else
		ret = length;

otherwise you've just overwritten the -EIO.

yup

Quoted 6 lines

And maybe this should be:

	ret = length - copy_mc_to_kernel(daddr, saddr, length);
	if (ret < length)
		ret = -EIO;

not a fan of giving `ret' a temporary new meaning like that. If it was

	copied = length - copy_mc_to_kernel(daddr, saddr, length);
	if (copied < length)
		ret = -EIO;

then it would be clear.

Clearer, methinks:

	if (copy_mc_to_kernel(daddr, saddr, length) == 0)
		ret = length;
	else
		ret = -EIO;
#3 lore raw
Quoted 8 lines · Andrew Morton
Quoted 6 lines · On Thu, 2 Feb 2023 23:01:23 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 5 lines · Shiyang Ruan

The copy_mc_to_kernel() will return 0 if it executed successfully. Then the return value should be set to the length it copied.

Fixes d984648e428b ("fsdax,xfs: port unshare to fsdax")

[..]

Quoted 8 lines

Clearer, methinks:

	if (copy_mc_to_kernel(daddr, saddr, length) == 0)
		ret = length;
	else
		ret = -EIO;

That looks good to me.