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

drivers/misc: at25: convert to use devm_kzalloc

Use devm_kzalloc to make cleanup paths simpler

Signed-off-by: Nikolay Balandin <nbalandin@dev.rtsoft.ru>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Nikolay Balandin and committed by
Greg Kroah-Hartman
01fe7b43 f0ac2363

+8 -17
+8 -17
drivers/misc/eeprom/at25.c
··· 371 371 if (np) { 372 372 err = at25_np_to_chip(&spi->dev, np, &chip); 373 373 if (err) 374 - goto fail; 374 + return err; 375 375 } else { 376 376 dev_err(&spi->dev, "Error: no chip description\n"); 377 - err = -ENODEV; 378 - goto fail; 377 + return -ENODEV; 379 378 } 380 379 } else 381 380 chip = *(struct spi_eeprom *)spi->dev.platform_data; ··· 388 389 addrlen = 3; 389 390 else { 390 391 dev_dbg(&spi->dev, "unsupported address type\n"); 391 - err = -EINVAL; 392 - goto fail; 392 + return -EINVAL; 393 393 } 394 394 395 395 /* Ping the chip ... the status register is pretty portable, ··· 398 400 sr = spi_w8r8(spi, AT25_RDSR); 399 401 if (sr < 0 || sr & AT25_SR_nRDY) { 400 402 dev_dbg(&spi->dev, "rdsr --> %d (%02x)\n", sr, sr); 401 - err = -ENXIO; 402 - goto fail; 403 + return -ENXIO; 403 404 } 404 405 405 - if (!(at25 = kzalloc(sizeof *at25, GFP_KERNEL))) { 406 - err = -ENOMEM; 407 - goto fail; 408 - } 406 + at25 = devm_kzalloc(&spi->dev, sizeof(struct at25_data), GFP_KERNEL); 407 + if (!at25) 408 + return -ENOMEM; 409 409 410 410 mutex_init(&at25->lock); 411 411 at25->chip = chip; ··· 435 439 436 440 err = sysfs_create_bin_file(&spi->dev.kobj, &at25->bin); 437 441 if (err) 438 - goto fail; 442 + return err; 439 443 440 444 if (chip.setup) 441 445 chip.setup(&at25->mem, chip.context); ··· 449 453 (chip.flags & EE_READONLY) ? " (readonly)" : "", 450 454 at25->chip.page_size); 451 455 return 0; 452 - fail: 453 - dev_dbg(&spi->dev, "probe err %d\n", err); 454 - kfree(at25); 455 - return err; 456 456 } 457 457 458 458 static int at25_remove(struct spi_device *spi) ··· 457 465 458 466 at25 = spi_get_drvdata(spi); 459 467 sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin); 460 - kfree(at25); 461 468 return 0; 462 469 } 463 470