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

regulator: mc13xxx: Add warning of incorrect names of regulators

This patch adds a warning about incorrect regulators instead of
printing the names of non-information message about the wrong amount.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Mark Brown <broonie@sirena.org.uk>

authored by

Alexander Shiyan and committed by
Mark Brown
eb0d8e7a 60d509fa

+17 -43
+3 -36
drivers/regulator/mc13892-regulator.c
··· 535 535 struct mc13xxx_regulator_init_data *mc13xxx_data; 536 536 struct regulator_config config = { }; 537 537 int i, ret; 538 - int num_regulators = 0, num_parsed; 538 + int num_regulators = 0; 539 539 u32 val; 540 540 541 541 num_regulators = mc13xxx_get_num_regulators_dt(pdev); ··· 544 544 num_regulators = pdata->num_regulators; 545 545 if (num_regulators <= 0) 546 546 return -EINVAL; 547 - 548 - num_parsed = num_regulators; 549 547 550 548 priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + 551 549 num_regulators * sizeof(priv->regulators[0]), ··· 587 589 = mc13892_vcam_get_mode; 588 590 589 591 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators, 590 - ARRAY_SIZE(mc13892_regulators), 591 - &num_parsed); 592 + ARRAY_SIZE(mc13892_regulators)); 592 593 593 - /* 594 - * Perform a little sanity check on the regulator tree - if we found 595 - * a number of regulators from mc13xxx_get_num_regulators_dt and 596 - * then parsed a smaller number in mc13xxx_parse_regulators_dt then 597 - * there is a regulator defined in the regulators node which has 598 - * not matched any usable regulator in the driver. In this case, 599 - * there is one missing and what will happen is the first regulator 600 - * will get registered again. 601 - * 602 - * Fix this by basically making our number of registerable regulators 603 - * equal to the number of regulators we parsed. We are allocating 604 - * too much memory for priv, but this is unavoidable at this point. 605 - * 606 - * As an example of how this can happen, try making a typo in your 607 - * regulators node (vviohi {} instead of viohi {}) so that the name 608 - * does not match.. 609 - * 610 - * The check will basically pass for platform data (non-DT) because 611 - * mc13xxx_parse_regulators_dt for !CONFIG_OF will not touch num_parsed. 612 - * 613 - */ 614 - if (num_parsed != num_regulators) { 615 - dev_warn(&pdev->dev, 616 - "parsed %d != regulators %d - check your device tree!\n", 617 - num_parsed, num_regulators); 618 - 619 - num_regulators = num_parsed; 620 - priv->num_regulators = num_regulators; 621 - } 622 - 623 - for (i = 0; i < num_regulators; i++) { 594 + for (i = 0; i < priv->num_regulators; i++) { 624 595 struct regulator_init_data *init_data; 625 596 struct regulator_desc *desc; 626 597 struct device_node *node = NULL;
+12 -5
drivers/regulator/mc13xxx-regulator-core.c
··· 180 180 181 181 struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( 182 182 struct platform_device *pdev, struct mc13xxx_regulator *regulators, 183 - int num_regulators, int *num_parsed) 183 + int num_regulators) 184 184 { 185 185 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); 186 186 struct mc13xxx_regulator_init_data *data, *p; 187 187 struct device_node *parent, *child; 188 188 int i, parsed = 0; 189 - 190 - *num_parsed = 0; 191 189 192 190 of_node_get(pdev->dev.parent->of_node); 193 191 parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators"); ··· 202 204 p = data; 203 205 204 206 for_each_child_of_node(parent, child) { 207 + int found = 0; 208 + 205 209 for (i = 0; i < num_regulators; i++) { 210 + if (!regulators[i].desc.name) 211 + continue; 206 212 if (!of_node_cmp(child->name, 207 213 regulators[i].desc.name)) { 208 - 209 214 p->id = i; 210 215 p->init_data = of_get_regulator_init_data( 211 216 &pdev->dev, child); ··· 216 215 p++; 217 216 218 217 parsed++; 218 + found = 1; 219 219 break; 220 220 } 221 221 } 222 + 223 + if (!found) 224 + dev_warn(&pdev->dev, 225 + "Unknown regulator: %s\n", child->name); 222 226 } 223 227 of_node_put(parent); 224 228 225 - *num_parsed = parsed; 229 + priv->num_regulators = parsed; 230 + 226 231 return data; 227 232 } 228 233 EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt);
+2 -2
drivers/regulator/mc13xxx.h
··· 39 39 extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); 40 40 extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( 41 41 struct platform_device *pdev, struct mc13xxx_regulator *regulators, 42 - int num_regulators, int *num_parsed); 42 + int num_regulators); 43 43 #else 44 44 static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) 45 45 { ··· 48 48 49 49 static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( 50 50 struct platform_device *pdev, struct mc13xxx_regulator *regulators, 51 - int num_regulators, int *num_parsed) 51 + int num_regulators) 52 52 { 53 53 return NULL; 54 54 }