linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: "Tanwar, Rahul" <rahul.tanwar@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	linux-hwmon@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	songjun.Wu@intel.com, cheol.yong.kim@intel.com,
	qi-ming.wu@intel.com, rtanwar@maxlinear.com
Subject: Re: [PATCH v4 2/2] Add hardware monitoring driver for Moortec MR75203 PVT controller
Date: Mon, 5 Oct 2020 12:06:48 +0300	[thread overview]
Message-ID: <CAHp75VcHk0qZ_pFAvZLC4+8=r7E=cqe3J+enB3UWD9X1KQQ4Ng@mail.gmail.com> (raw)
In-Reply-To: <f224391a-2e51-ec37-7045-4a16f04b5384@linux.intel.com>

On Mon, Oct 5, 2020 at 11:53 AM Tanwar, Rahul
<rahul.tanwar@linux.intel.com> 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

      reply	other threads:[~2020-10-05  9:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02  7:04 [PATCH v4 0/2] Add hwmon driver for Moortec PVT controller Rahul Tanwar
2020-10-02  7:04 ` [PATCH v4 1/2] Add DT bindings schema for " Rahul Tanwar
2020-10-02  7:04 ` [PATCH v4 2/2] Add hardware monitoring driver for Moortec MR75203 " Rahul Tanwar
2020-10-02 14:45   ` Guenter Roeck
2020-10-02 18:11   ` Andy Shevchenko
2020-10-02 18:13     ` Andy Shevchenko
2020-10-05  8:50     ` Tanwar, Rahul
2020-10-05  9:06       ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHp75VcHk0qZ_pFAvZLC4+8=r7E=cqe3J+enB3UWD9X1KQQ4Ng@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=cheol.yong.kim@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=p.zabel@pengutronix.de \
    --cc=qi-ming.wu@intel.com \
    --cc=rahul.tanwar@linux.intel.com \
    --cc=robh+dt@kernel.org \
    --cc=rtanwar@maxlinear.com \
    --cc=songjun.Wu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).