public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Russell King <linux@armlinux.org.uk>,
	Gregory Clement <gregory.clement@bootlin.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next v4 4/8] net: Add helpers for netdev LEDs
Date: Thu, 11 Apr 2024 02:32:21 +0300	[thread overview]
Message-ID: <20240410233221.ntpxm7hfjiwod32u@skbuf> (raw)
In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-4-eb97665e7f96@lunn.ch>

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
> 

  parent reply	other threads:[~2024-04-10 23:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-06 20:13 [PATCH net-next v4 0/8] net: Add generic support for netdev LEDs Andrew Lunn
2024-04-06 20:13 ` [PATCH net-next v4 1/8] net: dsa: consolidate setup and teardown for shared ports Andrew Lunn
2024-04-06 20:13 ` [PATCH net-next v4 2/8] net: dsa: break out port setup and teardown code per port type Andrew Lunn
2024-04-06 20:13 ` [PATCH net-next v4 3/8] net: dsa: move call to driver port_setup after creation of netdev Andrew Lunn
2024-04-10 23:50   ` Vladimir Oltean
2024-04-06 20:13 ` [PATCH net-next v4 4/8] net: Add helpers for netdev LEDs Andrew Lunn
2024-04-07 17:26   ` Andrew Lunn
2024-04-10 23:32   ` Vladimir Oltean [this message]
2024-04-06 20:13 ` [PATCH net-next v4 5/8] net: dsa: mv88e6xxx: Add helpers for 6352 LED blink and brightness Andrew Lunn
2024-04-06 20:13 ` [PATCH net-next v4 6/8] net: dsa: mv88e6xxx: Tie the low level LED functions to device ops Andrew Lunn
2024-04-06 20:13 ` [PATCH net-next v4 7/8] dsa: mv88e6xxx: Create port/netdev LEDs Andrew Lunn
2024-04-10 23:45   ` Vladimir Oltean
2024-04-06 20:13 ` [PATCH net-next v4 8/8] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs Andrew Lunn
2024-06-26 12:16 ` [PATCH net-next v4 0/8] net: Add generic support for netdev LEDs Vladimir Oltean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240410233221.ntpxm7hfjiwod32u@skbuf \
    --to=olteanv@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregory.clement@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox