Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (chipcap2) fix return path in cc2_request_alarm_irqs()

The return path can be improved by returning upon first failure. The
current implementation would try to register the second interrupt even
if the first one failed, which is unnecessary.

Moreover, if no irqs are available, the return value should be zero
(the driver supports the use case with no interrupts). Currently the
initial value is unassigned and that may lead to returning an unknown
value if stack variables are not automatically set to zero and no irqs
were provided.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-hwmon/294e4634-89d4-415e-a723-b208d8770d7c@gmail.com/T/#t
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240207-chipcap2_init_vars-v1-2-08cafe43e20e@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Javier Carrasco and committed by
Guenter Roeck
efd49b8e f16fb6d2

+9 -5
+9 -5
drivers/hwmon/chipcap2.c
··· 670 670 671 671 static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) 672 672 { 673 - int ret; 673 + int ret = 0; 674 674 675 675 data->irq_low = fwnode_irq_get_byname(dev_fwnode(dev), "low"); 676 676 if (data->irq_low > 0) { ··· 679 679 IRQF_ONESHOT | 680 680 IRQF_TRIGGER_RISING, 681 681 dev_name(dev), data); 682 - if (!ret) 683 - data->rh_alarm.low_alarm_visible = true; 682 + if (ret) 683 + return ret; 684 + 685 + data->rh_alarm.low_alarm_visible = true; 684 686 } 685 687 686 688 data->irq_high = fwnode_irq_get_byname(dev_fwnode(dev), "high"); ··· 692 690 IRQF_ONESHOT | 693 691 IRQF_TRIGGER_RISING, 694 692 dev_name(dev), data); 695 - if (!ret) 696 - data->rh_alarm.high_alarm_visible = true; 693 + if (ret) 694 + return ret; 695 + 696 + data->rh_alarm.high_alarm_visible = true; 697 697 } 698 698 699 699 return ret;