Commit b4877d2b authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Linus Torvalds

rtc-ep93xx.c: cleanup probe/remove routines

Fix issue with rtc device not getting unregistered in probe error path.

Use the devres managed resource functions in the probe routine to cleanup
the error path.

Use sysfs_{create/remove}_group to add/remove the sysfs files.

Reduces the text size by 132 bytes, increases data by 12 bytes:
    text	   data	    bss	    dec	    hex	filename
-    937	    124	      0	   1061	    425	rtc-ep93xx.o
+    805	    136	      0	    941	    3ad	rtc-ep93xx.o
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Cc: Paul Gortmaker <p_gortmaker@yahoo.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 49908e73
...@@ -115,6 +115,15 @@ static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev, ...@@ -115,6 +115,15 @@ static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
} }
static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
static struct attribute *ep93xx_rtc_attrs[] = {
&dev_attr_comp_preload.attr,
&dev_attr_comp_delete.attr,
NULL
};
static const struct attribute_group ep93xx_rtc_sysfs_files = {
.attrs = ep93xx_rtc_attrs,
};
static int __init ep93xx_rtc_probe(struct platform_device *pdev) static int __init ep93xx_rtc_probe(struct platform_device *pdev)
{ {
...@@ -123,27 +132,22 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev) ...@@ -123,27 +132,22 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
struct rtc_device *rtc; struct rtc_device *rtc;
int err; int err;
ep93xx_rtc = kzalloc(sizeof(struct ep93xx_rtc), GFP_KERNEL); ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL);
if (ep93xx_rtc == NULL) if (!ep93xx_rtc)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) { if (!res)
err = -ENXIO; return -ENXIO;
goto fail_free;
}
res = request_mem_region(res->start, resource_size(res), pdev->name); if (!devm_request_mem_region(&pdev->dev, res->start,
if (res == NULL) { resource_size(res), pdev->name))
err = -EBUSY; return -EBUSY;
goto fail_free;
}
ep93xx_rtc->mmio_base = ioremap(res->start, resource_size(res)); ep93xx_rtc->mmio_base = devm_ioremap(&pdev->dev, res->start,
if (ep93xx_rtc->mmio_base == NULL) { resource_size(res));
err = -ENXIO; if (!ep93xx_rtc->mmio_base)
goto fail; return -ENXIO;
}
pdev->dev.platform_data = ep93xx_rtc; pdev->dev.platform_data = ep93xx_rtc;
...@@ -151,53 +155,34 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev) ...@@ -151,53 +155,34 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
&pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) { if (IS_ERR(rtc)) {
err = PTR_ERR(rtc); err = PTR_ERR(rtc);
goto fail; goto exit;
} }
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
err = device_create_file(&pdev->dev, &dev_attr_comp_preload); err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
if (err) if (err)
goto fail; goto fail;
err = device_create_file(&pdev->dev, &dev_attr_comp_delete);
if (err) {
device_remove_file(&pdev->dev, &dev_attr_comp_preload);
goto fail;
}
return 0; return 0;
fail: fail:
if (ep93xx_rtc->mmio_base) { platform_set_drvdata(pdev, NULL);
iounmap(ep93xx_rtc->mmio_base); rtc_device_unregister(rtc);
pdev->dev.platform_data = NULL; exit:
} pdev->dev.platform_data = NULL;
release_mem_region(res->start, resource_size(res));
fail_free:
kfree(ep93xx_rtc);
return err; return err;
} }
static int __exit ep93xx_rtc_remove(struct platform_device *pdev) static int __exit ep93xx_rtc_remove(struct platform_device *pdev)
{ {
struct rtc_device *rtc = platform_get_drvdata(pdev); struct rtc_device *rtc = platform_get_drvdata(pdev);
struct ep93xx_rtc *ep93xx_rtc = pdev->dev.platform_data;
struct resource *res;
/* cleanup sysfs */
device_remove_file(&pdev->dev, &dev_attr_comp_delete);
device_remove_file(&pdev->dev, &dev_attr_comp_preload);
sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
platform_set_drvdata(pdev, NULL);
rtc_device_unregister(rtc); rtc_device_unregister(rtc);
iounmap(ep93xx_rtc->mmio_base);
pdev->dev.platform_data = NULL; pdev->dev.platform_data = NULL;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
platform_set_drvdata(pdev, NULL);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment