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

regulator: act8865: Fix missing of_node_put() in act8865_pdata_from_dt()

This node pointer is returned by of_get_child_by_name() with
refcount incremented in this function. of_node_put() is missing
when exitting this function while invalid device type. Fix it
by move of_get_child_by_name() code after device type check.

Found by Coccinelle.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Wei Yongjun and committed by
Mark Brown
842a8824 1a695a90

+6 -6
+6 -6
drivers/regulator/act8865-regulator.c
··· 395 395 struct act8865_regulator_data *regulator; 396 396 struct of_regulator_match *matches; 397 397 398 - np = of_get_child_by_name(dev->of_node, "regulators"); 399 - if (!np) { 400 - dev_err(dev, "missing 'regulators' subnode in DT\n"); 401 - return -EINVAL; 402 - } 403 - 404 398 switch (type) { 405 399 case ACT8600: 406 400 matches = act8600_matches; ··· 410 416 break; 411 417 default: 412 418 dev_err(dev, "invalid device id %lu\n", type); 419 + return -EINVAL; 420 + } 421 + 422 + np = of_get_child_by_name(dev->of_node, "regulators"); 423 + if (!np) { 424 + dev_err(dev, "missing 'regulators' subnode in DT\n"); 413 425 return -EINVAL; 414 426 } 415 427