#define DECLARE_ATTR(_name,_mode,_show,_store) \
{ \
  .attr  = { .name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE } \
  .show  = _show, \
  .store = _store, \
}

static struct class_device_attribute bl_class_device_attribute[] = {
  DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power),
  DECLARE_ATTR(brightness, 0644, backlight_show_brightness, backlight_store_brightness),
  DECLARE_ATTR(max_brightness, 0644, backlight_show_max_brightness, NULL),
};

int backlight_device *backlight_device_register(...)
{
  ...
  for (i = 0; i < ARRAY_SIZE(bl_class_device_attribute); i++) {
    rc = class_device_create_file(&new_bd->class_dev,
                                  &bl_class_device_attribute[i]);
    if (unlikely(rc)) {
      while (--i >= 0)
        class_device_remove_file(&new_bd->class_dev,
                                 &bl_class_device_attribute[i]);
      ...
    }
  }
  ...
}