aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2013-07-24 13:38:04 -0400
committerJiri Kosina <jkosina@suse.cz>2013-07-31 04:12:28 -0400
commitabf832bfc349b54fd500f1e3b612f7f3cd9dfcc6 (patch)
tree4ece0e75cf3fd463be58376e3f900c1cfd60dd05
parent3366dd9fa887ebbda4872e9554f853eaeda764be (diff)
HID: trivial devm conversion for special hid drivers
It is safe to use devres allocation within the hid subsystem: - the devres release is called _after_ the call to .remove(), meaning that no freed pointers will exists while removing the device - if a .probe() fails, devres releases all the allocated ressources before going to the next driver: there will not be ghost ressources attached to a hid device if several drivers are probed. Given that, we can clean up a little some of the HID drivers. These ones are trivial: - there is only one kzalloc in the driver - the .remove() callback contains only one kfree on top of hid_hw_stop() - the error path in the probe is easy enough to be manually checked Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/hid-a4tech.c21
-rw-r--r--drivers/hid/hid-apple.c16
-rw-r--r--drivers/hid/hid-magicmouse.c17
-rw-r--r--drivers/hid/hid-sony.c9
-rw-r--r--drivers/hid/hid-zydacron.c19
5 files changed, 16 insertions, 66 deletions
diff --git a/drivers/hid/hid-a4tech.c b/drivers/hid/hid-a4tech.c
index 7c5507e94820..9428ea7cdf8a 100644
--- a/drivers/hid/hid-a4tech.c
+++ b/drivers/hid/hid-a4tech.c
@@ -90,11 +90,10 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
90 struct a4tech_sc *a4; 90 struct a4tech_sc *a4;
91 int ret; 91 int ret;
92 92
93 a4 = kzalloc(sizeof(*a4), GFP_KERNEL); 93 a4 = devm_kzalloc(&hdev->dev, sizeof(*a4), GFP_KERNEL);
94 if (a4 == NULL) { 94 if (a4 == NULL) {
95 hid_err(hdev, "can't alloc device descriptor\n"); 95 hid_err(hdev, "can't alloc device descriptor\n");
96 ret = -ENOMEM; 96 return -ENOMEM;
97 goto err_free;
98 } 97 }
99 98
100 a4->quirks = id->driver_data; 99 a4->quirks = id->driver_data;
@@ -104,27 +103,16 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
104 ret = hid_parse(hdev); 103 ret = hid_parse(hdev);
105 if (ret) { 104 if (ret) {
106 hid_err(hdev, "parse failed\n"); 105 hid_err(hdev, "parse failed\n");
107 goto err_free; 106 return ret;
108 } 107 }
109 108
110 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 109 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
111 if (ret) { 110 if (ret) {
112 hid_err(hdev, "hw start failed\n"); 111 hid_err(hdev, "hw start failed\n");
113 goto err_free; 112 return ret;
114 } 113 }
115 114
116 return 0; 115 return 0;
117err_free:
118 kfree(a4);
119 return ret;
120}
121
122static void a4_remove(struct hid_device *hdev)
123{
124 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
125
126 hid_hw_stop(hdev);
127 kfree(a4);
128} 116}
129 117
130static const struct hid_device_id a4_devices[] = { 118static const struct hid_device_id a4_devices[] = {
@@ -144,7 +132,6 @@ static struct hid_driver a4_driver = {
144 .input_mapped = a4_input_mapped, 132 .input_mapped = a4_input_mapped,
145 .event = a4_event, 133 .event = a4_event,
146 .probe = a4_probe, 134 .probe = a4_probe,
147 .remove = a4_remove,
148}; 135};
149module_hid_driver(a4_driver); 136module_hid_driver(a4_driver);
150 137
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index feae88b53fcd..bad40b9315b2 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -349,7 +349,7 @@ static int apple_probe(struct hid_device *hdev,
349 unsigned int connect_mask = HID_CONNECT_DEFAULT; 349 unsigned int connect_mask = HID_CONNECT_DEFAULT;
350 int ret; 350 int ret;
351 351
352 asc = kzalloc(sizeof(*asc), GFP_KERNEL); 352 asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
353 if (asc == NULL) { 353 if (asc == NULL) {
354 hid_err(hdev, "can't alloc apple descriptor\n"); 354 hid_err(hdev, "can't alloc apple descriptor\n");
355 return -ENOMEM; 355 return -ENOMEM;
@@ -362,7 +362,7 @@ static int apple_probe(struct hid_device *hdev,
362 ret = hid_parse(hdev); 362 ret = hid_parse(hdev);
363 if (ret) { 363 if (ret) {
364 hid_err(hdev, "parse failed\n"); 364 hid_err(hdev, "parse failed\n");
365 goto err_free; 365 return ret;
366 } 366 }
367 367
368 if (quirks & APPLE_HIDDEV) 368 if (quirks & APPLE_HIDDEV)
@@ -373,19 +373,10 @@ static int apple_probe(struct hid_device *hdev,
373 ret = hid_hw_start(hdev, connect_mask); 373 ret = hid_hw_start(hdev, connect_mask);
374 if (ret) { 374 if (ret) {
375 hid_err(hdev, "hw start failed\n"); 375 hid_err(hdev, "hw start failed\n");
376 goto err_free; 376 return ret;
377 } 377 }
378 378
379 return 0; 379 return 0;
380err_free:
381 kfree(asc);
382 return ret;
383}
384
385static void apple_remove(struct hid_device *hdev)
386{
387 hid_hw_stop(hdev);
388 kfree(hid_get_drvdata(hdev));
389} 380}
390 381
391static const struct hid_device_id apple_devices[] = { 382static const struct hid_device_id apple_devices[] = {
@@ -545,7 +536,6 @@ static struct hid_driver apple_driver = {
545 .id_table = apple_devices, 536 .id_table = apple_devices,
546 .report_fixup = apple_report_fixup, 537 .report_fixup = apple_report_fixup,
547 .probe = apple_probe, 538 .probe = apple_probe,
548 .remove = apple_remove,
549 .event = apple_event, 539 .event = apple_event,
550 .input_mapping = apple_input_mapping, 540 .input_mapping = apple_input_mapping,
551 .input_mapped = apple_input_mapped, 541 .input_mapped = apple_input_mapped,
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 5bc37343eb22..d393eb7ddaf0 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -484,7 +484,7 @@ static int magicmouse_probe(struct hid_device *hdev,
484 struct hid_report *report; 484 struct hid_report *report;
485 int ret; 485 int ret;
486 486
487 msc = kzalloc(sizeof(*msc), GFP_KERNEL); 487 msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL);
488 if (msc == NULL) { 488 if (msc == NULL) {
489 hid_err(hdev, "can't alloc magicmouse descriptor\n"); 489 hid_err(hdev, "can't alloc magicmouse descriptor\n");
490 return -ENOMEM; 490 return -ENOMEM;
@@ -498,13 +498,13 @@ static int magicmouse_probe(struct hid_device *hdev,
498 ret = hid_parse(hdev); 498 ret = hid_parse(hdev);
499 if (ret) { 499 if (ret) {
500 hid_err(hdev, "magicmouse hid parse failed\n"); 500 hid_err(hdev, "magicmouse hid parse failed\n");
501 goto err_free; 501 return ret;
502 } 502 }
503 503
504 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 504 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
505 if (ret) { 505 if (ret) {
506 hid_err(hdev, "magicmouse hw start failed\n"); 506 hid_err(hdev, "magicmouse hw start failed\n");
507 goto err_free; 507 return ret;
508 } 508 }
509 509
510 if (!msc->input) { 510 if (!msc->input) {
@@ -548,19 +548,9 @@ static int magicmouse_probe(struct hid_device *hdev,
548 return 0; 548 return 0;
549err_stop_hw: 549err_stop_hw:
550 hid_hw_stop(hdev); 550 hid_hw_stop(hdev);
551err_free:
552 kfree(msc);
553 return ret; 551 return ret;
554} 552}
555 553
556static void magicmouse_remove(struct hid_device *hdev)
557{
558 struct magicmouse_sc *msc = hid_get_drvdata(hdev);
559
560 hid_hw_stop(hdev);
561 kfree(msc);
562}
563
564static const struct hid_device_id magic_mice[] = { 554static const struct hid_device_id magic_mice[] = {
565 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 555 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
566 USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 }, 556 USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 },
@@ -574,7 +564,6 @@ static struct hid_driver magicmouse_driver = {
574 .name = "magicmouse", 564 .name = "magicmouse",
575 .id_table = magic_mice, 565 .id_table = magic_mice,
576 .probe = magicmouse_probe, 566 .probe = magicmouse_probe,
577 .remove = magicmouse_remove,
578 .raw_event = magicmouse_raw_event, 567 .raw_event = magicmouse_raw_event,
579 .input_mapping = magicmouse_input_mapping, 568 .input_mapping = magicmouse_input_mapping,
580 .input_configured = magicmouse_input_configured, 569 .input_configured = magicmouse_input_configured,
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index ecbc74923d06..f9898aad72fa 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -623,7 +623,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
623 struct sony_sc *sc; 623 struct sony_sc *sc;
624 unsigned int connect_mask = HID_CONNECT_DEFAULT; 624 unsigned int connect_mask = HID_CONNECT_DEFAULT;
625 625
626 sc = kzalloc(sizeof(*sc), GFP_KERNEL); 626 sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
627 if (sc == NULL) { 627 if (sc == NULL) {
628 hid_err(hdev, "can't alloc sony descriptor\n"); 628 hid_err(hdev, "can't alloc sony descriptor\n");
629 return -ENOMEM; 629 return -ENOMEM;
@@ -635,7 +635,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
635 ret = hid_parse(hdev); 635 ret = hid_parse(hdev);
636 if (ret) { 636 if (ret) {
637 hid_err(hdev, "parse failed\n"); 637 hid_err(hdev, "parse failed\n");
638 goto err_free; 638 return ret;
639 } 639 }
640 640
641 if (sc->quirks & VAIO_RDESC_CONSTANT) 641 if (sc->quirks & VAIO_RDESC_CONSTANT)
@@ -648,7 +648,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
648 ret = hid_hw_start(hdev, connect_mask); 648 ret = hid_hw_start(hdev, connect_mask);
649 if (ret) { 649 if (ret) {
650 hid_err(hdev, "hw start failed\n"); 650 hid_err(hdev, "hw start failed\n");
651 goto err_free; 651 return ret;
652 } 652 }
653 653
654 if (sc->quirks & SIXAXIS_CONTROLLER_USB) { 654 if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
@@ -668,8 +668,6 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
668 return 0; 668 return 0;
669err_stop: 669err_stop:
670 hid_hw_stop(hdev); 670 hid_hw_stop(hdev);
671err_free:
672 kfree(sc);
673 return ret; 671 return ret;
674} 672}
675 673
@@ -681,7 +679,6 @@ static void sony_remove(struct hid_device *hdev)
681 buzz_remove(hdev); 679 buzz_remove(hdev);
682 680
683 hid_hw_stop(hdev); 681 hid_hw_stop(hdev);
684 kfree(sc);
685} 682}
686 683
687static const struct hid_device_id sony_devices[] = { 684static const struct hid_device_id sony_devices[] = {
diff --git a/drivers/hid/hid-zydacron.c b/drivers/hid/hid-zydacron.c
index e4cddeccd6b5..1a660bd97ab2 100644
--- a/drivers/hid/hid-zydacron.c
+++ b/drivers/hid/hid-zydacron.c
@@ -169,7 +169,7 @@ static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id)
169 int ret; 169 int ret;
170 struct zc_device *zc; 170 struct zc_device *zc;
171 171
172 zc = kzalloc(sizeof(*zc), GFP_KERNEL); 172 zc = devm_kzalloc(&hdev->dev, sizeof(*zc), GFP_KERNEL);
173 if (zc == NULL) { 173 if (zc == NULL) {
174 hid_err(hdev, "can't alloc descriptor\n"); 174 hid_err(hdev, "can't alloc descriptor\n");
175 return -ENOMEM; 175 return -ENOMEM;
@@ -180,28 +180,16 @@ static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id)
180 ret = hid_parse(hdev); 180 ret = hid_parse(hdev);
181 if (ret) { 181 if (ret) {
182 hid_err(hdev, "parse failed\n"); 182 hid_err(hdev, "parse failed\n");
183 goto err_free; 183 return ret;
184 } 184 }
185 185
186 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 186 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
187 if (ret) { 187 if (ret) {
188 hid_err(hdev, "hw start failed\n"); 188 hid_err(hdev, "hw start failed\n");
189 goto err_free; 189 return ret;
190 } 190 }
191 191
192 return 0; 192 return 0;
193err_free:
194 kfree(zc);
195
196 return ret;
197}
198
199static void zc_remove(struct hid_device *hdev)
200{
201 struct zc_device *zc = hid_get_drvdata(hdev);
202
203 hid_hw_stop(hdev);
204 kfree(zc);
205} 193}
206 194
207static const struct hid_device_id zc_devices[] = { 195static const struct hid_device_id zc_devices[] = {
@@ -217,7 +205,6 @@ static struct hid_driver zc_driver = {
217 .input_mapping = zc_input_mapping, 205 .input_mapping = zc_input_mapping,
218 .raw_event = zc_raw_event, 206 .raw_event = zc_raw_event,
219 .probe = zc_probe, 207 .probe = zc_probe,
220 .remove = zc_remove,
221}; 208};
222module_hid_driver(zc_driver); 209module_hid_driver(zc_driver);
223 210