The armdiv array may contain unset divider values.
Check the relevant value to prevent division by zero
errors. Also check for set nr_armdiv and armdivmask
before meddling with clkdiv0.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
unsigned div;
int ptr;
+ if (!nr_armdiv)
+ return -EINVAL;
+
for (ptr = 0; ptr < nr_armdiv; ptr++) {
div = armdiv[ptr];
- calc = parent / div;
- if (calc <= rate && div < best)
- best = div;
+ if (div) {
+ calc = parent / div;
+ if (calc <= rate && div < best)
+ best = div;
+ }
}
return parent / best;
unsigned long clkcon0;
int val;
+ if (!nr_armdiv || !armdivmask)
+ return -EINVAL;
+
clkcon0 = __raw_readl(S3C2443_CLKDIV0);
clkcon0 &= armdivmask;
val = clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT;
int ptr;
int val = -1;
+ if (!nr_armdiv || !armdivmask)
+ return -EINVAL;
+
for (ptr = 0; ptr < nr_armdiv; ptr++) {
div = armdiv[ptr];
- calc = parent / div;
- if (calc <= rate && div < best) {
- best = div;
- val = ptr;
+ if (div) {
+ calc = parent / div;
+ if (calc <= rate && div < best) {
+ best = div;
+ val = ptr;
+ }
}
}