linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] hugetlbfs: Adjustments for two function implementations
@ 2023-12-29 11:36 Markus Elfring
  2023-12-29 11:37 ` [PATCH 1/2] hugetlbfs: Improve a size determination in two functions Markus Elfring
  2023-12-29 11:40 ` [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super() Markus Elfring
  0 siblings, 2 replies; 6+ messages in thread
From: Markus Elfring @ 2023-12-29 11:36 UTC (permalink / raw)
  To: linux-mm, kernel-janitors, Muchun Song; +Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 29 Dec 2023 12:32:12 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Improve a size determination in two functions
  Improve exception handling in hugetlbfs_fill_super()

 fs/hugetlbfs/inode.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

--
2.43.0



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

* [PATCH 1/2] hugetlbfs: Improve a size determination in two functions
  2023-12-29 11:36 [PATCH 0/2] hugetlbfs: Adjustments for two function implementations Markus Elfring
@ 2023-12-29 11:37 ` Markus Elfring
  2024-01-02  2:57   ` Muchun Song
  2023-12-29 11:40 ` [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super() Markus Elfring
  1 sibling, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2023-12-29 11:37 UTC (permalink / raw)
  To: linux-mm, kernel-janitors, Muchun Song; +Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 29 Dec 2023 11:32:07 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator “sizeof” to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/hugetlbfs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index ea5b8e57d904..24401a5046dd 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1460,7 +1460,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	struct hugetlbfs_fs_context *ctx = fc->fs_private;
 	struct hugetlbfs_sb_info *sbinfo;

-	sbinfo = kmalloc(sizeof(struct hugetlbfs_sb_info), GFP_KERNEL);
+	sbinfo = kmalloc(sizeof(*sbinfo), GFP_KERNEL);
 	if (!sbinfo)
 		return -ENOMEM;
 	sb->s_fs_info = sbinfo;
@@ -1530,7 +1530,7 @@ static int hugetlbfs_init_fs_context(struct fs_context *fc)
 {
 	struct hugetlbfs_fs_context *ctx;

-	ctx = kzalloc(sizeof(struct hugetlbfs_fs_context), GFP_KERNEL);
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;

--
2.43.0



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

* [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super()
  2023-12-29 11:36 [PATCH 0/2] hugetlbfs: Adjustments for two function implementations Markus Elfring
  2023-12-29 11:37 ` [PATCH 1/2] hugetlbfs: Improve a size determination in two functions Markus Elfring
@ 2023-12-29 11:40 ` Markus Elfring
  2023-12-29 14:52   ` Matthew Wilcox
  1 sibling, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2023-12-29 11:40 UTC (permalink / raw)
  To: linux-mm, kernel-janitors, Muchun Song; +Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 29 Dec 2023 11:46:32 +0100

The kfree() function was called in one case by
the hugetlbfs_fill_super() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus adjust jump targets.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/hugetlbfs/inode.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 24401a5046dd..5687ec574dc4 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1483,7 +1483,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
 						     ctx->max_hpages,
 						     ctx->min_hpages);
 		if (!sbinfo->spool)
-			goto out_free;
+			goto free_sbinfo;
 	}
 	sb->s_maxbytes = MAX_LFS_FILESIZE;
 	sb->s_blocksize = huge_page_size(ctx->hstate);
@@ -1499,10 +1499,12 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	sb->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
 	sb->s_root = d_make_root(hugetlbfs_get_root(sb, ctx));
 	if (!sb->s_root)
-		goto out_free;
+		goto free_spool;
 	return 0;
-out_free:
+
+free_spool:
 	kfree(sbinfo->spool);
+free_sbinfo:
 	kfree(sbinfo);
 	return -ENOMEM;
 }
--
2.43.0



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

* Re: [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super()
  2023-12-29 11:40 ` [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super() Markus Elfring
@ 2023-12-29 14:52   ` Matthew Wilcox
  2023-12-30  6:45     ` Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2023-12-29 14:52 UTC (permalink / raw)
  To: Markus Elfring; +Cc: linux-mm, kernel-janitors, Muchun Song, LKML

On Fri, Dec 29, 2023 at 12:40:12PM +0100, Markus Elfring wrote:
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 24401a5046dd..5687ec574dc4 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -1483,7 +1483,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
>  						     ctx->max_hpages,
>  						     ctx->min_hpages);
>  		if (!sbinfo->spool)
> -			goto out_free;
> +			goto free_sbinfo;
>  	}
>  	sb->s_maxbytes = MAX_LFS_FILESIZE;
>  	sb->s_blocksize = huge_page_size(ctx->hstate);
> @@ -1499,10 +1499,12 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
>  	sb->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
>  	sb->s_root = d_make_root(hugetlbfs_get_root(sb, ctx));
>  	if (!sb->s_root)
> -		goto out_free;
> +		goto free_spool;
>  	return 0;
> -out_free:
> +
> +free_spool:
>  	kfree(sbinfo->spool);
> +free_sbinfo:
>  	kfree(sbinfo);
>  	return -ENOMEM;
>  }

This is more complex.  NACK.


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

* Re: [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super()
  2023-12-29 14:52   ` Matthew Wilcox
@ 2023-12-30  6:45     ` Markus Elfring
  0 siblings, 0 replies; 6+ messages in thread
From: Markus Elfring @ 2023-12-30  6:45 UTC (permalink / raw)
  To: Matthew Wilcox, linux-mm; +Cc: kernel-janitors, Muchun Song, LKML

>> +++ b/fs/hugetlbfs/inode.c
>> @@ -1483,7 +1483,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
>>  						     ctx->max_hpages,
>>  						     ctx->min_hpages);
>>  		if (!sbinfo->spool)
>> -			goto out_free;
>> +			goto free_sbinfo;
>>  	}
>>  	sb->s_maxbytes = MAX_LFS_FILESIZE;
>>  	sb->s_blocksize = huge_page_size(ctx->hstate);
>> @@ -1499,10 +1499,12 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
>>  	sb->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
>>  	sb->s_root = d_make_root(hugetlbfs_get_root(sb, ctx));
>>  	if (!sb->s_root)
>> -		goto out_free;
>> +		goto free_spool;
>>  	return 0;
>> -out_free:
>> +
>> +free_spool:
>>  	kfree(sbinfo->spool);
>> +free_sbinfo:
>>  	kfree(sbinfo);
>>  	return -ENOMEM;
>>  }
>
> This is more complex.  NACK.

I am curious how coding style preferences will evolve further.

See also:
https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources

Regards,
Markus


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

* Re: [PATCH 1/2] hugetlbfs: Improve a size determination in two functions
  2023-12-29 11:37 ` [PATCH 1/2] hugetlbfs: Improve a size determination in two functions Markus Elfring
@ 2024-01-02  2:57   ` Muchun Song
  0 siblings, 0 replies; 6+ messages in thread
From: Muchun Song @ 2024-01-02  2:57 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Linux-MM, kernel-janitors, LKML



> On Dec 29, 2023, at 19:37, Markus Elfring <Markus.Elfring@web.de> wrote:
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 29 Dec 2023 11:32:07 +0100
> 
> Replace the specification of data structures by pointer dereferences
> as the parameter for the operator “sizeof” to make the corresponding size
> determination a bit safer according to the Linux coding style convention.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Reviewed-by: Muchun Song <songmuchun@bytedance.com>

Thanks.



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

end of thread, other threads:[~2024-01-02  2:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-29 11:36 [PATCH 0/2] hugetlbfs: Adjustments for two function implementations Markus Elfring
2023-12-29 11:37 ` [PATCH 1/2] hugetlbfs: Improve a size determination in two functions Markus Elfring
2024-01-02  2:57   ` Muchun Song
2023-12-29 11:40 ` [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super() Markus Elfring
2023-12-29 14:52   ` Matthew Wilcox
2023-12-30  6:45     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox