devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Matthias Kaehlcke <mka@chromium.org>
Cc: Siddartha Mohanadoss <smohanad@codeaurora.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Rob Herring <robh+dt@kernel.org>,
	Douglas Anderson <dianders@chromium.org>
Subject: Re: [PATCH v2 2/2] iio: adc: Add QCOM SPMI PMIC5 ADC driver
Date: Sat, 30 Jun 2018 16:56:06 +0100	[thread overview]
Message-ID: <20180630165606.7a8a1a37@archlinux> (raw)
In-Reply-To: <20180629233357.GX129942@google.com>

On Fri, 29 Jun 2018 16:33:57 -0700
Matthias Kaehlcke <mka@chromium.org> wrote:

> Hi,
> 
> not a full review, just two nits I noticed when glacing over the first
> lines, and more importantly a regression wrt v1 I found while testing.
> 
> On Thu, Jun 28, 2018 at 11:30:37AM -0700, Siddartha Mohanadoss wrote:
> > This patch adds support for QCOM SPMI PMIC5 family
> > of ADC driver that supports hardware based offset and
> > gain compensation. The ADC peripheral can measure both
> > voltage and current channels whose input signal is
> > connected to the PMIC ADC AMUX.
> > 
> > The register set and configuration has been refreshed
> > compared to the prior QCOM PMIC ADC family. Register
> > ADC5 as part of the IIO framework.
> > 
> > Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
> > ---
> >  drivers/iio/adc/Kconfig            |  20 +
> >  drivers/iio/adc/Makefile           |   1 +
> >  drivers/iio/adc/qcom-spmi-adc5.c   | 878 +++++++++++++++++++++++++++++++++++++
> >  drivers/iio/adc/qcom-vadc-common.c | 230 +++++++++-
> >  drivers/iio/adc/qcom-vadc-common.h |  56 +++
> >  5 files changed, 1180 insertions(+), 5 deletions(-)
> >  create mode 100644 drivers/iio/adc/qcom-spmi-adc5.c
> > 
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index 28a9423..9533a82 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -56,6 +56,7 @@ obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
> >  obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
> >  obj-$(CONFIG_QCOM_VADC_COMMON) += qcom-vadc-common.o
> >  obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
> > +obj-$(CONFIG_QCOM_SPMI_ADC5) += qcom-spmi-adc5.o  
> 
> In general this file uses alphabetical ordering, though the QCOM
> drivers don't respect that. Still no reason to continue with the
> tradition, best insert this one before CONFIG_QCOM_SPMI_IADC.

I'd welcome a patch to tidy up the QCOM section of the file either
before or after this series is fine.

> 
> > diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c
> > new file mode 100644
> > index 0000000..75308df
> > --- /dev/null
> > +++ b/drivers/iio/adc/qcom-spmi-adc5.c
> > @@ -0,0 +1,878 @@
> > +/*
> > + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 and
> > + * only version 2 as published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + */
> > +
> > +#include <linux/bitops.h>
> > +#include <linux/completion.h>
> > +#include <linux/delay.h>
> > +#include <linux/err.h>
> > +#include <linux/iio/iio.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/kernel.h>
> > +#include <linux/math64.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/slab.h>
> > +#include <linux/log2.h>  
> 
> Move 'log2.h' to it's position in alphabetical order, i.e. after 'kernel.h'
> 
> > +static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node)
> > +{
> > +	const struct adc_channels *adc_chan;
> > +	struct iio_chan_spec *iio_chan;
> > +	struct adc5_channel_prop prop;
> > +	struct device_node *child;
> > +	unsigned int index = 0;
> > +	const struct of_device_id *id;
> > +	const struct adc_data *data;
> > +	int ret;
> > +
> > +	adc->nchannels = of_get_available_child_count(node);
> > +	if (!adc->nchannels)
> > +		return -EINVAL;
> > +
> > +	adc->iio_chans = devm_kcalloc(adc->dev, adc->nchannels,
> > +				       sizeof(*adc->iio_chans), GFP_KERNEL);
> > +	if (!adc->iio_chans)
> > +		return -ENOMEM;
> > +
> > +	adc->chan_props = devm_kcalloc(adc->dev, adc->nchannels,
> > +					sizeof(*adc->chan_props), GFP_KERNEL);
> > +	if (!adc->chan_props)
> > +		return -ENOMEM;
> > +
> > +	iio_chan = adc->iio_chans;
> > +	id = of_match_node(adc5_match_table, node);
> > +	if (id)
> > +		data = id->data;
> > +	else
> > +		data = &data_pmic5;
> > +	adc->data = data;
> > +
> > +	for_each_available_child_of_node(node, child) {
> > +		ret = adc5_get_dt_channel_data(adc, &prop, child, data);
> > +		if (ret) {
> > +			of_node_put(child);
> > +			return ret;
> > +		}
> > +
> > +		prop.scale_fn_type =
> > +			data->adc_chans[prop.channel].scale_fn_type;
> > +		adc->chan_props = &prop;  
> 
> I suppose this intends to address Jonathan's comment about array
> access vs pointer arithmetics on v1.
> 
> However it overwrites the address of the memory we allocated above
> with the address of the stack object 'prop'.
> 
> You probably want to create a chan_props pointer and change the
> assignment to:
> 
> *chan_props = prop;
> 
> > +		adc_chan = &data->adc_chans[prop.channel];
> > +
> > +		iio_chan->channel = prop.channel;
> > +		iio_chan->datasheet_name = prop.datasheet_name;
> > +		iio_chan->extend_name = prop.datasheet_name;
> > +		iio_chan->info_mask_separate = adc_chan->info_mask;
> > +		iio_chan->type = adc_chan->type;
> > +		iio_chan->address = index;
> > +		iio_chan++;
> > +		adc->chan_props++;  
> 
> And this changes the pointer in the adc object. I think you want to do:
> 
> chan_props++;
> 
> Cheers
> 
> Matthias
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2018-06-30 15:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-28 18:30 [PATCH v2 2/2] iio: adc: Add QCOM SPMI PMIC5 ADC driver Siddartha Mohanadoss
2018-06-29 23:33 ` Matthias Kaehlcke
2018-06-30 15:56   ` Jonathan Cameron [this message]
2018-07-11 21:12   ` smohanad
2018-06-30 16:06 ` Jonathan Cameron
2018-07-11 21:26   ` smohanad
2018-07-12 13:25     ` Jonathan Cameron
2018-07-25 23:19       ` smohanad

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=20180630165606.7a8a1a37@archlinux \
    --to=jic23@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=smohanad@codeaurora.org \
    /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).