net: pse-pd: Avoid setting max_uA in regulator constraints
Hello Kory Maincent,
Commit 675d0e3cacc3 ("net: pse-pd: Avoid setting max_uA in regulator constraints") from Jan 10, 2025 (linux-next), leads to the following Smatch static checker warning:
drivers/net/pse-pd/pse_core.c:810 pse_pi_set_current_limit() warn: AAA no lower bound on 'max_uA' rl='s32min-(-1),1-1920000'
drivers/net/pse-pd/pse_core.c
783 static int pse_pi_set_current_limit(struct regulator_dev *rdev, int min_uA,
784 int max_uA)
785 {
786 struct pse_controller_dev *pcdev = rdev_get_drvdata(rdev);
787 const struct pse_controller_ops *ops;
788 int id, mW, ret;
789 s64 tmp_64;
790
791 ops = pcdev->ops;
792 if (!ops->pi_set_pw_limit || !ops->pi_get_voltage)
793 return -EOPNOTSUPP;
794
795 if (max_uA > MAX_PI_CURRENT)Do we need this? Shouldn't it be checked in regulator_check_current_limit() instead? max_uA is an int. Do we need to check for negatives?
796 return -ERANGE;
797
798 id = rdev_get_id(rdev);
799 mutex_lock(&pcdev->lock);
800 ret = _pse_pi_get_voltage(rdev);
801 if (!ret) {
802 dev_err(pcdev->dev, "Voltage null\n");
803 ret = -ERANGE;
804 goto out;
805 }
806 if (ret < 0)
807 goto out;
808
809 tmp_64 = ret;
--> 810 tmp_64 *= max_uA;
811 /* mW = uA * uV / 1000000000 */
812 mW = DIV_ROUND_CLOSEST_ULL(tmp_64, 1000000000);
813 ret = ops->pi_set_pw_limit(pcdev, id, mW);
814 out:
815 mutex_unlock(&pcdev->lock);
816
817 return ret;
818 }regards,
dan carpenter
Quoted 24 lines · On Tue, 23 Sep 2025 14:21:03 +0300 Dan Carpenter <[email protected]>…
Hello Kory Maincent,
Commit
675d0e3cacc3("net: pse-pd: Avoid settingmax_uAin regulator constraints") from Jan 10, 2025 (linux-next), leads to the following Smatch static checker warning:drivers/net/pse-pd/pse_core.c:810 pse_pi_set_current_limit() warn: AAA no lower bound on 'max_uA' rl='s32min-(-1),1-1920000'
drivers/net/pse-pd/pse_core.c
783 static int pse_pi_set_current_limit(structregulator_dev*rdev, intmin_uA, 784 intmax_uA)785 { 786 struct pse_controller_dev *pcdev = rdev_get_drvdata(rdev); 787 const struct pse_controller_ops *ops; 788 int id, mW, ret; 789 s64 tmp_64; 790 791 ops = pcdev->ops; 792 if (!ops->pi_set_pw_limit || !ops->pi_get_voltage) 793 return -EOPNOTSUPP; 794 795 if (max_uA > MAX_PI_CURRENT)
Quoted 2 lines
Do we need this? Shouldn't it be checked in
regulator_check_current_limit()instead?max_uAis an int. Do we need to check for negatives?
No we can't use max_uA in the regulator constraints as I wrote it in the commit message:
"Setting the max_uA constraint in the regulator API imposes a current limit during the regulator registration process. This behavior conflicts with preserving the maximum PI power budget configuration across reboots."
Maybe we need to add a negative check to remove this smatch warning.
Regards,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com