Skip to contentSkip to conversation

cxacru: Fix negative dB output

PATCH Applied Simon Arlott 2 participants 2 messages Apr 23, 2009 – Apr 27, 2009

Subsystems (5)
Networking Network drivers USB ATM +1 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxacru: Fix negative dB output

Values of dB between -0.99 and -0.01 will be output with the wrong sign. This converts the negative value to positive and outputs it with a "-" prefix.

---
 drivers/usb/atm/cxacru.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
drivers/usb/atm/cxacru.c +8 -2
index 6789089..56802d2 100644
@@ -227,8 +227,14 @@ static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf)
 
 static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
-					value / 100, abs(value) % 100);
+	if (likely(value >= 0)) {
+		return snprintf(buf, PAGE_SIZE, "%u.%02u\n",
+					value / 100, value % 100);
+	} else {
+		value = -value;
+		return snprintf(buf, PAGE_SIZE, "-%u.%02u\n",
+					value / 100, value % 100);
+	}
 }
 
 static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
Signature · 4 lines
1.6.2.2

-- 
Simon Arlott
maintainer Applied
#1 lore raw

From: Simon Arlott <[email protected]>
Date: Thu, 23 Apr 2009 18:19:02 +0100

Quoted 5 lines

Values of dB between -0.99 and -0.01 will be output with the wrong sign. This converts the negative value to positive and outputs it with a "-" prefix.

Applied to net-next-2.6, thanks.