On Mon, Oct 5, 2020 at 11:53 AM Tanwar, Rahul <rahul.tanwar@xxxxxxxxxxxxxxx> wrote: > On 3/10/2020 2:11 am, Andy Shevchenko wrote: > > On Fri, Oct 02, 2020 at 03:04:27PM +0800, Rahul Tanwar wrote: ... > >> + pvt_temp.config = temp_config; > >> + > >> + pvt_info[index++] = &pvt_temp; > >> + } > >> + > >> + if (pd_num) { > >> + ret = pvt_get_regmap(pdev, "pd", pvt); > >> + if (ret) > >> + return ret; > >> + } > >> + > >> + if (vm_num) { > >> + u32 num = vm_num; > >> + > >> + ret = pvt_get_regmap(pdev, "vm", pvt); > >> + if (ret) > >> + return ret; > >> + > >> + pvt->vm_idx = devm_kcalloc(dev, vm_num, sizeof(*pvt->vm_idx), > >> + GFP_KERNEL); > >> + if (!pvt->vm_idx) > >> + return -ENOMEM; > >> + for (i = 0; i < vm_num; i++) > >> + pvt->vm_idx[i] = i; > > What the point if you are replace them below in one case? > > > >> + ret = device_property_read_u8_array(dev, "intel,vm-map", > >> + pvt->vm_idx, vm_num); > >> + if (!ret) > > Misses {} and because of above > > > > if (ret) { > > for () ... > > } else { > > for () ... > > } > > > >> + for (i = 0; i < vm_num; i++) > >> + if (pvt->vm_idx[i] >= vm_num || > >> + pvt->vm_idx[i] == 0xff) { > >> + num = i; > >> + break; > >> + } > > Or looking in this, perhaps move the incremental for-loop here and start it > > with num which is 0. > > Not able to understand what exactly you are suggesting here. Presently > it is like below: > 1. Init vm_idx array with incremental values. > 2. Read array from device property. > 3. If success, figure out the last valid value and assign to num. > > Can you please elaborate and explain more clearly? Thanks. device_property_read_u8_array() effectively (partially) rewrites the vm_idx array. The code above is inefficient and not clear. My understanding based on the above is that half of the code may be dropped. So, clearer variant looks like this to me: ret = device_property_read_u8_array(dev, "intel,vm-map", pvt->vm_idx, vm_num); if (ret) { num = 0; } else { for (i = 0; i < vm_num; i++) { if (pvt->vm_idx[i] >= vm_num || pvt->vm_idx[i] == 0xff) break; } num = i; } for (i = num; i < vm_num; i++) pvt->vm_idx[i] = i; And all these require a good comment to describe why you are doing the trailing loop. -- With Best Regards, Andy Shevchenko