diff mbox series

[net-next] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event()

Message ID 20230804092636.91357-1-lizetao1@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net/mlx5: Devcom, only use devcom after NULL check in mlx5_devcom_send_event() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1328 this patch: 1328
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 1351 this patch: 1351
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1351 this patch: 1351
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Li Zetao Aug. 4, 2023, 9:26 a.m. UTC
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(-)

Comments

Vadim Fedorenko Aug. 4, 2023, 8:53 p.m. UTC | #1
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));
Roi Dayan Aug. 13, 2023, 8:02 a.m. UTC | #2
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));
>
diff mbox series

Patch

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));