[PATCH] fs:fc_log replace magic number 7 with ARRAY_SIZE()

Guo Weikang posted 1 patch 1 year, 2 months ago
fs/fs_context.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] fs:fc_log replace magic number 7 with ARRAY_SIZE()
Posted by Guo Weikang 1 year, 2 months ago
Replace the hardcoded value `7` in `put_fc_log()` with `ARRAY_SIZE`.
This improves maintainability by ensuring the loop adapts to changes
in the buffer size.

Signed-off-by: Guo Weikang <guoweikang.kernel@gmail.com>
---
 fs/fs_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fs_context.c b/fs/fs_context.c
index 98589aae5208..582d33e81117 100644
--- a/fs/fs_context.c
+++ b/fs/fs_context.c
@@ -493,7 +493,7 @@ static void put_fc_log(struct fs_context *fc)
 	if (log) {
 		if (refcount_dec_and_test(&log->usage)) {
 			fc->log.log = NULL;
-			for (i = 0; i <= 7; i++)
+			for (i = 0; i < ARRAY_SIZE(log->buffer) ; i++)
 				if (log->need_free & (1 << i))
 					kfree(log->buffer[i]);
 			kfree(log);
-- 
2.25.1
Re: [PATCH] fs:fc_log replace magic number 7 with ARRAY_SIZE()
Posted by Jan Kara 1 year, 2 months ago
On Mon 02-12-24 16:11:45, Guo Weikang wrote:
> Replace the hardcoded value `7` in `put_fc_log()` with `ARRAY_SIZE`.
> This improves maintainability by ensuring the loop adapts to changes
> in the buffer size.
> 
> Signed-off-by: Guo Weikang <guoweikang.kernel@gmail.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/fs_context.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/fs_context.c b/fs/fs_context.c
> index 98589aae5208..582d33e81117 100644
> --- a/fs/fs_context.c
> +++ b/fs/fs_context.c
> @@ -493,7 +493,7 @@ static void put_fc_log(struct fs_context *fc)
>  	if (log) {
>  		if (refcount_dec_and_test(&log->usage)) {
>  			fc->log.log = NULL;
> -			for (i = 0; i <= 7; i++)
> +			for (i = 0; i < ARRAY_SIZE(log->buffer) ; i++)
>  				if (log->need_free & (1 << i))
>  					kfree(log->buffer[i]);
>  			kfree(log);
> -- 
> 2.25.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
Re: [PATCH] fs: fc_log replace magic number 7 with ARRAY_SIZE()
Posted by Christian Brauner 1 year, 2 months ago
On Mon, 02 Dec 2024 16:11:45 +0800, Guo Weikang wrote:
> Replace the hardcoded value `7` in `put_fc_log()` with `ARRAY_SIZE`.
> This improves maintainability by ensuring the loop adapts to changes
> in the buffer size.
> 
> 

Applied to the vfs-6.14.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.14.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.14.misc

[1/1] fs:fc_log replace magic number 7 with ARRAY_SIZE()
      https://git.kernel.org/vfs/vfs/c/6814aad4d6ce