All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: clean up error return for convert_initialized_extent()
@ 2020-02-18 20:26 Eric Whitney
  2020-03-06  1:28 ` Theodore Y. Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Whitney @ 2020-02-18 20:26 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, Eric Whitney

Although convert_initialized_extent() can potentially return an error
code with a negative value, its returned value is assigned to an
unsigned variable containing a block count in ext4_ext_map_blocks() and
then returned to that function's caller. The code currently works,
though the way this happens is obscure.  The code would be more
readable if it followed the error handling convention used elsewhere
in ext4_ext_map_blocks().

This patch does not address any known test failure or bug report - it's
simply a cleanup.  It also addresses a nearby coding standard issue.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
---
 fs/ext4/extents.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 954013d6076b..71820d879a80 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3931,7 +3931,7 @@ static int
 convert_initialized_extent(handle_t *handle, struct inode *inode,
 			   struct ext4_map_blocks *map,
 			   struct ext4_ext_path **ppath,
-			   unsigned int allocated)
+			   unsigned int *allocated)
 {
 	struct ext4_ext_path *path = *ppath;
 	struct ext4_extent *ex;
@@ -3995,10 +3995,10 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
 	if (err)
 		return err;
 	map->m_flags |= EXT4_MAP_UNWRITTEN;
-	if (allocated > map->m_len)
-		allocated = map->m_len;
-	map->m_len = allocated;
-	return allocated;
+	if (*allocated > map->m_len)
+		*allocated = map->m_len;
+	map->m_len = *allocated;
+	return 0;
 }
 
 static int
@@ -4308,12 +4308,12 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
 			 */
 			if ((!ext4_ext_is_unwritten(ex)) &&
 			    (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) {
-				allocated = convert_initialized_extent(
-						handle, inode, map, &path,
-						allocated);
+				err = convert_initialized_extent(handle,
+					inode, map, &path, &allocated);
 				goto out2;
-			} else if (!ext4_ext_is_unwritten(ex))
+			} else if (!ext4_ext_is_unwritten(ex)) {
 				goto out;
+			}
 
 			ret = ext4_ext_handle_unwritten_extents(
 				handle, inode, map, &path, flags,
-- 
2.11.0


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

* Re: [PATCH] ext4: clean up error return for convert_initialized_extent()
  2020-02-18 20:26 [PATCH] ext4: clean up error return for convert_initialized_extent() Eric Whitney
@ 2020-03-06  1:28 ` Theodore Y. Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Y. Ts'o @ 2020-03-06  1:28 UTC (permalink / raw)
  To: Eric Whitney; +Cc: linux-ext4

On Tue, Feb 18, 2020 at 03:26:56PM -0500, Eric Whitney wrote:
> Although convert_initialized_extent() can potentially return an error
> code with a negative value, its returned value is assigned to an
> unsigned variable containing a block count in ext4_ext_map_blocks() and
> then returned to that function's caller. The code currently works,
> though the way this happens is obscure.  The code would be more
> readable if it followed the error handling convention used elsewhere
> in ext4_ext_map_blocks().
> 
> This patch does not address any known test failure or bug report - it's
> simply a cleanup.  It also addresses a nearby coding standard issue.
> 
> Signed-off-by: Eric Whitney <enwlinux@gmail.com>

Thanks, applied.

					- Ted

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

end of thread, other threads:[~2020-03-06  1:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-18 20:26 [PATCH] ext4: clean up error return for convert_initialized_extent() Eric Whitney
2020-03-06  1:28 ` Theodore Y. Ts'o

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.