memset(&dev->class_dev, 0, sizeof(dev->class_dev));
  dev->class_dev.class = &xxx_class;
  strlcpy(dev->class_dev.class_id, xxx_name, KOBJ_NAME_LEN);
  class_set_devdata(&dev->class_dev, xxx_data)

  ret = class_device_register(&dev->class_dev);
  if (unlikely(ret)) {
    ...
    return ERR_PTR(ret);
  }