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

drivers/w1/masters/ds1wm.c: use devm_ functions

The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Julia Lawall and committed by
Greg Kroah-Hartman
eea2172e feee8303

+18 -34
+18 -34
drivers/w1/masters/ds1wm.c
··· 13 13 14 14 #include <linux/module.h> 15 15 #include <linux/interrupt.h> 16 + #include <linux/io.h> 16 17 #include <linux/irq.h> 17 18 #include <linux/pm.h> 18 19 #include <linux/platform_device.h> ··· 460 459 if (!pdev) 461 460 return -ENODEV; 462 461 463 - ds1wm_data = kzalloc(sizeof(*ds1wm_data), GFP_KERNEL); 462 + ds1wm_data = devm_kzalloc(&pdev->dev, sizeof(*ds1wm_data), GFP_KERNEL); 464 463 if (!ds1wm_data) 465 464 return -ENOMEM; 466 465 467 466 platform_set_drvdata(pdev, ds1wm_data); 468 467 469 468 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 470 - if (!res) { 471 - ret = -ENXIO; 472 - goto err0; 473 - } 474 - ds1wm_data->map = ioremap(res->start, resource_size(res)); 475 - if (!ds1wm_data->map) { 476 - ret = -ENOMEM; 477 - goto err0; 478 - } 469 + if (!res) 470 + return -ENXIO; 471 + ds1wm_data->map = devm_ioremap(&pdev->dev, res->start, 472 + resource_size(res)); 473 + if (!ds1wm_data->map) 474 + return -ENOMEM; 479 475 480 476 /* calculate bus shift from mem resource */ 481 477 ds1wm_data->bus_shift = resource_size(res) >> 3; 482 478 483 479 ds1wm_data->pdev = pdev; 484 480 ds1wm_data->cell = mfd_get_cell(pdev); 485 - if (!ds1wm_data->cell) { 486 - ret = -ENODEV; 487 - goto err1; 488 - } 481 + if (!ds1wm_data->cell) 482 + return -ENODEV; 489 483 plat = pdev->dev.platform_data; 490 - if (!plat) { 491 - ret = -ENODEV; 492 - goto err1; 493 - } 484 + if (!plat) 485 + return -ENODEV; 494 486 495 487 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 496 - if (!res) { 497 - ret = -ENXIO; 498 - goto err1; 499 - } 488 + if (!res) 489 + return -ENXIO; 500 490 ds1wm_data->irq = res->start; 501 491 ds1wm_data->int_en_reg_none = (plat->active_high ? DS1WM_INTEN_IAS : 0); 502 492 ds1wm_data->reset_recover_delay = plat->reset_recover_delay; ··· 497 505 if (res->flags & IORESOURCE_IRQ_LOWEDGE) 498 506 irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_FALLING); 499 507 500 - ret = request_irq(ds1wm_data->irq, ds1wm_isr, 508 + ret = devm_request_irq(&pdev->dev, ds1wm_data->irq, ds1wm_isr, 501 509 IRQF_DISABLED | IRQF_SHARED, "ds1wm", ds1wm_data); 502 510 if (ret) 503 - goto err1; 511 + return ret; 504 512 505 513 ds1wm_up(ds1wm_data); 506 514 ··· 508 516 509 517 ret = w1_add_master_device(&ds1wm_master); 510 518 if (ret) 511 - goto err2; 519 + goto err; 512 520 513 521 return 0; 514 522 515 - err2: 523 + err: 516 524 ds1wm_down(ds1wm_data); 517 - free_irq(ds1wm_data->irq, ds1wm_data); 518 - err1: 519 - iounmap(ds1wm_data->map); 520 - err0: 521 - kfree(ds1wm_data); 522 525 523 526 return ret; 524 527 } ··· 547 560 548 561 w1_remove_master_device(&ds1wm_master); 549 562 ds1wm_down(ds1wm_data); 550 - free_irq(ds1wm_data->irq, ds1wm_data); 551 - iounmap(ds1wm_data->map); 552 - kfree(ds1wm_data); 553 563 554 564 return 0; 555 565 }