* [PATCH] iio/adc/nau7802: Improve unlocking of a mutex in nau7802_read_raw()
@ 2018-03-13 19:56 SF Markus Elfring
2018-03-18 10:22 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2018-03-13 19:56 UTC (permalink / raw)
To: linux-iio, Hartmut Knaack, Jonathan Cameron, Lars-Peter Clausen,
Peter Meerwald-Stadler
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 13 Mar 2018 20:52:26 +0100
* Add a jump target so that a call of the function "mutex_unlock" is stored
only once in this function implementation.
* Replace two calls by goto statements.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/iio/adc/nau7802.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
index 8997e74a8847..68d06a492760 100644
--- a/drivers/iio/adc/nau7802.c
+++ b/drivers/iio/adc/nau7802.c
@@ -303,10 +303,8 @@ static int nau7802_read_raw(struct iio_dev *indio_dev,
* - Channel 2 is value 1 in the CHS register
*/
ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL2);
- if (ret < 0) {
- mutex_unlock(&st->lock);
- return ret;
- }
+ if (ret < 0)
+ goto unlock;
if (((ret & NAU7802_CTRL2_CHS_BIT) && !chan->channel) ||
(!(ret & NAU7802_CTRL2_CHS_BIT) &&
@@ -316,18 +314,15 @@ static int nau7802_read_raw(struct iio_dev *indio_dev,
NAU7802_REG_CTRL2,
NAU7802_CTRL2_CHS(chan->channel) |
NAU7802_CTRL2_CRS(st->sample_rate));
-
- if (ret < 0) {
- mutex_unlock(&st->lock);
- return ret;
- }
+ if (ret < 0)
+ goto unlock;
}
if (st->client->irq)
ret = nau7802_read_irq(indio_dev, chan, val);
else
ret = nau7802_read_poll(indio_dev, chan, val);
-
+unlock:
mutex_unlock(&st->lock);
return ret;
--
2.16.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio/adc/nau7802: Improve unlocking of a mutex in nau7802_read_raw()
2018-03-13 19:56 [PATCH] iio/adc/nau7802: Improve unlocking of a mutex in nau7802_read_raw() SF Markus Elfring
@ 2018-03-18 10:22 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-03-18 10:22 UTC (permalink / raw)
To: SF Markus Elfring
Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, LKML, kernel-janitors
On Tue, 13 Mar 2018 20:56:25 +0100
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 13 Mar 2018 20:52:26 +0100
>
> * Add a jump target so that a call of the function "mutex_unlock" is stored
> only once in this function implementation.
>
> * Replace two calls by goto statements.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Similar to other cases, this non obvious error handling flow rather implies
that this block of code might work better as a utility function called from
the case statement.
> ---
> drivers/iio/adc/nau7802.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
> index 8997e74a8847..68d06a492760 100644
> --- a/drivers/iio/adc/nau7802.c
> +++ b/drivers/iio/adc/nau7802.c
> @@ -303,10 +303,8 @@ static int nau7802_read_raw(struct iio_dev *indio_dev,
> * - Channel 2 is value 1 in the CHS register
> */
> ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL2);
> - if (ret < 0) {
> - mutex_unlock(&st->lock);
> - return ret;
> - }
> + if (ret < 0)
> + goto unlock;
>
> if (((ret & NAU7802_CTRL2_CHS_BIT) && !chan->channel) ||
> (!(ret & NAU7802_CTRL2_CHS_BIT) &&
> @@ -316,18 +314,15 @@ static int nau7802_read_raw(struct iio_dev *indio_dev,
> NAU7802_REG_CTRL2,
> NAU7802_CTRL2_CHS(chan->channel) |
> NAU7802_CTRL2_CRS(st->sample_rate));
> -
> - if (ret < 0) {
> - mutex_unlock(&st->lock);
> - return ret;
> - }
> + if (ret < 0)
> + goto unlock;
> }
>
> if (st->client->irq)
> ret = nau7802_read_irq(indio_dev, chan, val);
> else
> ret = nau7802_read_poll(indio_dev, chan, val);
> -
> +unlock:
> mutex_unlock(&st->lock);
blank line before simple returns. It isn't a major enough part to be
worth the noise of adding them to existing code, but there is no reason
to take them out!
> return ret;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-18 10:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-13 19:56 [PATCH] iio/adc/nau7802: Improve unlocking of a mutex in nau7802_read_raw() SF Markus Elfring
2018-03-18 10:22 ` Jonathan Cameron
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).