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

usb: dwc3: Use of_property_read_variable_u32_array() to read "power"

There's no need to get the length of an DT array property before
parsing the array. of_property_read_variable_u32_array() takes a minimum
and maximum length and returns the actual length (or error code).

This is part of a larger effort to remove callers of of_find_property()
and similar functions. of_find_property() leaks the DT struct property
and data pointers which is a problem for dynamically allocated nodes
which may be freed.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20240731201407.1838385-5-robh@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rob Herring (Arm) and committed by
Greg Kroah-Hartman
f3586024 89b75391

+4 -15
+4 -15
drivers/usb/dwc3/dwc3-octeon.c
··· 419 419 int ref_clk_sel, ref_clk_fsel, mpll_mul; 420 420 int power_active_low, power_gpio; 421 421 int err, len; 422 - u32 clock_rate; 422 + u32 clock_rate, gpio_pwr[3]; 423 423 424 424 if (of_property_read_u32(node, "refclk-frequency", &clock_rate)) { 425 425 dev_err(dev, "No UCTL \"refclk-frequency\"\n"); ··· 476 476 477 477 power_gpio = DWC3_GPIO_POWER_NONE; 478 478 power_active_low = 0; 479 - if (of_find_property(node, "power", &len)) { 480 - u32 gpio_pwr[3]; 481 - 482 - switch (len) { 483 - case 8: 484 - of_property_read_u32_array(node, "power", gpio_pwr, 2); 485 - break; 486 - case 12: 487 - of_property_read_u32_array(node, "power", gpio_pwr, 3); 479 + len = of_property_read_variable_u32_array(node, "power", gpio_pwr, 2, 3); 480 + if (len > 0) { 481 + if (len == 3) 488 482 power_active_low = gpio_pwr[2] & 0x01; 489 - break; 490 - default: 491 - dev_err(dev, "invalid power configuration\n"); 492 - return -EINVAL; 493 - } 494 483 power_gpio = gpio_pwr[1]; 495 484 } 496 485