* [PATCH] iio/proximity/srf08: Improve unlocking of a mutex in srf08_read_ranging()
@ 2017-10-26 15:00 SF Markus Elfring
2017-10-26 16:18 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2017-10-26 15:00 UTC (permalink / raw)
To: linux-iio, Andreas Klinger, Hartmut Knaack, Jonathan Cameron,
Lars-Peter Clausen, Peter Meerwald-Stadler
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 26 Oct 2017 16:51:08 +0200
Add a jump target so that a call of the function "mutex_unlock" is stored
only once at the end of 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/proximity/srf08.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c
index f2bf783f829a..85957550195b 100644
--- a/drivers/iio/proximity/srf08.c
+++ b/drivers/iio/proximity/srf08.c
@@ -135,8 +135,7 @@ static int srf08_read_ranging(struct srf08_data *data)
SRF08_WRITE_COMMAND, SRF08_CMD_RANGING_CM);
if (ret < 0) {
dev_err(&client->dev, "write command - err: %d\n", ret);
- mutex_unlock(&data->lock);
- return ret;
+ goto unlock;
}
/*
@@ -163,20 +162,17 @@ static int srf08_read_ranging(struct srf08_data *data)
if (ret >= 255 || ret <= 0) {
dev_err(&client->dev, "device not ready\n");
- mutex_unlock(&data->lock);
- return -EIO;
+ ret = -EIO;
+ goto unlock;
}
ret = i2c_smbus_read_word_swapped(data->client,
SRF08_READ_ECHO_1_HIGH);
- if (ret < 0) {
+ if (ret < 0)
dev_err(&client->dev, "cannot read distance: ret=%d\n", ret);
- mutex_unlock(&data->lock);
- return ret;
- }
+unlock:
mutex_unlock(&data->lock);
-
return ret;
}
--
2.14.3
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] iio/proximity/srf08: Improve unlocking of a mutex in srf08_read_ranging()
2017-10-26 15:00 [PATCH] iio/proximity/srf08: Improve unlocking of a mutex in srf08_read_ranging() SF Markus Elfring
@ 2017-10-26 16:18 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2017-10-26 16:18 UTC (permalink / raw)
To: SF Markus Elfring
Cc: linux-iio, Andreas Klinger, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, LKML, kernel-janitors
On Thu, 26 Oct 2017 17:00:07 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 26 Oct 2017 16:51:08 +0200
>
> Add a jump target so that a call of the function "mutex_unlock" is stored
> only once at the end of 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>
This simple case is a reasonable change. A few minor points though.
Firstly, for a given subsystem please look at other patches to identify
the standard formatting used in patch titles.
Secondly make sure you don't make unconnected changes. Here there
is a whitespace change that should not be here.
Jonathan
> ---
> drivers/iio/proximity/srf08.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c
> index f2bf783f829a..85957550195b 100644
> --- a/drivers/iio/proximity/srf08.c
> +++ b/drivers/iio/proximity/srf08.c
> @@ -135,8 +135,7 @@ static int srf08_read_ranging(struct srf08_data *data)
> SRF08_WRITE_COMMAND, SRF08_CMD_RANGING_CM);
> if (ret < 0) {
> dev_err(&client->dev, "write command - err: %d\n", ret);
> - mutex_unlock(&data->lock);
> - return ret;
> + goto unlock;
> }
>
> /*
> @@ -163,20 +162,17 @@ static int srf08_read_ranging(struct srf08_data *data)
>
> if (ret >= 255 || ret <= 0) {
> dev_err(&client->dev, "device not ready\n");
> - mutex_unlock(&data->lock);
> - return -EIO;
> + ret = -EIO;
> + goto unlock;
> }
>
> ret = i2c_smbus_read_word_swapped(data->client,
> SRF08_READ_ECHO_1_HIGH);
> - if (ret < 0) {
> + if (ret < 0)
> dev_err(&client->dev, "cannot read distance: ret=%d\n", ret);
> - mutex_unlock(&data->lock);
> - return ret;
> - }
>
> +unlock:
> mutex_unlock(&data->lock);
> -
Please don't make unconnected white space changes.
> return ret;
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-26 16:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-26 15:00 [PATCH] iio/proximity/srf08: Improve unlocking of a mutex in srf08_read_ranging() SF Markus Elfring
2017-10-26 16:18 ` 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).