greybus: svc: pwrmon: validate svc protocol op status when getting rail names
authorDavid Lin <dtwlin@google.com>
Wed, 8 Jun 2016 07:39:00 +0000 (09:39 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 8 Jun 2016 17:21:34 +0000 (10:21 -0700)
AP should check for Greybus SVC Protocol Operation Status to determine if the
operation was successfully completed by the SVC

Testing Done:
- Successfully getting the rail names in the pwrmon_dummy sandbox branch

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/greybus_protocols.h
drivers/staging/greybus/svc.c

index 8125fb7..3c6415f 100644 (file)
@@ -1145,6 +1145,7 @@ struct gb_svc_pwrmon_rail_count_get_response {
 #define GB_SVC_PWRMON_RAIL_NAME_BUFSIZE                32
 
 struct gb_svc_pwrmon_rail_names_get_response {
+       __u8    status;
        __u8    name[0][GB_SVC_PWRMON_RAIL_NAME_BUFSIZE];
 } __packed;
 
index bfdd0ce..e2ab942 100644 (file)
@@ -135,6 +135,13 @@ static int gb_svc_pwrmon_rail_names_get(struct gb_svc *svc,
                return ret;
        }
 
+       if (response->status != GB_SVC_OP_SUCCESS) {
+               dev_err(&svc->dev,
+                       "SVC error while getting rail names: %u\n",
+                       response->status);
+               return -EREMOTEIO;
+       }
+
        return 0;
 }
 
@@ -778,7 +785,8 @@ static void gb_svc_pwrmon_debugfs_init(struct gb_svc *svc)
        if (!rail_count || rail_count > GB_SVC_PWRMON_MAX_RAIL_COUNT)
                goto err_pwrmon_debugfs;
 
-       bufsize = GB_SVC_PWRMON_RAIL_NAME_BUFSIZE * rail_count;
+       bufsize = sizeof(*rail_names) +
+               GB_SVC_PWRMON_RAIL_NAME_BUFSIZE * rail_count;
 
        rail_names = kzalloc(bufsize, GFP_KERNEL);
        if (!rail_names)