Subject: Re: [PATCH v1 iwl-next] igc: Add support for LEDs on i225/i226

From: Simon Horman <[email-masked]>
Date: Wed, 24 Jan 2024 21:08:55 +0000

On Wed, Jan 24, 2024 at 09:24:08AM +0100, Kurt Kanzenbach wrote:

...

> +static int igc_led_hw_control_set(struct led_classdev *led_cdev,
> +				  unsigned long flags)
> +{
> +	struct igc_led_classdev *ldev = lcdev_to_igc_ldev(led_cdev);
> +	struct igc_adapter *adapter = netdev_priv(ldev->netdev);
> +	bool blink = false;
> +	u32 mode;
> +
> +	if (flags & BIT(TRIGGER_NETDEV_LINK_10))
> +		mode = IGC_LEDCTL_MODE_LINK_10;
> +	if (flags & BIT(TRIGGER_NETDEV_LINK_100))
> +		mode = IGC_LEDCTL_MODE_LINK_100;
> +	if (flags & BIT(TRIGGER_NETDEV_LINK_1000))
> +		mode = IGC_LEDCTL_MODE_LINK_1000;
> +	if (flags & BIT(TRIGGER_NETDEV_LINK_2500))
> +		mode = IGC_LEDCTL_MODE_LINK_2500;
> +	if ((flags & BIT(TRIGGER_NETDEV_TX)) ||
> +	    (flags & BIT(TRIGGER_NETDEV_RX)))
> +		mode = IGC_LEDCTL_MODE_ACTIVITY;

Hi Kurt,

I guess this can't happen in practice,
but if none of the conditions above are met,
then mode is used uninitialised below.

Flagged by Smatch.

> +
> +	/* blink is recommended for activity */
> +	if (mode == IGC_LEDCTL_MODE_ACTIVITY)
> +		blink = true;
> +
> +	igc_led_set(adapter, ldev->index, mode, blink);
> +
> +	return 0;
> +}

...