From f952347c840f04b0e241a1f2ee9189ae6631ab5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 13 Jan 2019 17:40:17 +0100 Subject: [PATCH] module/backlight: don't divide by zero --- modules/backlight.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/backlight.c b/modules/backlight.c index 6f9bf46..70b65a5 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -41,11 +41,15 @@ content(struct module *mod) const struct private *m = mod->private; mtx_lock(&mod->lock); + + const long current = m->current_brightness; + const long max = m->max_brightness; + const long percent = max > 0 ? 100 * current / max : 0; + struct tag_set tags = { .tags = (struct tag *[]){ - tag_new_int_range( - mod, "brightness", m->current_brightness, 0, m->max_brightness), - tag_new_int_range(mod, "percent", 100 * m->current_brightness / m->max_brightness, 0, 100), + tag_new_int_range(mod, "brightness", current, 0, max), + tag_new_int_range(mod, "percent", percent, 0, 100), }, .count = 2, };