hwmon: Add support for Amphenol ChipCap 2
Hello Javier Carrasco,
The patch 33c41faa98f3: "hwmon: Add support for Amphenol ChipCap 2" from Jan 30, 2024 (linux-next), leads to the following Smatch static checker warning:
drivers/hwmon/chipcap2.c:327 cc2_get_reg_val() error: uninitialized symbol 'reg_val'. drivers/hwmon/chipcap2.c:695 cc2_request_alarm_irqs() error: uninitialized symbol 'ret'.
drivers/hwmon/chipcap2.c
669 static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev)
670 {
671 int ret;Set this to ret = -ENODEV?
672
673 data->irq_low = fwnode_irq_get_byname(dev_fwnode(dev), "low");
674 if (data->irq_low > 0) {
675 ret = devm_request_threaded_irq(dev, data->irq_low, NULL,
676 cc2_low_interrupt,
677 IRQF_ONESHOT |
678 IRQF_TRIGGER_RISING,
679 dev_name(dev), data);
680 if (!ret)
681 data->rh_alarm.low_alarm_visible = true;
682 }
683
684 data->irq_high = fwnode_irq_get_byname(dev_fwnode(dev), "high");
685 if (data->irq_high > 0) {
686 ret = devm_request_threaded_irq(dev, data->irq_high, NULL,
687 cc2_high_interrupt,
688 IRQF_ONESHOT |
689 IRQF_TRIGGER_RISING,
690 dev_name(dev), data);
691 if (!ret)
692 data->rh_alarm.high_alarm_visible = true;
693 }
694
--> 695 return ret;
696 }regards,
dan carpenter
Hello Dan,
Quoted 42 lines · Dan Carpenter
Hello Javier Carrasco,
The patch
33c41faa98f3: "hwmon: Add support for Amphenol ChipCap 2" from Jan 30, 2024 (linux-next), leads to the following Smatch static checker warning:
drivers/hwmon/chipcap2.c:327cc2_get_reg_val()error: uninitialized symbol 'reg_val'.drivers/hwmon/chipcap2.c:695cc2_request_alarm_irqs()error: uninitialized symbol 'ret'.
drivers/hwmon/chipcap2.c669 static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) 670 { 671 int ret;Set this to ret =
-ENODEV?672 673 data->irq_low = fwnode_irq_get_byname(dev_fwnode(dev), "low"); 674 if (data->irq_low > 0) { 675 ret = devm_request_threaded_irq(dev, data->irq_low, NULL, 676 cc2_low_interrupt, 677 IRQF_ONESHOT | 678 IRQF_TRIGGER_RISING, 679 dev_name(dev), data); 680 if (!ret) 681 data->rh_alarm.low_alarm_visible = true; 682 } 683 684 data->irq_high = fwnode_irq_get_byname(dev_fwnode(dev), "high"); 685 if (data->irq_high > 0) { 686 ret = devm_request_threaded_irq(dev, data->irq_high, NULL, 687 cc2_high_interrupt, 688 IRQF_ONESHOT | 689 IRQF_TRIGGER_RISING, 690 dev_name(dev), data); 691 if (!ret) 692 data->rh_alarm.high_alarm_visible = true; 693 } 694 --> 695 return ret; 696 }
Quoted 2 lines
regards,
dan carpenter
The ret variable should be initialized to 0 because if no irqs are defined, the function should not fail i.e. the driver supports that case. That is probably the reason why I did not notice in my tests.
The reg_val symbol might stay unassigned if the function that assigns its value fails, and the check of the error return value is missing.
I will fix both issues asap.
Thanks a lot for your feedback and best regards,
Javier Carrasco
Quoted 4 lines · Javier Carrasco
The ret variable should be initialized to 0 because if no irqs are defined, the function should not fail i.e. the driver supports that case. That is probably the reason why I did not notice in my tests.
These days everyone has the GCC extension to automatically zero out stack variables so it wouldn't have shown up in testing. It's still technically a bug, but I don't know how many people it would affect in real life (probably a small number).
regards,
dan carpenter
Quoted 6 lines · Dan Carpenter
Quoted 4 lines · Javier Carrasco
The ret variable should be initialized to 0 because if no irqs are defined, the function should not fail i.e. the driver supports that case. That is probably the reason why I did not notice in my tests.
Quoted 8 lines
These days everyone has the GCC extension to automatically zero out stack variables so it wouldn't have shown up in testing. It's still technically a bug, but I don't know how many people it would affect in real life (probably a small number).
regards,
dan carpenter
That is right, but because a small number is greater than zero, I am glad that you found this issue now before the driver is released.
By the way, Smatch caught this while gcc, coccinelle and the language server protocol I use did not... great tool.
Bests regards,
Javier Carrasco
Guenter Roeck
maintainerQuoted 14 lines · Javier Carrasco
Quoted 11 lines · Dan Carpenter
Quoted 4 lines · Javier Carrasco
The ret variable should be initialized to 0 because if no irqs are defined, the function should not fail i.e. the driver supports that case. That is probably the reason why I did not notice in my tests.
These days everyone has the GCC extension to automatically zero out stack variables so it wouldn't have shown up in testing. It's still technically a bug, but I don't know how many people it would affect in real life (probably a small number).
Quoted 9 lines
Quoted 3 lines
regards,
dan carpenterThat is right, but because a small number is greater than zero, I am glad that you found this issue now before the driver is released.
By the way, Smatch caught this while gcc, coccinelle and the language server protocol I use did not... great tool.
gcc is notoriously bad with finding uninitialized variable problems. Maybe that is because of that gcc extension, I don't know. It is quite annoying, though.
Guenter
Hello again Dan,
Quoted 9 lines · Dan Carpenter
Hello Javier Carrasco,
The patch
33c41faa98f3: "hwmon: Add support for Amphenol ChipCap 2" from Jan 30, 2024 (linux-next), leads to the following Smatch static checker warning:
drivers/hwmon/chipcap2.c:327cc2_get_reg_val()error: uninitialized symbol 'reg_val'.drivers/hwmon/chipcap2.c:695cc2_request_alarm_irqs()error: uninitialized symbol 'ret'.
may I ask you what Smatch configuration/arguments you used to find the first warning? I tried kchecker without arguments (with --sparse nothing was found), and only the second warning is reported:
~/smatch/smatch_scripts/kchecker drivers/hwmon/chipcap2.c
CHECK scripts/mod/empty.c
CALL scripts/checksyscalls.sh CC drivers/hwmon/chipcap2.o CHECK drivers/hwmon/chipcap2.c
drivers/hwmon/chipcap2.c:695 cc2_request_alarm_irqs() error:
uninitialized symbol 'ret'.
I have checked out the current status of the master branch:
7162b9ec99f71 double_fget: warn about re-using file descriptors
And of course, the first bug was not removed from the code.
Thanks and best regards,
Javier Carrasco
Quoted 23 lines · Javier Carrasco
Hello again Dan,
Quoted 9 lines · Dan Carpenter
Hello Javier Carrasco,
The patch
33c41faa98f3: "hwmon: Add support for Amphenol ChipCap 2" from Jan 30, 2024 (linux-next), leads to the following Smatch static checker warning:
drivers/hwmon/chipcap2.c:327cc2_get_reg_val()error: uninitialized symbol 'reg_val'.drivers/hwmon/chipcap2.c:695cc2_request_alarm_irqs()error: uninitialized symbol 'ret'.may I ask you what Smatch configuration/arguments you used to find the first warning? I tried kchecker without arguments (with --sparse nothing was found), and only the second warning is reported:
~/smatch/smatch_scripts/kchecker
drivers/hwmon/chipcap2.cCHECK
scripts/mod/empty.cCALL scripts/checksyscalls.sh CC drivers/hwmon/chipcap2.o CHECK drivers/hwmon/chipcap2.c
Quoted 8 lines
drivers/hwmon/chipcap2.c:695cc2_request_alarm_irqs()error:
uninitialized symbol 'ret'.I have checked out the current status of the master branch:
7162b9ec99f71double_fget: warn about re-using file descriptorsAnd of course, the first bug was not removed from the code.
The first warning requires the cross function database to work. It's a simple process but it takes probably 6 hours...
~/smatch/devel/smatch_scripts/build_kernel_data.sh
regards,
dan carpenter