diff mbox

[1/5] mlx5: Use NULL instead of 0 to represent a pointer

Message ID 16dc2a07-86f7-ce47-7b0c-1da03e58d99f@sandisk.com (mailing list archive)
State Accepted
Headers show

Commit Message

Bart Van Assche Dec. 6, 2016, 1:18 a.m. UTC
Detected by sparse.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Eli Cohen <eli@mellanox.com>
---
 drivers/infiniband/hw/mlx5/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Leon Romanovsky Dec. 6, 2016, 1:59 p.m. UTC | #1
On Mon, Dec 05, 2016 at 05:18:08PM -0800, Bart Van Assche wrote:
> Detected by sparse.
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Eli Cohen <eli@mellanox.com>
> ---
>  drivers/infiniband/hw/mlx5/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> index 32b09f059c84..abd200e3e299 100644
> --- a/drivers/infiniband/hw/mlx5/main.c
> +++ b/drivers/infiniband/hw/mlx5/main.c
> @@ -127,7 +127,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
>  
>  		if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev))
>  		    && ibdev->ib_active) {
> -			struct ib_event ibev = {0};
> +			struct ib_event ibev = { NULL };

I afraid that it is sparse anomality and because NULL==0, the ibev.event
will be initialized to zero, but it is a matter of time when the sparse
will complain about wrong initialization again.

>  
>  			ibev.device = &ibdev->ib_dev;
>  			ibev.event = (event == NETDEV_UP) ?
> -- 
> 2.11.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jason Gunthorpe Dec. 6, 2016, 4:28 p.m. UTC | #2
On Tue, Dec 06, 2016 at 03:59:17PM +0200, Leon Romanovsky wrote:
> On Mon, Dec 05, 2016 at 05:18:08PM -0800, Bart Van Assche wrote:
> > Detected by sparse.
> > 
> > Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> > Cc: Eli Cohen <eli@mellanox.com>
> >  drivers/infiniband/hw/mlx5/main.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> > index 32b09f059c84..abd200e3e299 100644
> > +++ b/drivers/infiniband/hw/mlx5/main.c
> > @@ -127,7 +127,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
> >  
> >  		if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev))
> >  		    && ibdev->ib_active) {
> > -			struct ib_event ibev = {0};
> > +			struct ib_event ibev = { NULL };
> 
> I afraid that it is sparse anomality and because NULL==0, the ibev.event
> will be initialized to zero, but it is a matter of time when the sparse
> will complain about wrong initialization again.

Use '= {}' for zeroing structs.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bart Van Assche Dec. 6, 2016, 4:29 p.m. UTC | #3
On 12/06/2016 05:59 AM, Leon Romanovsky wrote:
> On Mon, Dec 05, 2016 at 05:18:08PM -0800, Bart Van Assche wrote:
>> Detected by sparse.
>>
>> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
>> Cc: Eli Cohen <eli@mellanox.com>
>> ---
>>  drivers/infiniband/hw/mlx5/main.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
>> index 32b09f059c84..abd200e3e299 100644
>> --- a/drivers/infiniband/hw/mlx5/main.c
>> +++ b/drivers/infiniband/hw/mlx5/main.c
>> @@ -127,7 +127,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
>>
>>  		if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev))
>>  		    && ibdev->ib_active) {
>> -			struct ib_event ibev = {0};
>> +			struct ib_event ibev = { NULL };
>
> I afraid that it is sparse anomality and because NULL==0, the ibev.event
> will be initialized to zero, but it is a matter of time when the sparse
> will complain about wrong initialization again.

Hello Leon,

The first member of struct ib_event is a pointer so I think the sparse 
complaint is correct. Anyway, how about one of the following two 
alternatives:
* Change {0} into { }.
* Use memset() instead of an initializer.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Leon Romanovsky Dec. 7, 2016, 8:21 a.m. UTC | #4
On Tue, Dec 06, 2016 at 08:29:56AM -0800, Bart Van Assche wrote:
> On 12/06/2016 05:59 AM, Leon Romanovsky wrote:
> > On Mon, Dec 05, 2016 at 05:18:08PM -0800, Bart Van Assche wrote:
> > > Detected by sparse.
> > > 
> > > Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> > > Cc: Eli Cohen <eli@mellanox.com>
> > > ---
> > >  drivers/infiniband/hw/mlx5/main.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> > > index 32b09f059c84..abd200e3e299 100644
> > > --- a/drivers/infiniband/hw/mlx5/main.c
> > > +++ b/drivers/infiniband/hw/mlx5/main.c
> > > @@ -127,7 +127,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
> > > 
> > >  		if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev))
> > >  		    && ibdev->ib_active) {
> > > -			struct ib_event ibev = {0};
> > > +			struct ib_event ibev = { NULL };
> > 
> > I afraid that it is sparse anomality and because NULL==0, the ibev.event
> > will be initialized to zero, but it is a matter of time when the sparse
> > will complain about wrong initialization again.
> 
> Hello Leon,
> 
> The first member of struct ib_event is a pointer so I think the sparse
> complaint is correct. 

Yes, sparse didn't iterate all fields of this struct. This is why I
called it "sparse anomality".

> Anyway, how about one of the following two
> alternatives:
> * Change {0} into { }.

Yes, please.
Thanks

> * Use memset() instead of an initializer.
> 
> Bart.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Doug Ledford Dec. 14, 2016, 6:44 p.m. UTC | #5
On 12/7/2016 3:21 AM, Leon Romanovsky wrote:
> On Tue, Dec 06, 2016 at 08:29:56AM -0800, Bart Van Assche wrote:

>> Anyway, how about one of the following two
>> alternatives:
>> * Change {0} into { }.
> 
> Yes, please.
> Thanks

Fixed this one up and applied it.
diff mbox

Patch

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 32b09f059c84..abd200e3e299 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -127,7 +127,7 @@  static int mlx5_netdev_event(struct notifier_block *this,
 
 		if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev))
 		    && ibdev->ib_active) {
-			struct ib_event ibev = {0};
+			struct ib_event ibev = { NULL };
 
 			ibev.device = &ibdev->ib_dev;
 			ibev.event = (event == NETDEV_UP) ?