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.

Input: sparcspkr - use device managed memory for 'state'

Use devm_kzalloc() in bbc_bee_probe() and grover_beep_probe() to
automatically free 'state' when the device is removed. Drop the
kfree(state) calls from the probe error paths and the remove functions
accordingly.

Suggested-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20241021-input_automate_of_node_put-v3-1-cc73f636e1bc@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Javier Carrasco and committed by
Dmitry Torokhov
ddefcd77 6951ec3f

+14 -27
+14 -27
drivers/input/misc/sparcspkr.c
··· 183 183 struct sparcspkr_state *state; 184 184 struct bbc_beep_info *info; 185 185 struct device_node *dp; 186 - int err = -ENOMEM; 186 + int err; 187 187 188 - state = kzalloc(sizeof(*state), GFP_KERNEL); 188 + state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL); 189 189 if (!state) 190 - goto out_err; 190 + return -ENOMEM; 191 191 192 192 state->name = "Sparc BBC Speaker"; 193 193 state->event = bbc_spkr_event; 194 194 spin_lock_init(&state->lock); 195 195 196 196 dp = of_find_node_by_path("/"); 197 - err = -ENODEV; 198 197 if (!dp) 199 - goto out_free; 198 + return -ENODEV; 200 199 201 200 info = &state->u.bbc; 202 201 info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0); 203 202 of_node_put(dp); 204 203 if (!info->clock_freq) 205 - goto out_free; 204 + return -ENODEV; 206 205 207 206 info->regs = of_ioremap(&op->resource[0], 0, 6, "bbc beep"); 208 207 if (!info->regs) 209 - goto out_free; 208 + return -ENODEV; 210 209 211 210 platform_set_drvdata(op, state); 212 211 213 212 err = sparcspkr_probe(&op->dev); 214 - if (err) 215 - goto out_clear_drvdata; 213 + if (err) { 214 + of_iounmap(&op->resource[0], info->regs, 6); 215 + return err; 216 + } 216 217 217 218 return 0; 218 - 219 - out_clear_drvdata: 220 - of_iounmap(&op->resource[0], info->regs, 6); 221 - 222 - out_free: 223 - kfree(state); 224 - out_err: 225 - return err; 226 219 } 227 220 228 221 static void bbc_remove(struct platform_device *op) ··· 230 237 input_unregister_device(input_dev); 231 238 232 239 of_iounmap(&op->resource[0], info->regs, 6); 233 - 234 - kfree(state); 235 240 } 236 241 237 242 static const struct of_device_id bbc_beep_match[] = { ··· 257 266 struct grover_beep_info *info; 258 267 int err = -ENOMEM; 259 268 260 - state = kzalloc(sizeof(*state), GFP_KERNEL); 269 + state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL); 261 270 if (!state) 262 - goto out_err; 271 + return err; 263 272 264 273 state->name = "Sparc Grover Speaker"; 265 274 state->event = grover_spkr_event; ··· 268 277 info = &state->u.grover; 269 278 info->freq_regs = of_ioremap(&op->resource[2], 0, 2, "grover beep freq"); 270 279 if (!info->freq_regs) 271 - goto out_free; 280 + return err; 272 281 273 282 info->enable_reg = of_ioremap(&op->resource[3], 0, 1, "grover beep enable"); 274 283 if (!info->enable_reg) ··· 287 296 288 297 out_unmap_freq_regs: 289 298 of_iounmap(&op->resource[2], info->freq_regs, 2); 290 - out_free: 291 - kfree(state); 292 - out_err: 299 + 293 300 return err; 294 301 } 295 302 ··· 304 315 305 316 of_iounmap(&op->resource[3], info->enable_reg, 1); 306 317 of_iounmap(&op->resource[2], info->freq_regs, 2); 307 - 308 - kfree(state); 309 318 } 310 319 311 320 static const struct of_device_id grover_beep_match[] = {