From: David Lin Date: Sat, 23 Apr 2016 02:03:42 +0000 (-0700) Subject: greybus: svc: clean up gb_svc struct for pwrmon X-Git-Tag: Ubuntu-4.10.0-19.21~2488^2~378^2~21^2~487 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=3fd747a63e836baab1739bab7f18d9227a083312;p=mirror_ubuntu-artful-kernel.git greybus: svc: clean up gb_svc struct for pwrmon The power rail names and counts are unnecessarily stored in the gb_svc structure once the SVC created, this causes waste of memory usage. This patch removes rail names and rail counts storage from th gb_svc structure. Testing Done: - Validated the readings from /d/greybus/1-svc/pwrmon/* Signed-off-by: David Lin Reviewed-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c index 0a49698ce298..b30b2277fa86 100644 --- a/drivers/staging/greybus/svc.c +++ b/drivers/staging/greybus/svc.c @@ -581,38 +581,40 @@ 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, &svc->rail_count)) + if (gb_svc_pwrmon_rail_count_get(svc, &rail_count)) goto err_pwrmon_debugfs; - if (!svc->rail_count || svc->rail_count > GB_SVC_PWRMON_MAX_RAIL_COUNT) + if (!rail_count || rail_count > GB_SVC_PWRMON_MAX_RAIL_COUNT) goto err_pwrmon_debugfs; - bufsize = GB_SVC_PWRMON_RAIL_NAME_BUFSIZE * svc->rail_count; + bufsize = GB_SVC_PWRMON_RAIL_NAME_BUFSIZE * rail_count; - svc->rail_names = kzalloc(bufsize, GFP_KERNEL); - if (!svc->rail_names) + rail_names = kzalloc(bufsize, GFP_KERNEL); + if (!rail_names) goto err_pwrmon_debugfs; - svc->pwrmon_rails = kcalloc(svc->rail_count, sizeof(*svc->pwrmon_rails), + 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, svc->rail_names, bufsize)) + if (gb_svc_pwrmon_rail_names_get(svc, rail_names, bufsize)) goto err_pwrmon_debugfs_free; - for (i = 0; i < svc->rail_count; i++) { + 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 *)&svc->rail_names->name[i]); + (char *)&rail_names->name[i]); rail->id = i; rail->svc = svc; @@ -625,12 +627,12 @@ static void gb_svc_pwrmon_debugfs_init(struct gb_svc *svc) debugfs_create_file("power_now", S_IRUGO, dir, rail, &pwrmon_debugfs_power_fops); }; + + kfree(rail_names); return; err_pwrmon_debugfs_free: - kfree(svc->rail_names); - svc->rail_names = NULL; - + kfree(rail_names); kfree(svc->pwrmon_rails); svc->pwrmon_rails = NULL; @@ -648,7 +650,6 @@ static void gb_svc_debugfs_init(struct gb_svc *svc) static void gb_svc_debugfs_exit(struct gb_svc *svc) { debugfs_remove_recursive(svc->debugfs_dentry); - kfree(svc->rail_names); } static int gb_svc_hello(struct gb_operation *op) diff --git a/drivers/staging/greybus/svc.h b/drivers/staging/greybus/svc.h index 546061198cb9..7268db6e2643 100644 --- a/drivers/staging/greybus/svc.h +++ b/drivers/staging/greybus/svc.h @@ -48,8 +48,6 @@ struct gb_svc { struct dentry *debugfs_dentry; struct svc_debugfs_pwrmon_rail *pwrmon_rails; - struct gb_svc_pwrmon_rail_names_get_response *rail_names; - u8 rail_count; }; #define to_gb_svc(d) container_of(d, struct gb_svc, dev)