Re: [PATCH V12 7/9] regulator: Add a regulator driver for the PM8008 PMIC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Satya,

url:    https://github.com/intel-lab-lkp/linux/commits/Satya-Priya/Add-Qualcomm-Technologies-Inc-PM8008-regulator-driver/20220511-212136
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next
config: nios2-randconfig-m031-20220512 (https://download.01.org/0day-ci/archive/20220513/202205130908.O31s3mhc-lkp@xxxxxxxxx/config)
compiler: nios2-linux-gcc (GCC) 11.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
drivers/regulator/qcom-pm8008-regulator.c:174 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)

Old smatch warnings:
drivers/regulator/qcom-pm8008-regulator.c:175 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)
drivers/regulator/qcom-pm8008-regulator.c:176 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)
drivers/regulator/qcom-pm8008-regulator.c:178 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)
drivers/regulator/qcom-pm8008-regulator.c:180 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)
drivers/regulator/qcom-pm8008-regulator.c:180 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)
drivers/regulator/qcom-pm8008-regulator.c:182 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)
drivers/regulator/qcom-pm8008-regulator.c:186 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)
drivers/regulator/qcom-pm8008-regulator.c:196 pm8008_regulator_probe() error: buffer overflow 'reg_data' 7 <= 7 (assuming for loop doesn't break)

vim +174 drivers/regulator/qcom-pm8008-regulator.c

3337142527c77d Satya Priya 2022-05-11  122  static int pm8008_regulator_probe(struct platform_device *pdev)
3337142527c77d Satya Priya 2022-05-11  123  {
3337142527c77d Satya Priya 2022-05-11  124  	int rc, i;
3337142527c77d Satya Priya 2022-05-11  125  	u32 base;
3337142527c77d Satya Priya 2022-05-11  126  	unsigned int reg;
3337142527c77d Satya Priya 2022-05-11  127  	const char *name;
3337142527c77d Satya Priya 2022-05-11  128  	struct device *dev = &pdev->dev;
3337142527c77d Satya Priya 2022-05-11  129  	struct regulator_config reg_config = {};
3337142527c77d Satya Priya 2022-05-11  130  	struct regulator_dev    *rdev;
3337142527c77d Satya Priya 2022-05-11  131  	const struct pm8008_data *chip = dev_get_drvdata(pdev->dev.parent);
3337142527c77d Satya Priya 2022-05-11  132  	struct pm8008_regulator *pm8008_reg;
3337142527c77d Satya Priya 2022-05-11  133  
3337142527c77d Satya Priya 2022-05-11  134  	pm8008_reg = devm_kzalloc(dev, sizeof(*pm8008_reg), GFP_KERNEL);
3337142527c77d Satya Priya 2022-05-11  135  	if (!pm8008_reg)
3337142527c77d Satya Priya 2022-05-11  136  		return -ENOMEM;
3337142527c77d Satya Priya 2022-05-11  137  
3337142527c77d Satya Priya 2022-05-11  138  	pm8008_reg->regmap = pm8008_get_regmap(chip);
3337142527c77d Satya Priya 2022-05-11  139  	if (!pm8008_reg->regmap) {
3337142527c77d Satya Priya 2022-05-11  140  		dev_err(dev, "parent regmap is missing\n");
3337142527c77d Satya Priya 2022-05-11  141  		return -EINVAL;
3337142527c77d Satya Priya 2022-05-11  142  	}
3337142527c77d Satya Priya 2022-05-11  143  
3337142527c77d Satya Priya 2022-05-11  144  	pm8008_reg->dev = dev;
3337142527c77d Satya Priya 2022-05-11  145  
3337142527c77d Satya Priya 2022-05-11  146  	rc = of_property_read_string(dev->of_node, "regulator-name", &name);
3337142527c77d Satya Priya 2022-05-11  147  	if (rc)
3337142527c77d Satya Priya 2022-05-11  148  		return rc;
3337142527c77d Satya Priya 2022-05-11  149  
3337142527c77d Satya Priya 2022-05-11  150  	/* get the required regulator data */
3337142527c77d Satya Priya 2022-05-11  151  	for (i = 0; i < ARRAY_SIZE(reg_data); i++)
3337142527c77d Satya Priya 2022-05-11  152  		if (strstr(name, reg_data[i].name))
3337142527c77d Satya Priya 2022-05-11  153  			break;

This code assumes that we will find a match but it would be more robust
to add a check.

	if (i == ARRAY_SIZE(reg_data))
		return -ENODEV;

3337142527c77d Satya Priya 2022-05-11  154  
3337142527c77d Satya Priya 2022-05-11  155  	rc = of_property_read_u32_index(dev->of_node, "reg", 1, &base);
3337142527c77d Satya Priya 2022-05-11  156  	if (rc < 0) {
3337142527c77d Satya Priya 2022-05-11  157  		dev_err(dev, "%s: failed to get regulator base rc=%d\n", name, rc);
3337142527c77d Satya Priya 2022-05-11  158  		return rc;
3337142527c77d Satya Priya 2022-05-11  159  	}
3337142527c77d Satya Priya 2022-05-11  160  	pm8008_reg->base = base;
3337142527c77d Satya Priya 2022-05-11  161  
3337142527c77d Satya Priya 2022-05-11  162  	/* get slew rate */
3337142527c77d Satya Priya 2022-05-11  163  	rc = regmap_bulk_read(pm8008_reg->regmap,
3337142527c77d Satya Priya 2022-05-11  164  			LDO_STEPPER_CTL_REG(pm8008_reg->base), &reg, 1);
3337142527c77d Satya Priya 2022-05-11  165  	if (rc < 0) {
3337142527c77d Satya Priya 2022-05-11  166  		dev_err(dev, "failed to read step rate configuration rc=%d\n", rc);
3337142527c77d Satya Priya 2022-05-11  167  		return rc;
3337142527c77d Satya Priya 2022-05-11  168  	}
3337142527c77d Satya Priya 2022-05-11  169  	reg &= STEP_RATE_MASK;
3337142527c77d Satya Priya 2022-05-11  170  	pm8008_reg->step_rate = DEFAULT_VOLTAGE_STEPPER_RATE >> reg;
3337142527c77d Satya Priya 2022-05-11  171  
3337142527c77d Satya Priya 2022-05-11  172  	pm8008_reg->rdesc.type = REGULATOR_VOLTAGE;
3337142527c77d Satya Priya 2022-05-11  173  	pm8008_reg->rdesc.ops = &pm8008_regulator_ops;
3337142527c77d Satya Priya 2022-05-11 @174  	pm8008_reg->rdesc.name = reg_data[i].name;
3337142527c77d Satya Priya 2022-05-11  175  	pm8008_reg->rdesc.supply_name = reg_data[i].supply_name;
3337142527c77d Satya Priya 2022-05-11  176  	pm8008_reg->rdesc.of_match = reg_data[i].name;
3337142527c77d Satya Priya 2022-05-11  177  	pm8008_reg->rdesc.uV_step = VSET_STEP_UV;
3337142527c77d Satya Priya 2022-05-11  178  	pm8008_reg->rdesc.min_uV = reg_data[i].min_uv;
3337142527c77d Satya Priya 2022-05-11  179  	pm8008_reg->rdesc.n_voltages
3337142527c77d Satya Priya 2022-05-11  180  		= ((reg_data[i].max_uv - reg_data[i].min_uv)
3337142527c77d Satya Priya 2022-05-11  181  			/ pm8008_reg->rdesc.uV_step) + 1;
3337142527c77d Satya Priya 2022-05-11  182  	pm8008_reg->rdesc.linear_ranges = reg_data[i].voltage_range;
3337142527c77d Satya Priya 2022-05-11  183  	pm8008_reg->rdesc.n_linear_ranges = 1;
3337142527c77d Satya Priya 2022-05-11  184  	pm8008_reg->rdesc.enable_reg = LDO_ENABLE_REG(pm8008_reg->base);
3337142527c77d Satya Priya 2022-05-11  185  	pm8008_reg->rdesc.enable_mask = ENABLE_BIT;
3337142527c77d Satya Priya 2022-05-11  186  	pm8008_reg->rdesc.min_dropout_uV = reg_data[i].min_dropout_uv;
3337142527c77d Satya Priya 2022-05-11  187  	pm8008_reg->voltage_selector = -ENOTRECOVERABLE;
3337142527c77d Satya Priya 2022-05-11  188  
3337142527c77d Satya Priya 2022-05-11  189  	reg_config.dev = dev->parent;
3337142527c77d Satya Priya 2022-05-11  190  	reg_config.driver_data = pm8008_reg;
3337142527c77d Satya Priya 2022-05-11  191  	reg_config.regmap = pm8008_reg->regmap;
3337142527c77d Satya Priya 2022-05-11  192  
3337142527c77d Satya Priya 2022-05-11  193  	rdev = devm_regulator_register(dev, &pm8008_reg->rdesc, &reg_config);
3337142527c77d Satya Priya 2022-05-11  194  	if (IS_ERR(rdev)) {
3337142527c77d Satya Priya 2022-05-11  195  		rc = PTR_ERR(rdev);
3337142527c77d Satya Priya 2022-05-11  196  		dev_err(dev, "%s: failed to register regulator rc=%d\n",
3337142527c77d Satya Priya 2022-05-11  197  				reg_data[i].name, rc);
3337142527c77d Satya Priya 2022-05-11  198  		return rc;
3337142527c77d Satya Priya 2022-05-11  199  	}
3337142527c77d Satya Priya 2022-05-11  200  
3337142527c77d Satya Priya 2022-05-11  201  	return 0;
3337142527c77d Satya Priya 2022-05-11  202  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux