Re: [PATCH v3 09/19] hwmon: (mr75203) add VM active channel support

Andy Shevchenko
2022-08-31T11:48:17Z

On Tue, Aug 30, 2022 at 07:22:02PM +0000, Eliav Farber wrote:
> Add active channel support per voltage monitor.
> The number of active channels is read from the device-tree.
> When absent in device-tree, all channels are assumed to be used.
>
> This shall be useful to expose sysfs only for inputs that are connected
> to a voltage source.
>
> Setting number of active channels to 0, means that entire VM sensor is
> not used.

...

> +struct voltage_device {
> + u32 vm_map; /* Map channel number to VM index */
> + u32 ch_map; /* Map channel number to channel index */
> +};
> +
> +struct voltage_channels {
> + u32 total; /* Total number of channels in all VMs */
> + u8 max; /* Maximum number of channels among all VMs */
> +};

Why not convert them to kernel doc?

...

> + ret = device_property_read_u8_array(dev, "moortec,vm-active-channels",
> + vm_active_ch, vm_num);
> + if (ret) {
> + /*
> + * Incase vm-active-channels property is not defined,
> + * we assume each VM sensor has all of its channels
> + * active.
> + */
> + for (i = 0; i < vm_num; i++)
> + vm_active_ch[i] = ch_num;

NIH memset().

> + pvt->vm_channels.max = ch_num;
> + pvt->vm_channels.total = ch_num * vm_num;
> + } else {
> + for (i = 0; i < vm_num; i++) {
> + if (vm_active_ch[i] > ch_num) {
> + dev_err(dev, "invalid active channels: %u\n",
> + vm_active_ch[i]);
> + return -EINVAL;
> + }
> +
> + pvt->vm_channels.total += vm_active_ch[i];
> +
> + if (vm_active_ch[i] > pvt->vm_channels.max)
> + pvt->vm_channels.max = vm_active_ch[i];
> + }
> + }

...

> + k = 0;
> + for (i = 0; i < vm_num; i++)
> + for (j = 0; j < vm_active_ch[i]; j++) {
> + pvt->vd[k].vm_map = vm_idx[i];
> + pvt->vd[k].ch_map = j;

> + k++;

How is it different from moving this outside the inner loop as

k += vm_active_ch[i];

?

> + }

Missed outer {}.

--
With Best Regards,
Andy Shevchenko