]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
mac80211: ath9k: rework led allocation 21933/head
authorRosen Penev <rosenp@gmail.com>
Sun, 8 Jun 2025 03:13:26 +0000 (20:13 -0700)
committerRobert Marko <robimarko@gmail.com>
Fri, 6 Mar 2026 11:03:10 +0000 (12:03 +0100)
Embed gpio_led struct in ath_led. Simpler Allocation.

Use a flex array for the name. Allows using a single allocation.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/21933
Signed-off-by: Robert Marko <robimarko@gmail.com>
package/kernel/mac80211/patches/ath11k/948-wifi-ath11k-Fix-the-WMM-param-type.patch
package/kernel/mac80211/patches/ath9k/530-ath9k_extra_leds.patch
package/kernel/mac80211/patches/ath9k/547-ath9k_led_defstate_fix.patch
package/kernel/mac80211/patches/ath9k/548-ath9k_enable_gpio_chip.patch

index df3643e3ee75a2a9c7e0a4b2d1fcc84f68ad5bad..174f02be8159d933926cd8a81cc1ca2c4a1af7ee 100644 (file)
@@ -13,7 +13,7 @@ Signed-off-by: PaweÅ‚ Owoc <frut3k7@gmail.com>
 
 --- a/drivers/net/wireless/ath/ath11k/wmi.c
 +++ b/drivers/net/wireless/ath/ath11k/wmi.c
-@@ -2682,7 +2682,7 @@ int ath11k_wmi_send_wmm_update_cmd_tlv(s
+@@ -2688,7 +2688,7 @@ int ath11k_wmi_send_wmm_update_cmd_tlv(s
                          FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
  
        cmd->vdev_id = vdev_id;
index b92c19849e01269d23d41eba57a6ec270ed4df6b..ad025b4e081ec72c790c574d278eb456e244d9df 100644 (file)
  #else
  static inline void ath_init_leds(struct ath_softc *sc)
  {
-@@ -980,6 +983,13 @@ void ath_ant_comb_scan(struct ath_softc
+@@ -980,6 +983,14 @@ void ath_ant_comb_scan(struct ath_softc
  
  #define ATH9K_NUM_CHANCTX  2 /* supports 2 operating channels */
  
 +struct ath_led {
 +      struct list_head list;
 +      struct ath_softc *sc;
-+      const struct gpio_led *gpio;
++      struct gpio_led gpio;
 +      struct led_classdev cdev;
++      char name[];
 +};
 +
  struct ath_softc {
        struct ieee80211_hw *hw;
        struct device *dev;
-@@ -1035,9 +1045,8 @@ struct ath_softc {
+@@ -1035,9 +1046,8 @@ struct ath_softc {
        spinlock_t chan_lock;
  
  #ifdef CPTCFG_MAC80211_LEDS
@@ -38,7 +39,7 @@
  #ifdef CPTCFG_ATH9K_DEBUGFS
 --- a/drivers/net/wireless/ath/ath9k/gpio.c
 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
-@@ -39,61 +39,111 @@ static void ath_fill_led_pin(struct ath_
+@@ -39,61 +39,112 @@ static void ath_fill_led_pin(struct ath_
                else
                        ah->led_pin = ATH_LED_PIN_DEF;
        }
 +{
 +      struct ath_led *led = container_of(led_cdev, struct ath_led, cdev);
 +      struct ath_softc *sc = led->sc;
++      const struct gpio_led *gpio = &led->gpio;
 +
 +      ath9k_ps_wakeup(sc);
-+      ath9k_hw_set_gpio(sc->sc_ah, led->gpio->gpio,
-+                        (brightness != LED_OFF) ^ led->gpio->active_low);
++      ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio,
++                        (brightness != LED_OFF) ^ gpio->active_low);
 +      ath9k_ps_restore(sc);
 +}
 +
 +static int ath_add_led(struct ath_softc *sc, struct ath_led *led)
 +{
-+      const struct gpio_led *gpio = led->gpio;
++      const struct gpio_led *gpio = &led->gpio;
 +      int ret;
 +
 +      led->cdev.name = gpio->name;
 -      u32 val = (brightness == LED_OFF);
 +      struct ath_led *led;
 +      struct gpio_led *gpio;
-+      char *_name;
 +      int ret;
  
 -      if (sc->sc_ah->config.led_active_high)
 -              val = !val;
-+      led = kzalloc(sizeof(*led) + sizeof(*gpio) + strlen(name) + 1,
-+                    GFP_KERNEL);
++      led = kzalloc(struct_size(led, name, strlen(name) + 1), GFP_KERNEL);
 +      if (!led)
 +              return -ENOMEM;
 +
-+      led->gpio = gpio = (struct gpio_led *) (led + 1);
-+      _name = (char *) (led->gpio + 1);
++      strcpy(led->name, name);
 +
-+      strcpy(_name, name);
-+      gpio->name = _name;
++      gpio = &led->gpio;
++      gpio->name = led->name;
 +      gpio->gpio = gpio_num;
 +      gpio->active_low = active_low;
 +      gpio->default_trigger = trigger;
 +
 +      ret = ath_add_led(sc, led);
-+      if (unlikely(ret < 0))
-+              kfree(led);
++      if (likely(ret >= 0))
++              return ret;
  
 -      ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, val);
++      kfree(led);
 +      return ret;
  }
  
 -      if (!sc->led_registered)
 -              return;
 +      struct ath_led *led;
++      struct gpio_led *gpio;
  
 -      ath_led_brightness(&sc->led_cdev, LED_OFF);
 -      led_classdev_unregister(&sc->led_cdev);
 +              list_del(&led->list);
 +              ath_led_brightness(&led->cdev, LED_OFF);
 +              led_classdev_unregister(&led->cdev);
-+              ath9k_hw_gpio_free(sc->sc_ah, led->gpio->gpio);
++              gpio = &led->gpio;
++              ath9k_hw_gpio_free(sc->sc_ah, gpio->gpio);
 +              kfree(led);
 +      }
  }
index d633c051b0d04c945fc884ade2f38ab1a93c62ea..5d84cf0c423a6138b0a48305006202f00e4bbdef 100644 (file)
@@ -13,7 +13,7 @@ Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
 
 --- a/drivers/net/wireless/ath/ath9k/gpio.c
 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
-@@ -73,8 +73,11 @@ static int ath_add_led(struct ath_softc
+@@ -74,8 +74,11 @@ static int ath_add_led(struct ath_softc
        ath9k_hw_gpio_request_out(sc->sc_ah, gpio->gpio, gpio->name,
                                  AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  
index 56f59ce89a6da5b96e0323003a3f7ca6e57760ad..3365f441e62ff6cf3fede215d1d64187564aeba3 100644 (file)
@@ -19,7 +19,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  
  #include "common.h"
  #include "debug.h"
-@@ -1047,6 +1049,10 @@ struct ath_softc {
+@@ -1048,6 +1050,10 @@ struct ath_softc {
  #ifdef CPTCFG_MAC80211_LEDS
        const char *led_default_trigger;
        struct list_head leds;
@@ -157,7 +157,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  static void ath_fill_led_pin(struct ath_softc *sc)
  {
        struct ath_hw *ah = sc->sc_ah;
-@@ -79,6 +189,12 @@ static int ath_add_led(struct ath_softc
+@@ -80,6 +190,12 @@ static int ath_add_led(struct ath_softc
        else
                ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
  
@@ -170,7 +170,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
        return 0;
  }
  
-@@ -117,16 +233,23 @@ void ath_deinit_leds(struct ath_softc *s
+@@ -117,6 +233,11 @@ void ath_deinit_leds(struct ath_softc *s
  
        while (!list_empty(&sc->leds)) {
                led = list_first_entry(&sc->leds, struct ath_led, list);
@@ -182,27 +182,20 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
                list_del(&led->list);
                ath_led_brightness(&led->cdev, LED_OFF);
                led_classdev_unregister(&led->cdev);
-               ath9k_hw_gpio_free(sc->sc_ah, led->gpio->gpio);
+@@ -124,6 +245,7 @@ void ath_deinit_leds(struct ath_softc *s
+               ath9k_hw_gpio_free(sc->sc_ah, gpio->gpio);
                kfree(led);
        }
 +      ath9k_unregister_gpio_chip(sc);
  }
  
  void ath_init_leds(struct ath_softc *sc)
- {
-+      struct device_node *np = sc->dev->of_node;
-       char led_name[32];
-       const char *trigger;
-@@ -135,6 +258,15 @@ void ath_init_leds(struct ath_softc *sc)
+@@ -136,6 +258,12 @@ void ath_init_leds(struct ath_softc *sc)
        if (AR_SREV_9100(sc->sc_ah))
                return;
  
-+      if (!np)
-+              ath9k_register_gpio_chip(sc);
-+
 +      /* setup gpio controller only if requested and skip the led_pin setup */
-+      if (of_property_read_bool(np, "gpio-controller")) {
++      if (device_property_present(sc->dev, "gpio-controller")) {
 +              ath9k_register_gpio_chip(sc);
 +              return;
 +      }