acct: fix accuracy loss for input value of encode_comp_t()
authorZheng Yejian <zhengyejian1@huawei.com>
Sat, 15 May 2021 14:06:30 +0000 (22:06 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 1 Dec 2022 00:13:18 +0000 (16:13 -0800)
commit457139f16ae15d86df1e491fc45a9ea56def57b5
treeee2b4f536355921a5a6dfbcdab9029e6ea6bfa69
parentde985c109096b236d43e98da0c65376bf3bc24fb
acct: fix accuracy loss for input value of encode_comp_t()

Patch series "Fix encode_comp_t()".

Type conversion in encode_comp_t() may look a bit problematic.

This patch (of 2):

See calculation of ac_{u,s}time in fill_ac():
  > ac->ac_utime = encode_comp_t(nsec_to_AHZ(pacct->ac_utime));
  > ac->ac_stime = encode_comp_t(nsec_to_AHZ(pacct->ac_stime));

Return value of nsec_to_AHZ() is always type of 'u64', but it is handled
as type of 'unsigned long' in encode_comp_t, and accuracy loss would
happen on 32-bit platform when 'unsigned long' value is 32-bit-width.

So 'u64' value of encode_comp_t() may look better.

Link: https://lkml.kernel.org/r/20210515140631.369106-1-zhengyejian1@huawei.com
Link: https://lkml.kernel.org/r/20210515140631.369106-2-zhengyejian1@huawei.com
Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Randy Dunlap <rdunlap@infradead.org> # build-tested
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zhang Jinhao <zhangjinhao2@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/acct.c