[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240410233221.ntpxm7hfjiwod32u@skbuf>
Date: Thu, 11 Apr 2024 02:32:21 +0300
From: Vladimir Oltean <olteanv@...il.com>
To: Andrew Lunn <andrew@...n.ch>
Cc: Florian Fainelli <f.fainelli@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Russell King <linux@...linux.org.uk>,
Gregory Clement <gregory.clement@...tlin.com>,
netdev@...r.kernel.org
Subject: Re: [PATCH net-next v4 4/8] net: Add helpers for netdev LEDs
On Sat, Apr 06, 2024 at 03:13:31PM -0500, Andrew Lunn wrote:
> +/**
> + * netdev_leds_setup - Parse DT node and create LEDs for netdev
> + *
> + * @ndev: struct netdev for the MAC
> + * @np: ethernet-node in device tree
> + * @list: list to add LEDs to
> + * @ops: structure of ops to manipulate the LED.
> + * @max_leds: maximum number of LEDs support by netdev.
> + *
> + * Parse the device tree node, as described in
> + * ethernet-controller.yaml, and find any LEDs. For each LED found,
> + * ensure the reg value is less than max_leds, create an LED and
> + * register it with the LED subsystem. The LED will be added to the
> + * list, which should be unique to the netdev. The ops structure
> + * contains the callbacks needed to control the LEDs.
> + *
> + * Return 0 in success, otherwise an negative error code.
> + */
> +int netdev_leds_setup(struct net_device *ndev, struct device_node *np,
> + struct list_head *list, struct netdev_leds_ops *ops,
> + int max_leds)
> +{
> + struct device_node *leds, *led;
> + int err;
> +
> + leds = of_get_child_by_name(np, "leds");
> + if (!leds)
> + return 0;
> +
> + for_each_available_child_of_node(leds, led) {
> + err = netdev_led_setup(ndev, led, list, ops, max_leds);
> + if (err) {
> + of_node_put(leds);
> + of_node_put(led);
> + return err;
> + }
> + }
> + of_node_put(leds);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(netdev_leds_setup);
> +
> +/**
> + * netdev_leds_teardown - Remove LEDs for a netdev
> + *
> + * @list: list to add LEDs to teardown
> + *
> + * Unregister all LEDs from the given list of LEDS, freeing up any
> + * allocated memory.
> + */
> +void netdev_leds_teardown(struct list_head *list)
> +{
> + struct netdev_led *netdev_led;
> + struct led_classdev *cdev;
> +
> + list_for_each_entry(netdev_led, list, led_list) {
list_for_each_entry_safe(), since there is a kfree() inside.
> + cdev = &netdev_led->led_cdev;
> + led_classdev_unregister(cdev);
> + kfree(netdev_led);
> + }
> +}
> +EXPORT_SYMBOL_GPL(netdev_leds_teardown);
>
> --
> 2.43.0
>
Powered by blists - more mailing lists