Merge tag 'hwmon-for-v5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck...
[sfrench/cifs-2.6.git] / drivers / regulator / da9062-regulator.c
index d06e9600fa182a5ee8d2355b392eb14813c3de7d..b064d8a19d4ce5b7e25c2c7dbe1ab4a9b560ed50 100644 (file)
@@ -126,7 +126,7 @@ static int da9062_set_current_limit(struct regulator_dev *rdev,
        const struct da9062_regulator_info *rinfo = regl->info;
        int n, tval;
 
-       for (n = 0; n < rinfo->n_current_limits; n++) {
+       for (n = rinfo->n_current_limits - 1; n >= 0; n--) {
                tval = rinfo->current_limits[n];
                if (tval >= min_ua && tval <= max_ua)
                        return regmap_field_write(regl->ilimit, n);
@@ -992,7 +992,6 @@ static int da9062_regulator_probe(struct platform_device *pdev)
        struct regulator_config config = { };
        const struct da9062_regulator_info *rinfo;
        int irq, n, ret;
-       size_t size;
        int max_regulators;
 
        switch (chip->chip_type) {
@@ -1010,9 +1009,8 @@ static int da9062_regulator_probe(struct platform_device *pdev)
        }
 
        /* Allocate memory required by usable regulators */
-       size = sizeof(struct da9062_regulators) +
-               max_regulators * sizeof(struct da9062_regulator);
-       regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
+       regulators = devm_kzalloc(&pdev->dev, struct_size(regulators, regulator,
+                                 max_regulators), GFP_KERNEL);
        if (!regulators)
                return -ENOMEM;