On 12/30/20 2:41 PM, Jonathan Cameron wrote:
On Thu, 24 Dec 2020 03:19:21 +0000
Jyoti Bhayana <jbhay...@google.com> wrote:

+       /*
+        * The seconds field in the sensor interval in SCMI is 16 bits long
+        * Therefore seconds  = 1/Hz <= 0xFFFF. As floating point calculations 
are
+        * discouraged in the kernel driver code, to calculate the scale factor 
(sf)
+        * (1* 1000000 * sf)/uHz <= 0xFFFF. Therefore, sf <= (uHz * 
0xFFFF)/1000000
+        *  To calculate the multiplier,we convert the sf into char string  and
+        *  count the number of characters
+        */
+
+       mult = scnprintf(buf, 32, "%llu", ((u64)uHz * 0xFFFF) / UHZ_PER_HZ) - 1;
use sizeof(buf) instead of having 32 again.

Since this is just interested in the number of characters and not the string itself I believe it is possible to just call sprintf with NULL instead of a buffer. It will then still return the number of characters, but not print anything.

But maybe providing a ilog10() helper is the better approach.

Reply via email to