]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Add missing licences headers and fix overflown integer during conversion
authorbkotlowski <bartlomiej.kotlowski@intel.com>
Mon, 6 Jul 2020 12:09:35 +0000 (12:09 +0000)
committerbkotlowski <bartlomiej.kotlowski@intel.com>
Mon, 6 Jul 2020 12:33:10 +0000 (12:33 +0000)
src/intel-nvme.h
src/nvme.h
src/smart.c
src/smart_test.c

index a9d7bcb3651621d0ce8533b9a207ad9abc159945..27ed6cfd233314f05d5d8038aa0186c247a14b16 100644 (file)
@@ -1,3 +1,31 @@
+/**
+ * collectd - src/intel-nvme.h
+ * MIT License
+ *
+ * Copyright (C) 2020  Intel Corporation. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Bartlomiej Kotlowski <bartlomiej.kotlowski@intel.com>
+ * **/
+
 #include <linux/types.h>
 
 #ifdef __CHECKER__
index 8165b2cf0cafe2db97df8335296e9ea858283cfa..a25355a4f5393a7caac9130f1f636ae420eeb8f2 100644 (file)
@@ -1,3 +1,31 @@
+/**
+ * collectd - src/nvme.h
+ * MIT License
+ *
+ * Copyright (C) 2020  Intel Corporation. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Bartlomiej Kotlowski <bartlomiej.kotlowski@intel.com>
+ * **/
+
 #include <linux/types.h>
 
 #define NVME_NSID_ALL 0xffffffff
index fa085102ee46cb3bb53b7f395425cd31b0337dca..c85bafa3c275a4c84225972708ff9f3ccdceddc1 100644 (file)
@@ -45,7 +45,7 @@
 
 #define O_RDWR 02
 #define NVME_SMART_CDW10 0x00800002
-
+#define SHIFT_BYTE_LEFT 256
 struct nvme_admin_cmd {
   __u8 opcode;
   __u8 rsvd1[3];
@@ -207,17 +207,28 @@ static void handle_attribute(SkDisk *d, const SkSmartAttributeParsedData *a,
 
 static inline double compute_field(__u8 *data) {
   double sum = 0;
+  double add = 0;
 
-  for (int i = 0; i < 16; i++)
-    sum += data[i] << (i * 8);
-
+  for (int i = 0; i < 16; i++) {
+    add = data[15 - i];
+    for (int j = i + 1; j < 16; j++) {
+      add *= SHIFT_BYTE_LEFT;
+    }
+    sum += add;
+  }
   return sum;
 }
+
 static inline double int48_to_double(__u8 *data) {
   double sum = 0;
+  double add = 0;
 
   for (int i = 0; i < 6; i++) {
-    sum += data[i] << (i * 8);
+    add = data[5 - i];
+    for (int j = i + 1; j < 6; j++) {
+      add *= SHIFT_BYTE_LEFT;
+    }
+    sum += add;
   }
   return sum;
 }
index bbb6cda11838a781c3a9f669cac6745560813672..4963b51ebcbda06a657c1d883c30238c309129b8 100644 (file)
@@ -1,6 +1,8 @@
 /**
  * collectd - src/smart_test.c
- * Copyright (C) 2018  Intel Corporation. All rights reserved.
+ * MIT License
+ *
+ * Copyright (C) 2020  Intel Corporation. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -28,7 +30,7 @@
 #include "testing.h"
 
 int VENDOR_ID = 0x8086;
-char *CORRET_DEV_PATH = "/dev/nvme0n1";
+char *CORRECT_DEV_PATH = "/dev/nvme0n1";
 
 int ioctl(int __fd, unsigned long int __request, ...) {
   va_list valist;
@@ -60,7 +62,7 @@ int ioctl(int __fd, unsigned long int __request, ...) {
 };
 
 int open(const char *__path, int __oflag, ...) {
-  if (__path == CORRET_DEV_PATH) {
+  if (__path == CORRECT_DEV_PATH) {
     return 0;
   }
   return -1;
@@ -69,11 +71,11 @@ int open(const char *__path, int __oflag, ...) {
 DEF_TEST(x) {
   int ret;
 
-  ret = get_vendor_id(CORRET_DEV_PATH, "stub");
+  ret = get_vendor_id(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(VENDOR_ID, ret);
 
   VENDOR_ID = 0x144D;
-  ret = get_vendor_id(CORRET_DEV_PATH, "stub");
+  ret = get_vendor_id(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(VENDOR_ID, ret);
   VENDOR_ID = 0x8086;
 
@@ -81,16 +83,16 @@ DEF_TEST(x) {
   ret = get_vendor_id("dev/nvme0nXX", "stub");
   EXPECT_EQ_INT(-1, ret);
 
-  ret = smart_read_nvme_intel_disk(CORRET_DEV_PATH, "stub");
+  ret = smart_read_nvme_intel_disk(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(0, ret);
 
   // incorrect with DEV_PATH
   ret = smart_read_nvme_intel_disk("dev/nvme0nXX", "stub");
   EXPECT_EQ_INT(-1, ret);
 
-  CORRET_DEV_PATH = "dev/sda0";
+  CORRECT_DEV_PATH = "dev/sda0";
 
-  ret = smart_read_nvme_disk(CORRET_DEV_PATH, "stub");
+  ret = smart_read_nvme_disk(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(0, ret);
 
   // incorrect with DEV_PATH