From: bkotlowski Date: Mon, 6 Jul 2020 12:09:35 +0000 (+0000) Subject: Add missing licences headers and fix overflown integer during conversion X-Git-Tag: collectd-5.12.0~25^2^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f2cee80745af114c9768d0110f4dafaeb68d523;p=thirdparty%2Fcollectd.git Add missing licences headers and fix overflown integer during conversion --- diff --git a/src/intel-nvme.h b/src/intel-nvme.h index a9d7bcb36..27ed6cfd2 100644 --- a/src/intel-nvme.h +++ b/src/intel-nvme.h @@ -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 + * **/ + #include #ifdef __CHECKER__ diff --git a/src/nvme.h b/src/nvme.h index 8165b2cf0..a25355a4f 100644 --- a/src/nvme.h +++ b/src/nvme.h @@ -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 + * **/ + #include #define NVME_NSID_ALL 0xffffffff diff --git a/src/smart.c b/src/smart.c index fa085102e..c85bafa3c 100644 --- a/src/smart.c +++ b/src/smart.c @@ -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; } diff --git a/src/smart_test.c b/src/smart_test.c index bbb6cda11..4963b51eb 100644 --- a/src/smart_test.c +++ b/src/smart_test.c @@ -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