aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ep93xx.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2010-03-05 16:44:20 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-06 14:26:46 -0500
commitb4877d2b3678f4455f2b8b0211868ac57c3b1ff6 (patch)
tree78d93a4edc48bb76e6f0a385cf5bb2d806405229 /drivers/rtc/rtc-ep93xx.c
parent49908e739e23e2672d3efb9b1a35f877f8e86342 (diff)
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: H Hartley Sweeten <hsweeten@visionengravers.com> Acked-by: Alessandro Zummo <a.zummo@towertech.it> Cc: Paul Gortmaker <p_gortmaker@yahoo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/rtc-ep93xx.c')
-rw-r--r--drivers/rtc/rtc-ep93xx.c71
1 files changed, 28 insertions, 43 deletions
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 9da02d108b73..91bde976bc0f 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -115,6 +115,15 @@ static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
115} 115}
116static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); 116static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
117 117
118static struct attribute *ep93xx_rtc_attrs[] = {
119 &dev_attr_comp_preload.attr,
120 &dev_attr_comp_delete.attr,
121 NULL
122};
123
124static const struct attribute_group ep93xx_rtc_sysfs_files = {
125 .attrs = ep93xx_rtc_attrs,
126};
118 127
119static int __init ep93xx_rtc_probe(struct platform_device *pdev) 128static int __init ep93xx_rtc_probe(struct platform_device *pdev)
120{ 129{
@@ -123,27 +132,22 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
123 struct rtc_device *rtc; 132 struct rtc_device *rtc;
124 int err; 133 int err;
125 134
126 ep93xx_rtc = kzalloc(sizeof(struct ep93xx_rtc), GFP_KERNEL); 135 ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL);
127 if (ep93xx_rtc == NULL) 136 if (!ep93xx_rtc)
128 return -ENOMEM; 137 return -ENOMEM;
129 138
130 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 139 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
131 if (res == NULL) { 140 if (!res)
132 err = -ENXIO; 141 return -ENXIO;
133 goto fail_free;
134 }
135 142
136 res = request_mem_region(res->start, resource_size(res), pdev->name); 143 if (!devm_request_mem_region(&pdev->dev, res->start,
137 if (res == NULL) { 144 resource_size(res), pdev->name))
138 err = -EBUSY; 145 return -EBUSY;
139 goto fail_free;
140 }
141 146
142 ep93xx_rtc->mmio_base = ioremap(res->start, resource_size(res)); 147 ep93xx_rtc->mmio_base = devm_ioremap(&pdev->dev, res->start,
143 if (ep93xx_rtc->mmio_base == NULL) { 148 resource_size(res));
144 err = -ENXIO; 149 if (!ep93xx_rtc->mmio_base)
145 goto fail; 150 return -ENXIO;
146 }
147 151
148 pdev->dev.platform_data = ep93xx_rtc; 152 pdev->dev.platform_data = ep93xx_rtc;
149 153
@@ -151,53 +155,34 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
151 &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); 155 &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE);
152 if (IS_ERR(rtc)) { 156 if (IS_ERR(rtc)) {
153 err = PTR_ERR(rtc); 157 err = PTR_ERR(rtc);
154 goto fail; 158 goto exit;
155 } 159 }
156 160
157 platform_set_drvdata(pdev, rtc); 161 platform_set_drvdata(pdev, rtc);
158 162
159 err = device_create_file(&pdev->dev, &dev_attr_comp_preload); 163 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
160 if (err) 164 if (err)
161 goto fail; 165 goto fail;
162 err = device_create_file(&pdev->dev, &dev_attr_comp_delete);
163 if (err) {
164 device_remove_file(&pdev->dev, &dev_attr_comp_preload);
165 goto fail;
166 }
167 166
168 return 0; 167 return 0;
169 168
170fail: 169fail:
171 if (ep93xx_rtc->mmio_base) { 170 platform_set_drvdata(pdev, NULL);
172 iounmap(ep93xx_rtc->mmio_base); 171 rtc_device_unregister(rtc);
173 pdev->dev.platform_data = NULL; 172exit:
174 } 173 pdev->dev.platform_data = NULL;
175 release_mem_region(res->start, resource_size(res));
176fail_free:
177 kfree(ep93xx_rtc);
178 return err; 174 return err;
179} 175}
180 176
181static int __exit ep93xx_rtc_remove(struct platform_device *pdev) 177static int __exit ep93xx_rtc_remove(struct platform_device *pdev)
182{ 178{
183 struct rtc_device *rtc = platform_get_drvdata(pdev); 179 struct rtc_device *rtc = platform_get_drvdata(pdev);
184 struct ep93xx_rtc *ep93xx_rtc = pdev->dev.platform_data;
185 struct resource *res;
186
187 /* cleanup sysfs */
188 device_remove_file(&pdev->dev, &dev_attr_comp_delete);
189 device_remove_file(&pdev->dev, &dev_attr_comp_preload);
190 180
181 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
182 platform_set_drvdata(pdev, NULL);
191 rtc_device_unregister(rtc); 183 rtc_device_unregister(rtc);
192
193 iounmap(ep93xx_rtc->mmio_base);
194 pdev->dev.platform_data = NULL; 184 pdev->dev.platform_data = NULL;
195 185
196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
197 release_mem_region(res->start, resource_size(res));
198
199 platform_set_drvdata(pdev, NULL);
200
201 return 0; 186 return 0;
202} 187}
203 188