linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alison Schofield <amsfield22@gmail.com>
To: jic23@kernel.org
Cc: mranostay@gmail.com, knaack.h@gmx.de, lars@metafoo.de,
	pmeerw@pmeerw.net, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iio: humidity: hdc100x: move lock on config updates to single function
Date: Fri, 15 Jul 2016 22:23:42 -0700	[thread overview]
Message-ID: <20160716052341.GA1872@d830.WORKGROUP> (raw)
In-Reply-To: <634a2c91a91bdbbe3e79872fffb4fbf2d804a59e.1468180067.git.amsfield22@gmail.com>

On Sun, Jul 10, 2016 at 02:30:01PM -0700, Alison Schofield wrote:
> Move the config register locking to the config update function.  This
> continues to protect updates to heater and integration times. It puts
> the lock in one place, right where it needs to occur.

Since creating this patch, I've learned that it is a design choice in
kernel drivers to keep the locking at a higher level - ie point of entry.
This patch goes against that design, so, I get that it's not do-able.

alisons

> 
> Add the checkpatch required comment on this lock declaration.
> 
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
> ---
>  drivers/iio/humidity/hdc100x.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
> index a03832a..ad5a12a 100644
> --- a/drivers/iio/humidity/hdc100x.c
> +++ b/drivers/iio/humidity/hdc100x.c
> @@ -31,7 +31,7 @@
>  
>  struct hdc100x_data {
>  	struct i2c_client *client;
> -	struct mutex lock;
> +	struct mutex lock;  /* protect config updates & raw measurements */
>  	u16 config;
>  
>  	/* integration time of the sensor */
> @@ -108,10 +108,12 @@ static int hdc100x_update_config(struct hdc100x_data *data, int mask, int val)
>  	int tmp = (~mask & data->config) | val;
>  	int ret;
>  
> +	mutex_lock(&data->lock);
>  	ret = i2c_smbus_write_word_swapped(data->client,
>  						HDC100X_REG_CONFIG, tmp);
>  	if (!ret)
>  		data->config = tmp;
> +	mutex_unlock(&data->lock);
>  
>  	return ret;
>  }
> @@ -234,26 +236,20 @@ static int hdc100x_write_raw(struct iio_dev *indio_dev,
>  			     int val, int val2, long mask)
>  {
>  	struct hdc100x_data *data = iio_priv(indio_dev);
> -	int ret = -EINVAL;
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_INT_TIME:
>  		if (val != 0)
>  			return -EINVAL;
>  
> -		mutex_lock(&data->lock);
> -		ret = hdc100x_set_it_time(data, chan->address, val2);
> -		mutex_unlock(&data->lock);
> -		return ret;
> +		return hdc100x_set_it_time(data, chan->address, val2);
> +
>  	case IIO_CHAN_INFO_RAW:
>  		if (chan->type != IIO_CURRENT || val2 != 0)
>  			return -EINVAL;
>  
> -		mutex_lock(&data->lock);
> -		ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN,
> +		return hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN,
>  					val ? HDC100X_REG_CONFIG_HEATER_EN : 0);
> -		mutex_unlock(&data->lock);
> -		return ret;
>  	default:
>  		return -EINVAL;
>  	}
> -- 
> 2.1.4
> 

  reply	other threads:[~2016-07-16  5:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-10 21:29 [PATCH 0/2] iio: humidity: hdc100x: update driver locking Alison Schofield
2016-07-10 21:30 ` [PATCH 1/2] iio: humidity: hdc100x: move lock on config updates to single function Alison Schofield
2016-07-16  5:23   ` Alison Schofield [this message]
2016-07-10 21:31 ` [PATCH 2/2] iio: humidity: hdc100x: remove lock on heater configuration read Alison Schofield

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=20160716052341.GA1872@d830.WORKGROUP \
    --to=amsfield22@gmail.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=pmeerw@pmeerw.net \
    /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).