greybus: svc: clean up gb_svc struct for pwrmon
authorDavid Lin <dtwlin@google.com>
Sat, 23 Apr 2016 02:03:42 +0000 (19:03 -0700)
committerGreg Kroah-Hartman <gregkh@google.com>
Mon, 25 Apr 2016 18:13:59 +0000 (11:13 -0700)
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 <dtwlin@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/svc.c
drivers/staging/greybus/svc.h

index 0a49698..b30b227 100644 (file)
@@ -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)
index 5460611..7268db6 100644 (file)
@@ -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)