sw5100_bms: shutdown soc offset / reserve round up.

Replace truncation due to integer division with round up so that 99% is
properly modeled on the soc offset / reserve scale. Also correct for
possibility of division by zero or negative value.

Bug: 306380628
Test: Confirm healthd SOC percentage reaches 99%.
(cherry picked from https://partner-android-review.googlesource.com/q/commit:837fe047d049754272f00a2c90e5ae749f137d51)
Merged-In: Ibad6b75c6ce5088f32b10cb92e23890e5a15b705
Change-Id: Ibad6b75c6ce5088f32b10cb92e23890e5a15b705
diff --git a/sw5100_bms.c b/sw5100_bms.c
index 06bc616..1aded93 100644
--- a/sw5100_bms.c
+++ b/sw5100_bms.c
@@ -822,11 +822,11 @@
 /** Given a SOC percentage aka capacity we're going to scale 5-100 to 0-100. */
 static int scale_capacity(struct bms_dev const *bms, int capacity)
 {
-	if (bms->soc_shutdown_offset > 0) {
+	if ((bms->soc_shutdown_offset > 0) && (bms->soc_shutdown_offset < 100)) {
 		if (capacity >= 100) {
 			return 100;
 		} else if (capacity >= bms->soc_shutdown_offset) {
-			return (((capacity - bms->soc_shutdown_offset) * 100) /
+			return DIV_ROUND_UP(((capacity - bms->soc_shutdown_offset) * 100),
 				(100 - bms->soc_shutdown_offset));
 		} else {
 			return 0;