803-v6.5-05-leds-trigger-netdev-Use-mutex-instead-of-spinlocks.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. From d1b9e1391ab2dc80e9db87fe8b2de015c651e4c9 Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Wed, 19 Apr 2023 23:07:43 +0200
  4. Subject: [PATCH 5/5] leds: trigger: netdev: Use mutex instead of spinlocks
  5. Some LEDs may require to sleep while doing some operation like setting
  6. brightness and other cleanup.
  7. For this reason, using a spinlock will cause a sleep under spinlock
  8. warning.
  9. It should be safe to convert this to a sleepable lock since:
  10. - sysfs read/write can sleep
  11. - netdev_trig_work is a work queue and can sleep
  12. - netdev _trig_notify can sleep
  13. The spinlock was used when brightness didn't support sleeping, but this
  14. changed and now it supported with brightness_set_blocking().
  15. Convert to mutex lock to permit sleeping using brightness_set_blocking().
  16. Signed-off-by: Christian Marangi <[email protected]>
  17. Reviewed-by: Andrew Lunn <[email protected]>
  18. Signed-off-by: Lee Jones <[email protected]>
  19. Link: https://lore.kernel.org/r/[email protected]
  20. ---
  21. drivers/leds/trigger/ledtrig-netdev.c | 18 +++++++++---------
  22. 1 file changed, 9 insertions(+), 9 deletions(-)
  23. --- a/drivers/leds/trigger/ledtrig-netdev.c
  24. +++ b/drivers/leds/trigger/ledtrig-netdev.c
  25. @@ -20,7 +20,7 @@
  26. #include <linux/list.h>
  27. #include <linux/module.h>
  28. #include <linux/netdevice.h>
  29. -#include <linux/spinlock.h>
  30. +#include <linux/mutex.h>
  31. #include <linux/timer.h>
  32. #include "../leds.h"
  33. @@ -37,7 +37,7 @@
  34. */
  35. struct led_netdev_data {
  36. - spinlock_t lock;
  37. + struct mutex lock;
  38. struct delayed_work work;
  39. struct notifier_block notifier;
  40. @@ -97,9 +97,9 @@ static ssize_t device_name_show(struct d
  41. struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
  42. ssize_t len;
  43. - spin_lock_bh(&trigger_data->lock);
  44. + mutex_lock(&trigger_data->lock);
  45. len = sprintf(buf, "%s\n", trigger_data->device_name);
  46. - spin_unlock_bh(&trigger_data->lock);
  47. + mutex_unlock(&trigger_data->lock);
  48. return len;
  49. }
  50. @@ -115,7 +115,7 @@ static ssize_t device_name_store(struct
  51. cancel_delayed_work_sync(&trigger_data->work);
  52. - spin_lock_bh(&trigger_data->lock);
  53. + mutex_lock(&trigger_data->lock);
  54. if (trigger_data->net_dev) {
  55. dev_put(trigger_data->net_dev);
  56. @@ -138,7 +138,7 @@ static ssize_t device_name_store(struct
  57. trigger_data->last_activity = 0;
  58. set_baseline_state(trigger_data);
  59. - spin_unlock_bh(&trigger_data->lock);
  60. + mutex_unlock(&trigger_data->lock);
  61. return size;
  62. }
  63. @@ -279,7 +279,7 @@ static int netdev_trig_notify(struct not
  64. cancel_delayed_work_sync(&trigger_data->work);
  65. - spin_lock_bh(&trigger_data->lock);
  66. + mutex_lock(&trigger_data->lock);
  67. trigger_data->carrier_link_up = false;
  68. switch (evt) {
  69. @@ -304,7 +304,7 @@ static int netdev_trig_notify(struct not
  70. set_baseline_state(trigger_data);
  71. - spin_unlock_bh(&trigger_data->lock);
  72. + mutex_unlock(&trigger_data->lock);
  73. return NOTIFY_DONE;
  74. }
  75. @@ -365,7 +365,7 @@ static int netdev_trig_activate(struct l
  76. if (!trigger_data)
  77. return -ENOMEM;
  78. - spin_lock_init(&trigger_data->lock);
  79. + mutex_init(&trigger_data->lock);
  80. trigger_data->notifier.notifier_call = netdev_trig_notify;
  81. trigger_data->notifier.priority = 10;