platform/mellanox: mlxreg-lc: Fix locking issue
authorVadim Pasternak <vadimp@nvidia.com>
Tue, 23 Aug 2022 20:19:35 +0000 (23:19 +0300)
committerHans de Goede <hdegoede@redhat.com>
Thu, 1 Sep 2022 12:20:42 +0000 (14:20 +0200)
commit52e01c0b1d80b0a7e8d9970456e10b788398e633
tree49a548e7abb2ad224fb27c4f9b169eda867c70b8
parent16b36a953bc7fc4843568abcdb7b32f92cc65457
platform/mellanox: mlxreg-lc: Fix locking issue

Fix locking issues:
- mlxreg_lc_state_update() takes a lock when set or clear
  "MLXREG_LC_POWERED".
- All the devices can be deleted before MLXREG_LC_POWERED flag is cleared.

To fix it:
- Add lock() / unlock() at the beginning / end of
  mlxreg_lc_event_handler() and remove locking from
  mlxreg_lc_power_on_off() and mlxreg_lc_enable_disable()
- Add locked version of mlxreg_lc_state_update() -
  mlxreg_lc_state_update_locked() for using outside
  mlxreg_lc_event_handler().

(2) Remove redundant NULL check for of if 'data->notifier'.

Fixes: 62f9529b8d5c87b ("platform/mellanox: mlxreg-lc: Add initial support for Nvidia line card devices")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
Link: https://lore.kernel.org/r/20220823201937.46855-3-vadimp@nvidia.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/mellanox/mlxreg-lc.c