2020-09-17 07:54:07

by Liu Shixin

[permalink] [raw]
Subject: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

sizeof() when applied to a pointer typed expression should gives the
size of the pointed data, even if the data is a pointer.

Signed-off-by: Liu Shixin <[email protected]>
---
drivers/infiniband/hw/mlx5/counters.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/counters.c b/drivers/infiniband/hw/mlx5/counters.c
index 145f3cb40ccb..aeeb14ecb3ee 100644
--- a/drivers/infiniband/hw/mlx5/counters.c
+++ b/drivers/infiniband/hw/mlx5/counters.c
@@ -456,12 +456,12 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev,
cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts);
num_counters += ARRAY_SIZE(ext_ppcnt_cnts);
}
- cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL);
+ cnts->names = kcalloc(num_counters, sizeof(*cnts->names), GFP_KERNEL);
if (!cnts->names)
return -ENOMEM;

cnts->offsets = kcalloc(num_counters,
- sizeof(cnts->offsets), GFP_KERNEL);
+ sizeof(*cnts->offsets), GFP_KERNEL);
if (!cnts->offsets)
goto err_names;

--
2.25.1


2020-09-17 08:32:07

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 04:13:54PM +0800, Liu Shixin wrote:
> sizeof() when applied to a pointer typed expression should gives the

gives -> give

> size of the pointed data, even if the data is a pointer.
>
> Signed-off-by: Liu Shixin <[email protected]>
> ---
> drivers/infiniband/hw/mlx5/counters.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>

Thanks,
Acked-by: Leon Romanovsky <[email protected]>

2020-09-17 08:50:01

by Liu Shixin

[permalink] [raw]
Subject: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

sizeof() when applied to a pointer typed expression should give the
size of the pointed data, even if the data is a pointer.

Signed-off-by: Liu Shixin <[email protected]>
---
drivers/infiniband/hw/mlx5/counters.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/counters.c b/drivers/infiniband/hw/mlx5/counters.c
index 145f3cb40ccb..aeeb14ecb3ee 100644
--- a/drivers/infiniband/hw/mlx5/counters.c
+++ b/drivers/infiniband/hw/mlx5/counters.c
@@ -456,12 +456,12 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev,
cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts);
num_counters += ARRAY_SIZE(ext_ppcnt_cnts);
}
- cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL);
+ cnts->names = kcalloc(num_counters, sizeof(*cnts->names), GFP_KERNEL);
if (!cnts->names)
return -ENOMEM;

cnts->offsets = kcalloc(num_counters,
- sizeof(cnts->offsets), GFP_KERNEL);
+ sizeof(*cnts->offsets), GFP_KERNEL);
if (!cnts->offsets)
goto err_names;

--
2.25.1

2020-09-17 09:09:52

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 05:10:08PM +0800, Liu Shixin wrote:
> sizeof() when applied to a pointer typed expression should give the
> size of the pointed data, even if the data is a pointer.
>
> Signed-off-by: Liu Shixin <[email protected]>
> ---
> drivers/infiniband/hw/mlx5/counters.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/hw/mlx5/counters.c b/drivers/infiniband/hw/mlx5/counters.c
> index 145f3cb40ccb..aeeb14ecb3ee 100644
> --- a/drivers/infiniband/hw/mlx5/counters.c
> +++ b/drivers/infiniband/hw/mlx5/counters.c
> @@ -456,12 +456,12 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev,
> cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts);
> num_counters += ARRAY_SIZE(ext_ppcnt_cnts);
> }
> - cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL);
> + cnts->names = kcalloc(num_counters, sizeof(*cnts->names), GFP_KERNEL);

This change is correct.

> if (!cnts->names)
> return -ENOMEM;
>
> cnts->offsets = kcalloc(num_counters,
> - sizeof(cnts->offsets), GFP_KERNEL);
> + sizeof(*cnts->offsets), GFP_KERNEL);

This is not.


> if (!cnts->offsets)
> goto err_names;
>
> --
> 2.25.1
>

2020-09-17 09:33:20

by Liu Shixin

[permalink] [raw]
Subject: [PATCH -next v2] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

sizeof() when applied to a pointer typed expression should give the
size of the pointed data, even if the data is a pointer.

Signed-off-by: Liu Shixin <[email protected]>
---
drivers/infiniband/hw/mlx5/counters.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx5/counters.c b/drivers/infiniband/hw/mlx5/counters.c
index 8d77fea0eb48..6f8a8b558070 100644
--- a/drivers/infiniband/hw/mlx5/counters.c
+++ b/drivers/infiniband/hw/mlx5/counters.c
@@ -457,7 +457,7 @@ static int __mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev,
cnts->num_ext_ppcnt_counters = ARRAY_SIZE(ext_ppcnt_cnts);
num_counters += ARRAY_SIZE(ext_ppcnt_cnts);
}
- cnts->names = kcalloc(num_counters, sizeof(cnts->names), GFP_KERNEL);
+ cnts->names = kcalloc(num_counters, sizeof(*cnts->names), GFP_KERNEL);
if (!cnts->names)
return -ENOMEM;

--
2.25.1

2020-09-17 10:12:07

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH -next v2] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 05:52:16PM +0800, Liu Shixin wrote:
> sizeof() when applied to a pointer typed expression should give the
> size of the pointed data, even if the data is a pointer.
>
> Signed-off-by: Liu Shixin <[email protected]>
> ---
> drivers/infiniband/hw/mlx5/counters.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>

Thanks,
Acked-by: Leon Romanovsky <[email protected]>

2020-09-17 13:00:22

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 12:08:10PM +0300, Leon Romanovsky wrote:
> On Thu, Sep 17, 2020 at 05:10:08PM +0800, Liu Shixin wrote:
> > sizeof() when applied to a pointer typed expression should give the
> > size of the pointed data, even if the data is a pointer.
> >
> > Signed-off-by: Liu Shixin <[email protected]>

Needs a fixes line

> > if (!cnts->names)
> > return -ENOMEM;
> >
> > cnts->offsets = kcalloc(num_counters,
> > - sizeof(cnts->offsets), GFP_KERNEL);
> > + sizeof(*cnts->offsets), GFP_KERNEL);
>
> This is not.

Why not?

Jason

2020-09-17 17:07:19

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 09:38:06AM -0300, Jason Gunthorpe wrote:
> On Thu, Sep 17, 2020 at 12:08:10PM +0300, Leon Romanovsky wrote:
> > On Thu, Sep 17, 2020 at 05:10:08PM +0800, Liu Shixin wrote:
> > > sizeof() when applied to a pointer typed expression should give the
> > > size of the pointed data, even if the data is a pointer.
> > >
> > > Signed-off-by: Liu Shixin <[email protected]>
>
> Needs a fixes line
>
> > > if (!cnts->names)
> > > return -ENOMEM;
> > >
> > > cnts->offsets = kcalloc(num_counters,
> > > - sizeof(cnts->offsets), GFP_KERNEL);
> > > + sizeof(*cnts->offsets), GFP_KERNEL);
> >
> > This is not.
>
> Why not?

cnts->offsets is array of pointers that we will set later.
The "sizeof(*cnts->offsets)" will return the size of size_t, while we
need to get "size_t *".

Thanks

>
> Jason

2020-09-17 17:36:37

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 02:24:51PM -0300, Jason Gunthorpe wrote:
> On Thu, Sep 17, 2020 at 08:05:11PM +0300, Leon Romanovsky wrote:
> > On Thu, Sep 17, 2020 at 09:38:06AM -0300, Jason Gunthorpe wrote:
> > > On Thu, Sep 17, 2020 at 12:08:10PM +0300, Leon Romanovsky wrote:
> > > > On Thu, Sep 17, 2020 at 05:10:08PM +0800, Liu Shixin wrote:
> > > > > sizeof() when applied to a pointer typed expression should give the
> > > > > size of the pointed data, even if the data is a pointer.
> > > > >
> > > > > Signed-off-by: Liu Shixin <[email protected]>
> > >
> > > Needs a fixes line
> > >
> > > > > if (!cnts->names)
> > > > > return -ENOMEM;
> > > > >
> > > > > cnts->offsets = kcalloc(num_counters,
> > > > > - sizeof(cnts->offsets), GFP_KERNEL);
> > > > > + sizeof(*cnts->offsets), GFP_KERNEL);
> > > >
> > > > This is not.
> > >
> > > Why not?
> >
> > cnts->offsets is array of pointers that we will set later.
> > The "sizeof(*cnts->offsets)" will return the size of size_t, while we
> > need to get "size_t *".
>
> Then why isn't a pointer to size **?
>
> Something is rotten here

No problem, I'll check.

>
> Jason

2020-09-17 18:39:26

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 08:05:11PM +0300, Leon Romanovsky wrote:
> On Thu, Sep 17, 2020 at 09:38:06AM -0300, Jason Gunthorpe wrote:
> > On Thu, Sep 17, 2020 at 12:08:10PM +0300, Leon Romanovsky wrote:
> > > On Thu, Sep 17, 2020 at 05:10:08PM +0800, Liu Shixin wrote:
> > > > sizeof() when applied to a pointer typed expression should give the
> > > > size of the pointed data, even if the data is a pointer.
> > > >
> > > > Signed-off-by: Liu Shixin <[email protected]>
> >
> > Needs a fixes line
> >
> > > > if (!cnts->names)
> > > > return -ENOMEM;
> > > >
> > > > cnts->offsets = kcalloc(num_counters,
> > > > - sizeof(cnts->offsets), GFP_KERNEL);
> > > > + sizeof(*cnts->offsets), GFP_KERNEL);
> > >
> > > This is not.
> >
> > Why not?
>
> cnts->offsets is array of pointers that we will set later.
> The "sizeof(*cnts->offsets)" will return the size of size_t, while we
> need to get "size_t *".

Then why isn't a pointer to size **?

Something is rotten here

Jason

2020-09-18 03:25:20

by Liu Shixin

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On 2020/9/18 1:33, Leon Romanovsky wrote:
> On Thu, Sep 17, 2020 at 02:24:51PM -0300, Jason Gunthorpe wrote:
>> On Thu, Sep 17, 2020 at 08:05:11PM +0300, Leon Romanovsky wrote:
>>> On Thu, Sep 17, 2020 at 09:38:06AM -0300, Jason Gunthorpe wrote:
>>>> On Thu, Sep 17, 2020 at 12:08:10PM +0300, Leon Romanovsky wrote:
>>>>> On Thu, Sep 17, 2020 at 05:10:08PM +0800, Liu Shixin wrote:
>>>>>> sizeof() when applied to a pointer typed expression should give the
>>>>>> size of the pointed data, even if the data is a pointer.
>>>>>>
>>>>>> Signed-off-by: Liu Shixin <[email protected]>
>>>> Needs a fixes line
>>>>
>>>>>> if (!cnts->names)
>>>>>> return -ENOMEM;
>>>>>>
>>>>>> cnts->offsets = kcalloc(num_counters,
>>>>>> - sizeof(cnts->offsets), GFP_KERNEL);
>>>>>> + sizeof(*cnts->offsets), GFP_KERNEL);
>>>>> This is not.
>>>> Why not?
>>> cnts->offsets is array of pointers that we will set later.
>>> The "sizeof(*cnts->offsets)" will return the size of size_t, while we
>>> need to get "size_t *".
>> Then why isn't a pointer to size **?
>>
>> Something is rotten here
> No problem, I'll check.
I think cnts->offsets is an array pointer whose element is size_t rathen than pointer,
so the patch description does not correspond.
And I think it should be modified to sizeof(*cnts->offsets) with other description.
>
>> Jason
> .
>

2020-09-21 13:27:50

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Fri, Sep 18, 2020 at 11:23:18AM +0800, Liu Shixin wrote:
> On 2020/9/18 1:33, Leon Romanovsky wrote:
> > On Thu, Sep 17, 2020 at 02:24:51PM -0300, Jason Gunthorpe wrote:
> >> On Thu, Sep 17, 2020 at 08:05:11PM +0300, Leon Romanovsky wrote:
> >>> On Thu, Sep 17, 2020 at 09:38:06AM -0300, Jason Gunthorpe wrote:
> >>>> On Thu, Sep 17, 2020 at 12:08:10PM +0300, Leon Romanovsky wrote:
> >>>>> On Thu, Sep 17, 2020 at 05:10:08PM +0800, Liu Shixin wrote:
> >>>>>> sizeof() when applied to a pointer typed expression should give the
> >>>>>> size of the pointed data, even if the data is a pointer.
> >>>>>>
> >>>>>> Signed-off-by: Liu Shixin <[email protected]>
> >>>> Needs a fixes line
> >>>>
> >>>>>> if (!cnts->names)
> >>>>>> return -ENOMEM;
> >>>>>>
> >>>>>> cnts->offsets = kcalloc(num_counters,
> >>>>>> - sizeof(cnts->offsets), GFP_KERNEL);
> >>>>>> + sizeof(*cnts->offsets), GFP_KERNEL);
> >>>>> This is not.
> >>>> Why not?
> >>> cnts->offsets is array of pointers that we will set later.
> >>> The "sizeof(*cnts->offsets)" will return the size of size_t, while we
> >>> need to get "size_t *".
> >> Then why isn't a pointer to size **?
> >>
> >> Something is rotten here
> > No problem, I'll check.
> I think cnts->offsets is an array pointer whose element is size_t rathen than pointer,
> so the patch description does not correspond.
> And I think it should be modified to sizeof(*cnts->offsets) with other description.

Sorry for me being wrong, you are right.

Thanks

> >
> >> Jason
> > .
> >
>

2020-09-25 12:43:25

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH -next] RDMA/mlx5: fix type warning of sizeof in __mlx5_ib_alloc_counters()

On Thu, Sep 17, 2020 at 04:13:54PM +0800, Liu Shixin wrote:
> sizeof() when applied to a pointer typed expression should gives the
> size of the pointed data, even if the data is a pointer.
>
> Signed-off-by: Liu Shixin <[email protected]>
> ---
> drivers/infiniband/hw/mlx5/counters.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

Applied the original version to for-next

Thanks,
Jason