linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Slawomir Stepien <sst@poczta.fm>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com, knaack.h@gmx.de,
	pmeerw@pmeerw.net, linux-iio@vger.kernel.org,
	gregkh@linuxfoundation.org
Subject: Re: [PATCH 2/3] staging: iio: adc: ad7280a: split ad7280_attr_init() to more functions
Date: Sun, 2 Dec 2018 15:47:01 +0000	[thread overview]
Message-ID: <20181202154701.160243b9@archlinux> (raw)
In-Reply-To: <20181202115830.20363-3-sst@poczta.fm>

On Sun,  2 Dec 2018 12:58:29 +0100
Slawomir Stepien <sst@poczta.fm> wrote:

> The ad7280_attr_init function has been split into more specific
> functions to increase the code readability.
> 
> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
> ---
>  drivers/staging/iio/adc/ad7280a.c | 79 +++++++++++++++++++------------
>  1 file changed, 48 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
> index a6b1bdd9f372..6faa85bf6f7e 100644
> --- a/drivers/staging/iio/adc/ad7280a.c
> +++ b/drivers/staging/iio/adc/ad7280a.c
> @@ -592,11 +592,49 @@ static int ad7280_channel_init(struct ad7280_state *st)
>  	return cnt + 1;
>  }
>  
> +static int ad7280_balance_switch_attr_init(struct ad7280_state *st, int cnt,
> +					   int dev, int ch)
> +{
> +	struct iio_dev_attr *attr = &st->iio_attr[cnt];

I would pass this in to the function (and the dev you need below) to make the
scope of what the function is doing more obvious.

> +
> +	attr->address = ad7280a_devaddr(dev) << 8 | ch;
> +	attr->dev_attr.attr.mode = 0644;
> +	attr->dev_attr.show = ad7280_show_balance_sw;
> +	attr->dev_attr.store = ad7280_store_balance_sw;
> +	attr->dev_attr.attr.name = devm_kasprintf(&st->spi->dev, GFP_KERNEL,
> +						  "in%d-in%d_balance_switch_en",
> +						  ch, ch + 1);
> +	if (!attr->dev_attr.attr.name)
> +		return -ENOMEM;
> +
> +	ad7280_attributes[cnt] = &attr->dev_attr.attr;
> +
> +	return 0;
> +}
> +
> +static int ad7280_balance_timer_attr_init(struct ad7280_state *st, int cnt,
> +					  int dev, int ch)
> +{
> +	struct iio_dev_attr *attr = &st->iio_attr[cnt];
> +
> +	attr->address = ad7280a_devaddr(dev) << 8 | (AD7280A_CB1_TIMER + ch);
> +	attr->dev_attr.attr.mode = 0644;
> +	attr->dev_attr.show = ad7280_show_balance_timer;
> +	attr->dev_attr.store = ad7280_store_balance_timer;
> +	attr->dev_attr.attr.name = devm_kasprintf(&st->spi->dev, GFP_KERNEL,
> +						  "in%d-in%d_balance_timer",
> +						  ch, ch + 1);
> +	if (!attr->dev_attr.attr.name)
> +		return -ENOMEM;
> +
> +	ad7280_attributes[cnt] = &attr->dev_attr.attr;
> +
> +	return 0;
> +}
> +
>  static int ad7280_attr_init(struct ad7280_state *st)
>  {
> -	int dev, ch, cnt;
> -	unsigned int index;
> -	struct iio_dev_attr *iio_attr;
> +	int dev, ch, cnt, ret;
>  
>  	st->iio_attr = devm_kcalloc(&st->spi->dev, 2, sizeof(*st->iio_attr) *
>  				    (st->slave_num + 1) * AD7280A_CELLS_PER_DEV,
> @@ -607,35 +645,14 @@ static int ad7280_attr_init(struct ad7280_state *st)
>  	for (dev = 0, cnt = 0; dev <= st->slave_num; dev++)
>  		for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6;
>  			ch++, cnt++) {
> -			iio_attr = &st->iio_attr[cnt];
> -			index = dev * AD7280A_CELLS_PER_DEV + ch;
> -			iio_attr->address = ad7280a_devaddr(dev) << 8 | ch;
> -			iio_attr->dev_attr.attr.mode = 0644;
> -			iio_attr->dev_attr.show = ad7280_show_balance_sw;
> -			iio_attr->dev_attr.store = ad7280_store_balance_sw;
> -			iio_attr->dev_attr.attr.name =
> -				devm_kasprintf(&st->spi->dev, GFP_KERNEL,
> -					       "in%d-in%d_balance_switch_en",
> -					       index, index + 1);
> -			if (!iio_attr->dev_attr.attr.name)
> -				return -ENOMEM;
> -
> -			ad7280_attributes[cnt] = &iio_attr->dev_attr.attr;
> +			ret = ad7280_balance_switch_attr_init(st, cnt, dev, ch);
> +			if (ret < 0)
> +				return ret;
> +
>  			cnt++;
> -			iio_attr = &st->iio_attr[cnt];
> -			iio_attr->address = ad7280a_devaddr(dev) << 8 |
> -				(AD7280A_CB1_TIMER + ch);
> -			iio_attr->dev_attr.attr.mode = 0644;
> -			iio_attr->dev_attr.show = ad7280_show_balance_timer;
> -			iio_attr->dev_attr.store = ad7280_store_balance_timer;
> -			iio_attr->dev_attr.attr.name =
> -				devm_kasprintf(&st->spi->dev, GFP_KERNEL,
> -					       "in%d-in%d_balance_timer",
> -					       index, index + 1);
> -			if (!iio_attr->dev_attr.attr.name)
> -				return -ENOMEM;
> -
> -			ad7280_attributes[cnt] = &iio_attr->dev_attr.attr;
> +			ret = ad7280_balance_timer_attr_init(st, cnt, dev, ch);
> +			if (ret < 0)
> +				return ret;
>  		}
>  
>  	ad7280_attributes[cnt] = NULL;


  reply	other threads:[~2018-12-02 15:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-02 11:58 [PATCH 0/3] staging: iio: adc: ad7280a: channel and attr init refactor Slawomir Stepien
2018-12-02 11:58 ` [PATCH 1/3] staging: iio: adc: ad7280a: split ad7280_channel_init() to more functions Slawomir Stepien
2018-12-02 15:45   ` Jonathan Cameron
2018-12-03 20:06     ` Slawomir Stepien
2018-12-04 12:43       ` Jonathan Cameron
2018-12-02 11:58 ` [PATCH 2/3] staging: iio: adc: ad7280a: split ad7280_attr_init() " Slawomir Stepien
2018-12-02 15:47   ` Jonathan Cameron [this message]
2018-12-02 11:58 ` [PATCH 3/3] staging: iio: adc: ad7280a: add braces to complex for loops Slawomir Stepien
2018-12-02 15:47   ` Jonathan Cameron

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=20181202154701.160243b9@archlinux \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=sst@poczta.fm \
    /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).