in svc.c [758:821]
static void gb_svc_pwrmon_debugfs_init(struct gb_svc *svc)
{
int i;
size_t bufsize;
struct dentry *dent;
struct gb_svc_pwrmon_rail_names_get_response *rail_names;
u8 rail_count;
dent = debugfs_create_dir("pwrmon", svc->debugfs_dentry);
if (IS_ERR_OR_NULL(dent))
return;
if (gb_svc_pwrmon_rail_count_get(svc, &rail_count))
goto err_pwrmon_debugfs;
if (!rail_count || rail_count > GB_SVC_PWRMON_MAX_RAIL_COUNT)
goto err_pwrmon_debugfs;
bufsize = sizeof(*rail_names) +
GB_SVC_PWRMON_RAIL_NAME_BUFSIZE * rail_count;
rail_names = kzalloc(bufsize, GFP_KERNEL);
if (!rail_names)
goto err_pwrmon_debugfs;
svc->pwrmon_rails = kcalloc(rail_count, sizeof(*svc->pwrmon_rails),
GFP_KERNEL);
if (!svc->pwrmon_rails)
goto err_pwrmon_debugfs_free;
if (gb_svc_pwrmon_rail_names_get(svc, rail_names, bufsize))
goto err_pwrmon_debugfs_free;
for (i = 0; i < rail_count; i++) {
struct dentry *dir;
struct svc_debugfs_pwrmon_rail *rail = &svc->pwrmon_rails[i];
char fname[GB_SVC_PWRMON_RAIL_NAME_BUFSIZE];
snprintf(fname, sizeof(fname), "%s",
(char *)&rail_names->name[i]);
rail->id = i;
rail->svc = svc;
dir = debugfs_create_dir(fname, dent);
debugfs_create_file("voltage_now", 0444, dir, rail,
&pwrmon_debugfs_voltage_fops);
debugfs_create_file("current_now", 0444, dir, rail,
&pwrmon_debugfs_current_fops);
debugfs_create_file("power_now", 0444, dir, rail,
&pwrmon_debugfs_power_fops);
}
kfree(rail_names);
return;
err_pwrmon_debugfs_free:
kfree(rail_names);
kfree(svc->pwrmon_rails);
svc->pwrmon_rails = NULL;
err_pwrmon_debugfs:
debugfs_remove(dent);
}