netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event()
@ 2023-08-04  9:26 Li Zetao
  2023-08-04 20:53 ` Vadim Fedorenko
  0 siblings, 1 reply; 5+ messages in thread
From: Li Zetao @ 2023-08-04  9:26 UTC (permalink / raw)
  To: saeedm, leon, davem, edumazet, kuba
  Cc: lizetao1, pabeni, shayd, roid, mbloch, vladbu, elic, netdev,
	linux-rdma

There is a warning reported by kernel test robot:

smatch warnings:
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c:264
    mlx5_devcom_send_event() warn: variable dereferenced before
	IS_ERR check devcom (see line 259)

The reason for the warning is that the pointer is used before check, put
the assignment to comp after devcom check to silence the warning.

Fixes: 88d162b47981 ("net/mlx5: Devcom, Infrastructure changes")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202308041028.AkXYDwJ6-lkp@intel.com/
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
index feb62d952643..2bc18274858c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
@@ -256,7 +256,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
 			   int event, int rollback_event,
 			   void *event_data)
 {
-	struct mlx5_devcom_comp *comp = devcom->comp;
+	struct mlx5_devcom_comp *comp;
 	struct mlx5_devcom_comp_dev *pos;
 	int err = 0;
 	void *data;
@@ -264,6 +264,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
 	if (IS_ERR_OR_NULL(devcom))
 		return -ENODEV;
 
+	comp = devcom->comp;
 	down_write(&comp->sem);
 	list_for_each_entry(pos, &comp->comp_dev_list_head, list) {
 		data = rcu_dereference_protected(pos->data, lockdep_is_held(&comp->sem));
-- 
2.34.1


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

* Re: [PATCH net-next] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event()
  2023-08-04  9:26 [PATCH net-next] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event() Li Zetao
@ 2023-08-04 20:53 ` Vadim Fedorenko
  2023-08-13  8:02   ` Roi Dayan
  2023-08-14  7:23   ` [PATCH -next v2] " Li Zetao
  0 siblings, 2 replies; 5+ messages in thread
From: Vadim Fedorenko @ 2023-08-04 20:53 UTC (permalink / raw)
  To: Li Zetao, saeedm, leon, davem, edumazet, kuba
  Cc: pabeni, shayd, roid, mbloch, vladbu, elic, netdev, linux-rdma

On 04/08/2023 10:26, Li Zetao wrote:
> There is a warning reported by kernel test robot:
> 
> smatch warnings:
> drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c:264
>      mlx5_devcom_send_event() warn: variable dereferenced before
> 	IS_ERR check devcom (see line 259)
> 
> The reason for the warning is that the pointer is used before check, put
> the assignment to comp after devcom check to silence the warning.
> 
> Fixes: 88d162b47981 ("net/mlx5: Devcom, Infrastructure changes")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Closes: https://lore.kernel.org/r/202308041028.AkXYDwJ6-lkp@intel.com/
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
> index feb62d952643..2bc18274858c 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
> @@ -256,7 +256,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
>   			   int event, int rollback_event,
>   			   void *event_data)
>   {
> -	struct mlx5_devcom_comp *comp = devcom->comp;
> +	struct mlx5_devcom_comp *comp;
>   	struct mlx5_devcom_comp_dev *pos;

The code should end up with reverse x-mas tree order.
The change itself LGTM.

>   	int err = 0;
>   	void *data;
> @@ -264,6 +264,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
>   	if (IS_ERR_OR_NULL(devcom))
>   		return -ENODEV;
>   
> +	comp = devcom->comp;
>   	down_write(&comp->sem);
>   	list_for_each_entry(pos, &comp->comp_dev_list_head, list) {
>   		data = rcu_dereference_protected(pos->data, lockdep_is_held(&comp->sem));


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

* Re: [PATCH net-next] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event()
  2023-08-04 20:53 ` Vadim Fedorenko
@ 2023-08-13  8:02   ` Roi Dayan
  2023-08-14  7:23   ` [PATCH -next v2] " Li Zetao
  1 sibling, 0 replies; 5+ messages in thread
From: Roi Dayan @ 2023-08-13  8:02 UTC (permalink / raw)
  To: Vadim Fedorenko, Li Zetao, saeedm, leon, davem, edumazet, kuba
  Cc: pabeni, shayd, mbloch, vladbu, elic, netdev, linux-rdma



On 04/08/2023 23:53, Vadim Fedorenko wrote:
> On 04/08/2023 10:26, Li Zetao wrote:
>> There is a warning reported by kernel test robot:
>>
>> smatch warnings:
>> drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c:264
>>      mlx5_devcom_send_event() warn: variable dereferenced before
>>     IS_ERR check devcom (see line 259)
>>
>> The reason for the warning is that the pointer is used before check, put
>> the assignment to comp after devcom check to silence the warning.
>>
>> Fixes: 88d162b47981 ("net/mlx5: Devcom, Infrastructure changes")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Reported-by: Dan Carpenter <error27@gmail.com>
>> Closes: https://lore.kernel.org/r/202308041028.AkXYDwJ6-lkp@intel.com/
>> Signed-off-by: Li Zetao <lizetao1@huawei.com>
>> ---
>>   drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
>> index feb62d952643..2bc18274858c 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
>> @@ -256,7 +256,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
>>                  int event, int rollback_event,
>>                  void *event_data)
>>   {
>> -    struct mlx5_devcom_comp *comp = devcom->comp;
>> +    struct mlx5_devcom_comp *comp;
>>       struct mlx5_devcom_comp_dev *pos;
> 
> The code should end up with reverse x-mas tree order.
> The change itself LGTM.
> 


Hi Li,

Are you going to submit v2 ?

Thanks,
Roi


>>       int err = 0;
>>       void *data;
>> @@ -264,6 +264,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
>>       if (IS_ERR_OR_NULL(devcom))
>>           return -ENODEV;
>>   +    comp = devcom->comp;
>>       down_write(&comp->sem);
>>       list_for_each_entry(pos, &comp->comp_dev_list_head, list) {
>>           data = rcu_dereference_protected(pos->data, lockdep_is_held(&comp->sem));
> 

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

* [PATCH -next v2] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event()
  2023-08-04 20:53 ` Vadim Fedorenko
  2023-08-13  8:02   ` Roi Dayan
@ 2023-08-14  7:23   ` Li Zetao
  2023-08-14 10:11     ` Leon Romanovsky
  1 sibling, 1 reply; 5+ messages in thread
From: Li Zetao @ 2023-08-14  7:23 UTC (permalink / raw)
  To: vadim.fedorenko
  Cc: davem, edumazet, elic, kuba, leon, linux-rdma, lizetao1, mbloch,
	netdev, pabeni, roid, saeedm, shayd, vladbu, kernel test robot,
	Dan Carpenter

There is a warning reported by kernel test robot:

smatch warnings:
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c:264
	mlx5_devcom_send_event() warn: variable dereferenced before
		IS_ERR check devcom (see line 259)

The reason for the warning is that the pointer is used before check, put
the assignment to comp after devcom check to silence the warning.

Fixes: 88d162b47981 ("net/mlx5: Devcom, Infrastructure changes")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202308041028.AkXYDwJ6-lkp@intel.com/
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: Modify the order of variable declarations to end up with reverse x-mas tree order.
v1: https://lore.kernel.org/all/20230804092636.91357-1-lizetao1@huawei.com/

 drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
index feb62d952643..00e67910e3ee 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
@@ -256,14 +256,15 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
 			   int event, int rollback_event,
 			   void *event_data)
 {
-	struct mlx5_devcom_comp *comp = devcom->comp;
 	struct mlx5_devcom_comp_dev *pos;
+	struct mlx5_devcom_comp *comp;
 	int err = 0;
 	void *data;
 
 	if (IS_ERR_OR_NULL(devcom))
 		return -ENODEV;
 
+	comp = devcom->comp;
 	down_write(&comp->sem);
 	list_for_each_entry(pos, &comp->comp_dev_list_head, list) {
 		data = rcu_dereference_protected(pos->data, lockdep_is_held(&comp->sem));
-- 
2.34.1


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

* Re: [PATCH -next v2] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event()
  2023-08-14  7:23   ` [PATCH -next v2] " Li Zetao
@ 2023-08-14 10:11     ` Leon Romanovsky
  0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2023-08-14 10:11 UTC (permalink / raw)
  To: Li Zetao
  Cc: vadim.fedorenko, davem, edumazet, elic, kuba, linux-rdma, mbloch,
	netdev, pabeni, roid, saeedm, shayd, vladbu, kernel test robot,
	Dan Carpenter

On Mon, Aug 14, 2023 at 03:23:42PM +0800, Li Zetao wrote:
> There is a warning reported by kernel test robot:
> 
> smatch warnings:
> drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c:264
> 	mlx5_devcom_send_event() warn: variable dereferenced before
> 		IS_ERR check devcom (see line 259)
> 
> The reason for the warning is that the pointer is used before check, put
> the assignment to comp after devcom check to silence the warning.
> 
> Fixes: 88d162b47981 ("net/mlx5: Devcom, Infrastructure changes")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Closes: https://lore.kernel.org/r/202308041028.AkXYDwJ6-lkp@intel.com/
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
> v1 -> v2: Modify the order of variable declarations to end up with reverse x-mas tree order.
> v1: https://lore.kernel.org/all/20230804092636.91357-1-lizetao1@huawei.com/
> 
>  drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

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

end of thread, other threads:[~2023-08-14 10:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-04  9:26 [PATCH net-next] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event() Li Zetao
2023-08-04 20:53 ` Vadim Fedorenko
2023-08-13  8:02   ` Roi Dayan
2023-08-14  7:23   ` [PATCH -next v2] " Li Zetao
2023-08-14 10:11     ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).