power: Use ARRAY_SIZE macro where possible
Change-Id: Ie47d0e6b91b7bba378b0fdf53a345a021b0c2d48
diff --git a/power-660.c b/power-660.c
index 028cfcf..7c274af 100644
--- a/power-660.c
+++ b/power-660.c
@@ -116,7 +116,7 @@
if (is_target_SDM630()) {
int res[] = {0x41414000, 0x459, 0x41410000, 0x5F, 0x41400000, 0x4, 0x41820000, 0xA};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
+ num_resources = ARRAY_SIZE(res);
}
/*
1. CPUfreq params
@@ -131,7 +131,7 @@
int res[] = {0x41414100, 0x386, 0x41410100, 0x5F, 0x41400100,
0x4, 0x41820000, 0xA, 0x40C54000, 0x1F4};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
+ num_resources = ARRAY_SIZE(res);
}
perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values, num_resources);
}
@@ -195,8 +195,7 @@
int res[] = {0x41414000, 0x459, 0x41410000, 0x5F, 0x41400000, 0x4,
0x41420000, 0x5F, 0x40C2C000, 0X5, 0x41820000, 0xA};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
-
+ num_resources = ARRAY_SIZE(res);
}
/*
1. CPUfreq params
@@ -209,7 +208,7 @@
else {
int res[] = {0x41414100, 0x386, 0x41410100, 0x5F, 0x41400100, 0x4, 0x41820000, 0xA};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
+ num_resources = ARRAY_SIZE(res);
}
if (!video_encode_hint_sent) {
perform_hint_action(video_encode_metadata.hint_id, resource_values, num_resources);
diff --git a/power-845.c b/power-845.c
index 0138e26..ffe455d 100644
--- a/power-845.c
+++ b/power-845.c
@@ -195,7 +195,7 @@
case POWER_HINT_INTERACTION: {
int resources[] = {0x40800100, 0x514};
int duration = 100;
- interaction(duration, sizeof(resources) / sizeof(resources[0]), resources);
+ interaction(duration, ARRAY_SIZE(resources), resources);
ret_val = HINT_HANDLED;
} break;
default:
diff --git a/power-8937.c b/power-8937.c
index d6d7f21..b7a6d17 100644
--- a/power-8937.c
+++ b/power-8937.c
@@ -108,7 +108,7 @@
INT_OP_NOTIFY_ON_MIGRATE, 0x00};
perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values,
- sizeof(resource_values) / sizeof(resource_values[0]));
+ ARRAY_SIZE(resource_values));
} /* Perf time rate set for CORE0,CORE4 8952 target*/
} else {
@@ -128,7 +128,6 @@
static void process_video_encode_hint(void* metadata) {
char governor[80] = {0};
int resource_values[20] = {0};
- int num_resources = 0;
struct video_encode_metadata_t video_encode_metadata;
ALOGI("Got process_video_encode_hint");
@@ -174,10 +173,9 @@
0x41440100, 0x5f, 0x4143c100, 0x3e6,
};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
if (!video_encode_hint_sent) {
perform_hint_action(video_encode_metadata.hint_id, resource_values,
- num_resources);
+ ARRAY_SIZE(res));
video_encode_hint_sent = 1;
}
} else {
@@ -187,10 +185,9 @@
0xa,
};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
if (!video_encode_hint_sent) {
perform_hint_action(video_encode_metadata.hint_id, resource_values,
- num_resources);
+ ARRAY_SIZE(res));
video_encode_hint_sent = 1;
}
}
@@ -203,8 +200,7 @@
INT_OP_CLUSTER0_TIMER_RATE, BIG_LITTLE_TR_MS_40,
INT_OP_CLUSTER1_TIMER_RATE, BIG_LITTLE_TR_MS_40};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
- perform_hint_action(video_encode_metadata.hint_id, resource_values, num_resources);
+ perform_hint_action(video_encode_metadata.hint_id, resource_values, ARRAY_SIZE(res));
video_encode_hint_sent = 1;
}
} else if (video_encode_metadata.state == 0) {
diff --git a/power-8953.c b/power-8953.c
index 40f4e2e..e21ba68 100644
--- a/power-8953.c
+++ b/power-8953.c
@@ -110,7 +110,7 @@
0x28,
};
perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values,
- sizeof(resource_values) / sizeof(resource_values[0]));
+ ARRAY_SIZE(resource_values));
} /* Perf time rate set for CORE0,CORE4 8952 target*/
} else {
@@ -130,7 +130,6 @@
static void process_video_encode_hint(void* metadata) {
char governor[80] = {0};
int resource_values[20] = {0};
- int num_resources = 0;
struct video_encode_metadata_t video_encode_metadata;
ALOGI("Got process_video_encode_hint");
@@ -176,10 +175,9 @@
0x41440100, 0x5f, 0x4143c100, 0x40c,
};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
if (!video_encode_hint_sent) {
perform_hint_action(video_encode_metadata.hint_id, resource_values,
- num_resources);
+ ARRAY_SIZE(res));
video_encode_hint_sent = 1;
}
} else {
@@ -189,10 +187,9 @@
0xa,
};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
if (!video_encode_hint_sent) {
perform_hint_action(video_encode_metadata.hint_id, resource_values,
- num_resources);
+ ARRAY_SIZE(res));
video_encode_hint_sent = 1;
}
}
@@ -203,9 +200,9 @@
0x41430000, 0x1, 0x41434000, 0x1, 0x41424000, 0x28,
};
memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
- num_resources = sizeof(res) / sizeof(res[0]);
if (!video_encode_hint_sent) {
- perform_hint_action(video_encode_metadata.hint_id, resource_values, num_resources);
+ perform_hint_action(video_encode_metadata.hint_id, resource_values,
+ ARRAY_SIZE(res));
video_encode_hint_sent = 1;
}
}
diff --git a/power-8996.c b/power-8996.c
index 2feeed6..b66e5c9 100644
--- a/power-8996.c
+++ b/power-8996.c
@@ -96,7 +96,7 @@
0x41814000, 0x32, 0x4180C000, 0x0, 0x41820000, 0xA};
perform_hint_action(video_encode_metadata.hint_id, resource_values,
- sizeof(resource_values) / sizeof(resource_values[0]));
+ ARRAY_SIZE(resource_values));
ALOGI("Video Encode hint start");
return HINT_HANDLED;
}
diff --git a/power-common.h b/power-common.h
index e8e077c..ec17a00 100644
--- a/power-common.h
+++ b/power-common.h
@@ -52,6 +52,8 @@
void set_expensive_rendering(bool enabled);
void set_interactive(int on);
+#define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0]))
+
#ifdef __cplusplus
}
#endif
diff --git a/power-msmnile.c b/power-msmnile.c
index 3820d50..16144a8 100644
--- a/power-msmnile.c
+++ b/power-msmnile.c
@@ -60,7 +60,7 @@
case POWER_HINT_INTERACTION: {
int resources[] = {0x40800100, 0x514};
int duration = 100;
- interaction(duration, sizeof(resources) / sizeof(resources[0]), resources);
+ interaction(duration, ARRAY_SIZE(resources), resources);
ret_val = HINT_HANDLED;
}
default: