aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Imes <connor.k.imes@gmail.com>2021-04-10 19:14:50 -0400
committerConnor Imes <connor.k.imes@gmail.com>2021-04-10 19:14:50 -0400
commit4047d171791669794b3929fe86c20cbc3335384c (patch)
treef29a4752a96ac359cdd267a92ee603c9cf9afb09
parent868246c1bd9cbea6b30defdb9004392e6498f7eb (diff)
powercap: check validity of control_type_name
-rw-r--r--src/powercap.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/powercap.c b/src/powercap.c
index e72d757..f1847c3 100644
--- a/src/powercap.c
+++ b/src/powercap.c
@@ -40,7 +40,7 @@ int powercap_constraint_file_get_name(powercap_constraint_file type, uint32_t co
}
int powercap_get_path(const char* control_type_name, const uint32_t* zones, uint32_t depth, char* buf, size_t size) {
- if (!control_type_name || !buf || !size || (depth && !zones)) {
+ if (!is_valid_control_type(control_type_name) || !buf || !size || (depth && !zones)) {
errno = EINVAL;
return -errno;
}
@@ -50,7 +50,8 @@ int powercap_get_path(const char* control_type_name, const uint32_t* zones, uint
int powercap_control_type_file_get_path(powercap_control_type_file type, const char* control_type_name, char* buf,
size_t size) {
/* check type in case users pass bad int value instead of enum; int cast silences clang compiler */
- if (!control_type_name || !buf || !size || (int) type < 0 || (int) type > POWERCAP_CONTROL_TYPE_FILE_ENABLED) {
+ if (!is_valid_control_type(control_type_name) || !buf || !size ||
+ (int) type < 0 || (int) type > POWERCAP_CONTROL_TYPE_FILE_ENABLED) {
errno = EINVAL;
return -errno;
}
@@ -60,8 +61,8 @@ int powercap_control_type_file_get_path(powercap_control_type_file type, const c
int powercap_zone_file_get_path(powercap_zone_file type, const char* control_type_name, const uint32_t* zones,
uint32_t depth, char* buf, size_t size) {
/* check type in case users pass bad int value instead of enum; int cast silences clang compiler */
- if (!control_type_name || !buf || !size || (int) type < 0 || (int) type > POWERCAP_ZONE_FILE_NAME ||
- (depth && !zones)) {
+ if (!is_valid_control_type(control_type_name) || !buf || !size ||
+ (int) type < 0 || (int) type > POWERCAP_ZONE_FILE_NAME || (depth && !zones)) {
errno = EINVAL;
return -errno;
}
@@ -72,8 +73,8 @@ int powercap_constraint_file_get_path(powercap_constraint_file type, const char*
const uint32_t* zones, uint32_t depth, uint32_t constraint, char* buf,
size_t size) {
/* check type in case users pass bad int value instead of enum; int cast silences clang compiler */
- if (!control_type_name || !buf || !size || (int) type < 0 || (int) type > POWERCAP_CONSTRAINT_FILE_NAME ||
- (depth && !zones)) {
+ if (!is_valid_control_type(control_type_name) || !buf || !size ||
+ (int) type < 0 || (int) type > POWERCAP_CONSTRAINT_FILE_NAME || (depth && !zones)) {
errno = EINVAL;
return -errno;
}