aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal/thermal.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/thermal/thermal.c')
-rw-r--r--drivers/thermal/thermal.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/drivers/thermal/thermal.c b/drivers/thermal/thermal.c
index e782b3e7fcdb..8b86e53ccf7a 100644
--- a/drivers/thermal/thermal.c
+++ b/drivers/thermal/thermal.c
@@ -306,12 +306,23 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
306{ 306{
307 struct thermal_cooling_device_instance *dev; 307 struct thermal_cooling_device_instance *dev;
308 struct thermal_cooling_device_instance *pos; 308 struct thermal_cooling_device_instance *pos;
309 struct thermal_zone_device *pos1;
310 struct thermal_cooling_device *pos2;
309 int result; 311 int result;
310 312
311 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) 313 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
312 return -EINVAL; 314 return -EINVAL;
313 315
314 if (!tz || !cdev) 316 list_for_each_entry(pos1, &thermal_tz_list, node) {
317 if (pos1 == tz)
318 break;
319 }
320 list_for_each_entry(pos2, &thermal_cdev_list, node) {
321 if (pos2 == cdev)
322 break;
323 }
324
325 if (tz != pos1 || cdev != pos2)
315 return -EINVAL; 326 return -EINVAL;
316 327
317 dev = 328 dev =
@@ -437,20 +448,20 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *type,
437 int result; 448 int result;
438 449
439 if (strlen(type) >= THERMAL_NAME_LENGTH) 450 if (strlen(type) >= THERMAL_NAME_LENGTH)
440 return NULL; 451 return ERR_PTR(-EINVAL);
441 452
442 if (!ops || !ops->get_max_state || !ops->get_cur_state || 453 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
443 !ops->set_cur_state) 454 !ops->set_cur_state)
444 return NULL; 455 return ERR_PTR(-EINVAL);
445 456
446 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL); 457 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
447 if (!cdev) 458 if (!cdev)
448 return NULL; 459 return ERR_PTR(-ENOMEM);
449 460
450 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id); 461 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
451 if (result) { 462 if (result) {
452 kfree(cdev); 463 kfree(cdev);
453 return NULL; 464 return ERR_PTR(result);
454 } 465 }
455 466
456 strcpy(cdev->type, type); 467 strcpy(cdev->type, type);
@@ -462,7 +473,7 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *type,
462 if (result) { 473 if (result) {
463 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id); 474 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
464 kfree(cdev); 475 kfree(cdev);
465 return NULL; 476 return ERR_PTR(result);
466 } 477 }
467 478
468 /* sys I/F */ 479 /* sys I/F */
@@ -498,7 +509,7 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *type,
498 unregister: 509 unregister:
499 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id); 510 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
500 device_unregister(&cdev->device); 511 device_unregister(&cdev->device);
501 return NULL; 512 return ERR_PTR(result);
502} 513}
503 514
504EXPORT_SYMBOL(thermal_cooling_device_register); 515EXPORT_SYMBOL(thermal_cooling_device_register);
@@ -570,17 +581,17 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
570 int count; 581 int count;
571 582
572 if (strlen(type) >= THERMAL_NAME_LENGTH) 583 if (strlen(type) >= THERMAL_NAME_LENGTH)
573 return NULL; 584 return ERR_PTR(-EINVAL);
574 585
575 if (trips > THERMAL_MAX_TRIPS || trips < 0) 586 if (trips > THERMAL_MAX_TRIPS || trips < 0)
576 return NULL; 587 return ERR_PTR(-EINVAL);
577 588
578 if (!ops || !ops->get_temp) 589 if (!ops || !ops->get_temp)
579 return NULL; 590 return ERR_PTR(-EINVAL);
580 591
581 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL); 592 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL);
582 if (!tz) 593 if (!tz)
583 return NULL; 594 return ERR_PTR(-ENOMEM);
584 595
585 INIT_LIST_HEAD(&tz->cooling_devices); 596 INIT_LIST_HEAD(&tz->cooling_devices);
586 idr_init(&tz->idr); 597 idr_init(&tz->idr);
@@ -588,7 +599,7 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
588 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id); 599 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
589 if (result) { 600 if (result) {
590 kfree(tz); 601 kfree(tz);
591 return NULL; 602 return ERR_PTR(result);
592 } 603 }
593 604
594 strcpy(tz->type, type); 605 strcpy(tz->type, type);
@@ -601,7 +612,7 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
601 if (result) { 612 if (result) {
602 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); 613 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
603 kfree(tz); 614 kfree(tz);
604 return NULL; 615 return ERR_PTR(result);
605 } 616 }
606 617
607 /* sys I/F */ 618 /* sys I/F */
@@ -643,7 +654,7 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
643 unregister: 654 unregister:
644 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); 655 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
645 device_unregister(&tz->device); 656 device_unregister(&tz->device);
646 return NULL; 657 return ERR_PTR(result);
647} 658}
648 659
649EXPORT_SYMBOL(thermal_zone_device_register); 660EXPORT_SYMBOL(thermal_zone_device_register);