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

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: stm32: Use device_for_each_child_node_scoped()

Switching to the _scoped() version removes the need for manual
calling of fwnode_handle_put() in the paths where the code
exits the loop early. In this case that's all in error paths.

Note this would have made the bug fixed in the previous path much
less likely as it allows for direct returns.

Took advantage of dev_err_probe() to futher simplify things given no
longer a need for the goto err.

Cc: Olivier Moysan <olivier.moysan@foss.st.com>
Tested-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Acked-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20240330185305.1319844-5-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

+24 -38
+24 -38
drivers/iio/adc/stm32-adc.c
··· 2187 2187 struct iio_chan_spec *channels) 2188 2188 { 2189 2189 const struct stm32_adc_info *adc_info = adc->cfg->adc_info; 2190 - struct fwnode_handle *child; 2190 + struct device *dev = &indio_dev->dev; 2191 2191 const char *name; 2192 2192 int val, scan_index = 0, ret; 2193 2193 bool differential; 2194 2194 u32 vin[2]; 2195 2195 2196 - device_for_each_child_node(&indio_dev->dev, child) { 2196 + device_for_each_child_node_scoped(dev, child) { 2197 2197 ret = fwnode_property_read_u32(child, "reg", &val); 2198 - if (ret) { 2199 - dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); 2200 - goto err; 2201 - } 2198 + if (ret) 2199 + return dev_err_probe(dev, ret, 2200 + "Missing channel index\n"); 2202 2201 2203 2202 ret = fwnode_property_read_string(child, "label", &name); 2204 2203 /* label is optional */ 2205 2204 if (!ret) { 2206 - if (strlen(name) >= STM32_ADC_CH_SZ) { 2207 - dev_err(&indio_dev->dev, "Label %s exceeds %d characters\n", 2208 - name, STM32_ADC_CH_SZ); 2209 - ret = -EINVAL; 2210 - goto err; 2211 - } 2205 + if (strlen(name) >= STM32_ADC_CH_SZ) 2206 + return dev_err_probe(dev, -EINVAL, 2207 + "Label %s exceeds %d characters\n", 2208 + name, STM32_ADC_CH_SZ); 2209 + 2212 2210 strscpy(adc->chan_name[val], name, STM32_ADC_CH_SZ); 2213 2211 ret = stm32_adc_populate_int_ch(indio_dev, name, val); 2214 2212 if (ret == -ENOENT) 2215 2213 continue; 2216 2214 else if (ret) 2217 - goto err; 2215 + return ret; 2218 2216 } else if (ret != -EINVAL) { 2219 - dev_err(&indio_dev->dev, "Invalid label %d\n", ret); 2220 - goto err; 2217 + return dev_err_probe(dev, ret, "Invalid label\n"); 2221 2218 } 2222 2219 2223 - if (val >= adc_info->max_channels) { 2224 - dev_err(&indio_dev->dev, "Invalid channel %d\n", val); 2225 - ret = -EINVAL; 2226 - goto err; 2227 - } 2220 + if (val >= adc_info->max_channels) 2221 + return dev_err_probe(dev, -EINVAL, 2222 + "Invalid channel %d\n", val); 2228 2223 2229 2224 differential = false; 2230 2225 ret = fwnode_property_read_u32_array(child, "diff-channels", vin, 2); 2231 2226 /* diff-channels is optional */ 2232 2227 if (!ret) { 2233 2228 differential = true; 2234 - if (vin[0] != val || vin[1] >= adc_info->max_channels) { 2235 - dev_err(&indio_dev->dev, "Invalid channel in%d-in%d\n", 2236 - vin[0], vin[1]); 2237 - ret = -EINVAL; 2238 - goto err; 2239 - } 2229 + if (vin[0] != val || vin[1] >= adc_info->max_channels) 2230 + return dev_err_probe(dev, -EINVAL, 2231 + "Invalid channel in%d-in%d\n", 2232 + vin[0], vin[1]); 2240 2233 } else if (ret != -EINVAL) { 2241 - dev_err(&indio_dev->dev, "Invalid diff-channels property %d\n", ret); 2242 - goto err; 2234 + return dev_err_probe(dev, ret, 2235 + "Invalid diff-channels property\n"); 2243 2236 } 2244 2237 2245 2238 stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val, ··· 2241 2248 val = 0; 2242 2249 ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val); 2243 2250 /* st,min-sample-time-ns is optional */ 2244 - if (ret && ret != -EINVAL) { 2245 - dev_err(&indio_dev->dev, "Invalid st,min-sample-time-ns property %d\n", 2246 - ret); 2247 - goto err; 2248 - } 2251 + if (ret && ret != -EINVAL) 2252 + return dev_err_probe(dev, ret, 2253 + "Invalid st,min-sample-time-ns property\n"); 2249 2254 2250 2255 stm32_adc_smpr_init(adc, channels[scan_index].channel, val); 2251 2256 if (differential) ··· 2253 2262 } 2254 2263 2255 2264 return scan_index; 2256 - 2257 - err: 2258 - fwnode_handle_put(child); 2259 - 2260 - return ret; 2261 2265 } 2262 2266 2263 2267 static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)