Skip to contentSkip to conversation

patch "tools: iio: iio_utils: fix digit calculation" added to char-misc-linus

PATCH [email protected] 1 participant 1 message Oct 23, 2022

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

tools: iio: iio_utils: fix digit calculation

to my char-misc git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
in the char-misc-linus branch.

The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)

The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.

If you have any questions about this process, please let me know.

From 72b2aa38191bcba28389b0e20bf6b4f15017ff2b Mon Sep 17 00:00:00 2001
From: Matti Vaittinen <[email protected]>
Date: Thu, 13 Oct 2022 15:04:04 +0300
Subject: tools: iio: iio_utils: fix digit calculation

The iio_utils uses a digit calculation in order to know length of the file name containing a buffer number. The digit calculation does not work for number 0.

This leads to allocation of one character too small buffer for the file-name when file name contains value '0'. (Eg. buffer0).

Fix digit calculation by returning one digit to be present for number '0'.

Fixes 096f9b862e60 ("tools:iio:iio_utils: implement digit calculation")
---
 tools/iio/iio_utils.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/iio/iio_utils.c +4 -0
index aadee6d34c74..8d35893b2fa8 100644
@@ -547,6 +547,10 @@ static int calc_digits(int num)
 {
 	int count = 0;
 
+	/* It takes a digit to represent zero */
+	if (!num)
+		return 1;
+
 	while (num != 0) {
 		num /= 10;
 		count++;
Signature · 1 line
2.38.1