diff mbox series

[1/2] virtiofs: Improve three size determinations

Message ID 02fe18da-55f5-47c5-a297-58411edbb78b@web.de (mailing list archive)
State New
Headers show
Series virtiofs: Adjustments for two function implementations | expand

Commit Message

Markus Elfring Dec. 29, 2023, 8:36 a.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 29 Dec 2023 08:42:04 +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/fuse/virtio_fs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--
2.43.0

Comments

Vivek Goyal Jan. 2, 2024, 8:41 p.m. UTC | #1
On Fri, Dec 29, 2023 at 09:36:36AM +0100, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 29 Dec 2023 08:42:04 +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.

I had a look at coding-style.rst and it does say that dereferencing the
pointer is preferred form. Primary argument seems to be that somebody
might change the pointer variable type but not the corresponding type
passed to sizeof().

There is some value to the argument. I don't feel strongly about it.

Miklos, if you like this change, feel free to apply. 

Thanks
Vivek
  
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  fs/fuse/virtio_fs.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
> index 5f1be1da92ce..2f8ba9254c1e 100644
> --- a/fs/fuse/virtio_fs.c
> +++ b/fs/fuse/virtio_fs.c
> @@ -1435,11 +1435,11 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
>  		goto out_err;
> 
>  	err = -ENOMEM;
> -	fc = kzalloc(sizeof(struct fuse_conn), GFP_KERNEL);
> +	fc = kzalloc(sizeof(*fc), GFP_KERNEL);
>  	if (!fc)
>  		goto out_err;
> 
> -	fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
> +	fm = kzalloc(sizeof(*fm), GFP_KERNEL);
>  	if (!fm)
>  		goto out_err;
> 
> @@ -1495,7 +1495,7 @@ static int virtio_fs_init_fs_context(struct fs_context *fsc)
>  	if (fsc->purpose == FS_CONTEXT_FOR_SUBMOUNT)
>  		return fuse_init_fs_context_submount(fsc);
> 
> -	ctx = kzalloc(sizeof(struct fuse_fs_context), GFP_KERNEL);
> +	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
>  	if (!ctx)
>  		return -ENOMEM;
>  	fsc->fs_private = ctx;
> --
> 2.43.0
> 
>
diff mbox series

Patch

diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 5f1be1da92ce..2f8ba9254c1e 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1435,11 +1435,11 @@  static int virtio_fs_get_tree(struct fs_context *fsc)
 		goto out_err;

 	err = -ENOMEM;
-	fc = kzalloc(sizeof(struct fuse_conn), GFP_KERNEL);
+	fc = kzalloc(sizeof(*fc), GFP_KERNEL);
 	if (!fc)
 		goto out_err;

-	fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
+	fm = kzalloc(sizeof(*fm), GFP_KERNEL);
 	if (!fm)
 		goto out_err;

@@ -1495,7 +1495,7 @@  static int virtio_fs_init_fs_context(struct fs_context *fsc)
 	if (fsc->purpose == FS_CONTEXT_FOR_SUBMOUNT)
 		return fuse_init_fs_context_submount(fsc);

-	ctx = kzalloc(sizeof(struct fuse_fs_context), GFP_KERNEL);
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
 	fsc->fs_private = ctx;