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

iio: frequency: admfm2000: Use device_for_each_child_node_scoped() to simplify error paths.

This loop definition automatically release the fwnode_handle on early exit
simplifying error handling paths.

Cc: Kim Seer Paller <kimseer.paller@analog.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20240330190849.1321065-7-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

+6 -18
+6 -18
drivers/iio/frequency/admfm2000.c
··· 160 160 { 161 161 struct platform_device *pdev = to_platform_device(indio_dev->dev.parent); 162 162 struct device *dev = &pdev->dev; 163 - struct fwnode_handle *child; 164 163 struct gpio_desc **dsa; 165 164 struct gpio_desc **sw; 166 165 int ret, i; 167 166 bool mode; 168 167 u32 reg; 169 168 170 - device_for_each_child_node(dev, child) { 169 + device_for_each_child_node_scoped(dev, child) { 171 170 ret = fwnode_property_read_u32(child, "reg", &reg); 172 - if (ret) { 173 - fwnode_handle_put(child); 171 + if (ret) 174 172 return dev_err_probe(dev, ret, 175 173 "Failed to get reg property\n"); 176 - } 177 174 178 - if (reg >= indio_dev->num_channels) { 179 - fwnode_handle_put(child); 175 + if (reg >= indio_dev->num_channels) 180 176 return dev_err_probe(dev, -EINVAL, "reg bigger than: %d\n", 181 177 indio_dev->num_channels); 182 - } 183 178 184 179 if (fwnode_property_present(child, "adi,mixer-mode")) 185 180 mode = ADMFM2000_MIXER_MODE; ··· 191 196 dsa = st->dsa2_gpios; 192 197 break; 193 198 default: 194 - fwnode_handle_put(child); 195 199 return -EINVAL; 196 200 } 197 201 198 202 for (i = 0; i < ADMFM2000_MODE_GPIOS; i++) { 199 203 sw[i] = devm_fwnode_gpiod_get_index(dev, child, "switch", 200 204 i, GPIOD_OUT_LOW, NULL); 201 - if (IS_ERR(sw[i])) { 202 - fwnode_handle_put(child); 205 + if (IS_ERR(sw[i])) 203 206 return dev_err_probe(dev, PTR_ERR(sw[i]), 204 207 "Failed to get gpios\n"); 205 - } 206 208 } 207 209 208 210 for (i = 0; i < ADMFM2000_DSA_GPIOS; i++) { 209 211 dsa[i] = devm_fwnode_gpiod_get_index(dev, child, 210 212 "attenuation", i, 211 213 GPIOD_OUT_LOW, NULL); 212 - if (IS_ERR(dsa[i])) { 213 - fwnode_handle_put(child); 214 + if (IS_ERR(dsa[i])) 214 215 return dev_err_probe(dev, PTR_ERR(dsa[i]), 215 216 "Failed to get gpios\n"); 216 - } 217 217 } 218 218 219 219 ret = admfm2000_mode(indio_dev, reg, mode); 220 - if (ret) { 221 - fwnode_handle_put(child); 220 + if (ret) 222 221 return ret; 223 - } 224 222 } 225 223 226 224 return 0;