sysedp_reactive_capping: Fix warning string check
Anand Prasad [Wed, 28 Dec 2016 19:45:29 +0000 (11:45 -0800)]
The current implementation incorrectly checks if a pointer value is
NULL when actually referencing an array.
Instead, use a pointer to read the threshold warning string from
device-tree so that the pointer NULL check now works.

Bug 200266221

Change-Id: Iff9e43780534cf43e93b489c7ebe150fdf4ac437
Signed-off-by: Anand Prasad <anprasad@nvidia.com>
Reviewed-on: http://git-master/r/1277816
(cherry picked from commit 29d326af77ad71f6e61ce6e6e35eac6626500a72)
Reviewed-on: http://git-master/r/1279362
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Raymond Poudrier <rapoudrier@nvidia.com>

drivers/edp/sysedp_reactive_capping.c
include/linux/sysedp.h

index 10a1a41..43ab82b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2013-2017, NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -97,7 +97,6 @@ static void of_sysedp_reactive_capping_get_pdata(struct platform_device *pdev,
        int i;
        u32 lenp, val, irq_flags;
        const char *c_ptr;
-       const char *warning_ptr;
        const void *ptr;
        int ret;
        int max_capping_mw, step_alarm_mw, step_relax_mw, relax_ms;
@@ -152,11 +151,10 @@ static void of_sysedp_reactive_capping_get_pdata(struct platform_device *pdev,
        obj_ptr->relax_ms = relax_ms;
 
        ret = of_property_read_string(np, "nvidia,threshold_warning",
-                                     &warning_ptr);
-       if (!ret) {
-               strncpy(obj_ptr->threshold_warning, warning_ptr,
-                       THRESHOLD_WARNING_LEN);
-               obj_ptr->threshold_warning[THRESHOLD_WARNING_LEN-1] = 0;
+                                     &(obj_ptr->threshold_warning));
+       if (ret) {
+               dev_info(&pdev->dev, "No Threshold Warning string found.\n");
+               obj_ptr->threshold_warning = NULL;
        }
 
        /* Only interrupt at index 0 is expected per reactive capping node. */
index 839e646..c186c1f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2013-2017, NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -23,7 +23,6 @@
 #include <linux/kobject.h>
 
 #define SYSEDP_NAME_LEN 32
-#define THRESHOLD_WARNING_LEN 150
 
 /*
  * @name: name of consumer
@@ -140,7 +139,7 @@ struct sysedp_reactive_capping_platform_data {
        int cur_capping_mw;
        struct mutex mutex;
        struct delayed_work work;
-       char threshold_warning[THRESHOLD_WARNING_LEN];
+       const char *threshold_warning;
 };
 
 #ifdef CONFIG_SYSEDP_FRAMEWORK