summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiwakar Tundlam <dtundlam@nvidia.com>2013-02-20 14:58:13 -0500
committerNicolin Chen <nicolinc@nvidia.com>2017-08-14 21:38:52 -0400
commita80e0e397671343e1900eb265dbd281998f0bb3a (patch)
treeb7bd0fe952b84d13348eee77dfcdbe6abea38746
parent99b1a4f67bd91155380405091921a0c535bbdbf9 (diff)
drivers: misc: therm_est: Fixed buffer issues
Cleaned up some buffer issues which became apparent with http://git-master/r/145060 bug 1158994 Change-Id: Ie5f605bd7eee4efce548764a7ce2fd3f0c230844 Signed-off-by: Diwakar Tundlam <dtundlam@nvidia.com> Reviewed-on: http://git-master/r/202625 (cherry picked from commit 5e8643cab0e91b80bebe6266c32aa05fee4a0a10) Reviewed-on: http://git-master/r/204253
-rw-r--r--drivers/misc/therm_est.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/drivers/misc/therm_est.c b/drivers/misc/therm_est.c
index 111299a1b..ab543bb7d 100644
--- a/drivers/misc/therm_est.c
+++ b/drivers/misc/therm_est.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/misc/therm_est.c 2 * drivers/misc/therm_est.c
3 * 3 *
4 * Copyright (C) 2010-2013 NVIDIA Corporation. 4 * Copyright (c) 2010-2013 NVIDIA Corporation. All rights reserved.
5 * 5 *
6 * This software is licensed under the terms of the GNU General Public 6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and 7 * License version 2, as published by the Free Software Foundation, and
@@ -190,14 +190,16 @@ static ssize_t show_coeff(struct device *dev,
190 ssize_t len, total_len = 0; 190 ssize_t len, total_len = 0;
191 int i, j; 191 int i, j;
192 for (i = 0; i < est->ndevs; i++) { 192 for (i = 0; i < est->ndevs; i++) {
193 len = snprintf(buf + total_len, PAGE_SIZE, "[%d]", i); 193 len = snprintf(buf + total_len,
194 PAGE_SIZE - total_len, "[%d]", i);
194 total_len += len; 195 total_len += len;
195 for (j = 0; j < HIST_LEN; j++) { 196 for (j = 0; j < HIST_LEN; j++) {
196 len = snprintf(buf + total_len, PAGE_SIZE, " %ld", 197 len = snprintf(buf + total_len,
198 PAGE_SIZE - total_len, " %ld",
197 est->devs[i].coeffs[j]); 199 est->devs[i].coeffs[j]);
198 total_len += len; 200 total_len += len;
199 } 201 }
200 len = snprintf(buf + total_len, PAGE_SIZE, "\n"); 202 len = snprintf(buf + total_len, PAGE_SIZE - total_len, "\n");
201 total_len += len; 203 total_len += len;
202 } 204 }
203 return strlen(buf); 205 return strlen(buf);
@@ -245,7 +247,7 @@ static ssize_t set_coeff(struct device *dev,
245 return -EINVAL; 247 return -EINVAL;
246 248
247 /* This has obvious locking issues but don't worry about it */ 249 /* This has obvious locking issues but don't worry about it */
248 memcpy(est->devs[devid].coeffs, coeff, sizeof(long) * HIST_LEN); 250 memcpy(est->devs[devid].coeffs, coeff, sizeof(coeff[0]) * HIST_LEN);
249 251
250 return count; 252 return count;
251} 253}
@@ -285,15 +287,16 @@ static ssize_t show_temps(struct device *dev,
285 287
286 /* This has obvious locking issues but don't worry about it */ 288 /* This has obvious locking issues but don't worry about it */
287 for (i = 0; i < est->ndevs; i++) { 289 for (i = 0; i < est->ndevs; i++) {
288 total_len += snprintf(buf + total_len, PAGE_SIZE, "[%d]", i); 290 total_len += snprintf(buf + total_len,
291 PAGE_SIZE - total_len, "[%d]", i);
289 for (j = 0; j < HIST_LEN; j++) { 292 for (j = 0; j < HIST_LEN; j++) {
290 index = (est->ntemp - j + HIST_LEN) % HIST_LEN; 293 index = (est->ntemp - j + HIST_LEN) % HIST_LEN;
291 total_len += snprintf(buf + total_len, 294 total_len += snprintf(buf + total_len,
292 PAGE_SIZE, 295 PAGE_SIZE - total_len, " %ld",
293 " %ld",
294 est->devs[i].hist[index]); 296 est->devs[i].hist[index]);
295 } 297 }
296 total_len += snprintf(buf + total_len, PAGE_SIZE, "\n"); 298 total_len += snprintf(buf + total_len,
299 PAGE_SIZE - total_len, "\n");
297 } 300 }
298 return strlen(buf); 301 return strlen(buf);
299} 302}