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)
499 goto free_mem;
500
501 sprintf(dev->name, "cdev%d", dev->id);
502 result =
503 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
504 if (result)
505 goto release_idr;
506
507 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
508 dev->attr.attr.name = dev->attr_name;
509 dev->attr.attr.mode = 0444;
510 dev->attr.show = thermal_cooling_device_trip_point_show;
511 result = device_create_file(&tz->device, &dev->attr);
512 if (result)
513 goto remove_symbol_link;
514
515 mutex_lock(&tz->lock);
516 list_for_each_entry(pos, &tz->cooling_devices, node)
517 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
518 result = -EEXIST;
519 break;
520 }
521 if (!result)
522 list_add_tail(&dev->node, &tz->cooling_devices);
523 mutex_unlock(&tz->lock);
524
525 if (!result)