458
459
460
461
462
463
464
465int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
466 int trip,
467 struct thermal_cooling_device *cdev)
468{
469 struct thermal_cooling_device_instance *dev;
470 struct thermal_cooling_device_instance *pos;
471 struct thermal_zone_device *pos1;
472 struct thermal_cooling_device *pos2;
473 int result;
474
475 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
476 return -EINVAL;
477
478 list_for_each_entry(pos1, &thermal_tz_list, node) {
479 if (pos1 == tz)
480 break;
481 }
482 list_for_each_entry(pos2, &thermal_cdev_list, node) {
483 if (pos2 == cdev)
484 break;
485 }
486
487 if (tz != pos1 || cdev != pos2)
488 return -EINVAL;
489
490 dev =
491 kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL);
492 if (!dev)
493 return -ENOMEM;
494 dev->tz = tz;
495 dev->cdev = cdev;
496 dev->trip = trip;
497 result = get_idr(&tz->idr, &tz->lock, &dev->id);
498 if (result)