From eea2172e6915a92cab1d3a79a4961e14a3c388ff Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Fri, 7 Dec 2012 00:15:23 +0100 Subject: 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 Acked-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/masters/ds1wm.c | 52 ++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 34 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c index 7c294f4dc0ed..96cab6ac2b4e 100644 --- a/drivers/w1/masters/ds1wm.c +++ b/drivers/w1/masters/ds1wm.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -459,43 +460,34 @@ static int ds1wm_probe(struct platform_device *pdev) if (!pdev) return -ENODEV; - ds1wm_data = kzalloc(sizeof(*ds1wm_data), GFP_KERNEL); + ds1wm_data = devm_kzalloc(&pdev->dev, sizeof(*ds1wm_data), GFP_KERNEL); if (!ds1wm_data) return -ENOMEM; platform_set_drvdata(pdev, ds1wm_data); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - ret = -ENXIO; - goto err0; - } - ds1wm_data->map = ioremap(res->start, resource_size(res)); - if (!ds1wm_data->map) { - ret = -ENOMEM; - goto err0; - } + if (!res) + return -ENXIO; + ds1wm_data->map = devm_ioremap(&pdev->dev, res->start, + resource_size(res)); + if (!ds1wm_data->map) + return -ENOMEM; /* calculate bus shift from mem resource */ ds1wm_data->bus_shift = resource_size(res) >> 3; ds1wm_data->pdev = pdev; ds1wm_data->cell = mfd_get_cell(pdev); - if (!ds1wm_data->cell) { - ret = -ENODEV; - goto err1; - } + if (!ds1wm_data->cell) + return -ENODEV; plat = pdev->dev.platform_data; - if (!plat) { - ret = -ENODEV; - goto err1; - } + if (!plat) + return -ENODEV; res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!res) { - ret = -ENXIO; - goto err1; - } + if (!res) + return -ENXIO; ds1wm_data->irq = res->start; ds1wm_data->int_en_reg_none = (plat->active_high ? DS1WM_INTEN_IAS : 0); ds1wm_data->reset_recover_delay = plat->reset_recover_delay; @@ -505,10 +497,10 @@ static int ds1wm_probe(struct platform_device *pdev) if (res->flags & IORESOURCE_IRQ_LOWEDGE) irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_FALLING); - ret = request_irq(ds1wm_data->irq, ds1wm_isr, + ret = devm_request_irq(&pdev->dev, ds1wm_data->irq, ds1wm_isr, IRQF_DISABLED | IRQF_SHARED, "ds1wm", ds1wm_data); if (ret) - goto err1; + return ret; ds1wm_up(ds1wm_data); @@ -516,17 +508,12 @@ static int ds1wm_probe(struct platform_device *pdev) ret = w1_add_master_device(&ds1wm_master); if (ret) - goto err2; + goto err; return 0; -err2: +err: ds1wm_down(ds1wm_data); - free_irq(ds1wm_data->irq, ds1wm_data); -err1: - iounmap(ds1wm_data->map); -err0: - kfree(ds1wm_data); return ret; } @@ -560,9 +547,6 @@ static int ds1wm_remove(struct platform_device *pdev) w1_remove_master_device(&ds1wm_master); ds1wm_down(ds1wm_data); - free_irq(ds1wm_data->irq, ds1wm_data); - iounmap(ds1wm_data->map); - kfree(ds1wm_data); return 0; } -- cgit v1.2.3