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:22:48 +0000 (14:22 +0200)
commit1e092b7faa6b507125b69c92a51bb22c2d549d37
tree7be25d4651aa62d430a74af598ccad6764d3b647
parent17c2bd6bea4c32fe691c1f9ebcc20fd48d77454a
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