[PATCH] ceph: Use struct_size() helper

Thorsten Blum posted 1 patch 2 months, 2 weeks ago
fs/ceph/addr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] ceph: Use struct_size() helper
Posted by Thorsten Blum 2 months, 2 weeks ago
Use struct_size() to calculate the number of bytes to be allocated.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 fs/ceph/addr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index c4744a02db75..ab494f250d80 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -2133,7 +2133,7 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci,
 	}
 
 	pool_ns_len = pool_ns ? pool_ns->len : 0;
-	perm = kmalloc(sizeof(*perm) + pool_ns_len + 1, GFP_NOFS);
+	perm = kmalloc(struct_size(perm, pool_ns, pool_ns_len + 1), GFP_NOFS);
 	if (!perm) {
 		err = -ENOMEM;
 		goto out_unlock;
-- 
2.46.0
Re: [PATCH] ceph: Use struct_size() helper
Posted by Ilya Dryomov 2 months ago
On Thu, Sep 12, 2024 at 5:39 PM Thorsten Blum <thorsten.blum@toblux.com> wrote:
>
> Use struct_size() to calculate the number of bytes to be allocated.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  fs/ceph/addr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index c4744a02db75..ab494f250d80 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -2133,7 +2133,7 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci,
>         }
>
>         pool_ns_len = pool_ns ? pool_ns->len : 0;
> -       perm = kmalloc(sizeof(*perm) + pool_ns_len + 1, GFP_NOFS);
> +       perm = kmalloc(struct_size(perm, pool_ns, pool_ns_len + 1), GFP_NOFS);
>         if (!perm) {
>                 err = -ENOMEM;
>                 goto out_unlock;
> --
> 2.46.0
>

Applied.

Thanks,

                Ilya