lkml.org 
[lkml]   [2022]   [Sep]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 06/21] hwmon: (mr75203) fix multi-channel voltage reading
On Tue, Sep 06, 2022 at 08:33:41AM +0000, Eliav Farber wrote:
> Fix voltage allocation and reading to support all channels in all VMs.
> Prior to this change allocation and reading were done only for the first
> channel in each VM.
> This change counts the total number of channels for allocation, and takes
> into account the channel offset when reading the sample data register.

...

> + total_ch = ch_num * vm_num;
> + in_config = devm_kcalloc(dev, total_ch + 1,
> sizeof(*in_config), GFP_KERNEL);

Strictly speaking this should be `size_add(size_mul(...) ...)` construction
from overflow.h.

total_ch = size_mul(ch_num, vm_num);
in_config = devm_kcalloc(dev, size_add(total_ch, 1),
sizeof(*in_config), GFP_KERNEL);

Alternatively before doing all these, add a check

if (array3_size(ch_num, vm_num, sizeof(*in_config)) < SIZE_MAX - sizeof(*in_config))
return -EOVERFLOW;

But this is a bit monstrous. Seems like the above looks and feels better.

Also for backporting purposes perhaps it's fine to do without using those macro
helpers.

> if (!in_config)
> return -ENOMEM;


--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2022-09-06 16:58    [W:0.212 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site