From: Dan Carpenter <error27@gmail.com>
To: kernel-janitors@vger.kernel.org
Subject: [patch 2/2] Staging: iio: unlock on error paths
Date: Tue, 10 Aug 2010 05:40:05 +0000 [thread overview]
Message-ID: <20100810054005.GP9031@bicker> (raw)
hmc5843_set_operating_mode() and set_range() didn't unlock on error
paths.
Also in hmc5843_set_operating_mode() it wasn't clear if we should return
"status", "error" or "count" so I changed it all to return "ret" and
then for consistency I did the same for set_range().
I also changed it to propagate the error codes from lower levels instead
of simply returning -EINVAL for everything.
Signed-off-by: Dan Carpenter <error27@gmail.com>
diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c
index 3d3bac4..7c52038 100644
--- a/drivers/staging/iio/magnetometer/hmc5843.c
+++ b/drivers/staging/iio/magnetometer/hmc5843.c
@@ -216,26 +216,28 @@ static ssize_t hmc5843_set_operating_mode(struct device *dev,
struct hmc5843_data *data = indio_dev->dev_data;
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
unsigned long operating_mode = 0;
- s32 status;
- int error;
+ ssize_t ret = 0;
+
mutex_lock(&data->lock);
- error = strict_strtoul(buf, 10, &operating_mode);
- if (error)
- return error;
+ ret = strict_strtoul(buf, 10, &operating_mode);
+ if (ret)
+ goto exit;
dev_dbg(dev, "set Conversion mode to %lu\n", operating_mode);
- if (operating_mode > MODE_SLEEP)
- return -EINVAL;
+ if (operating_mode > MODE_SLEEP) {
+ ret = -EINVAL;
+ goto exit;
+ }
- status = i2c_smbus_write_byte_data(client, this_attr->address,
+ ret = i2c_smbus_write_byte_data(client, this_attr->address,
operating_mode);
- if (status) {
- count = -EINVAL;
+ if (ret)
goto exit;
- }
data->operating_mode = operating_mode;
exit:
mutex_unlock(&data->lock);
+ if (!ret)
+ ret = count;
return count;
}
static IIO_DEVICE_ATTR(operating_mode,
@@ -434,24 +436,27 @@ static ssize_t set_range(struct device *dev,
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
struct hmc5843_data *data = indio_dev->dev_data;
unsigned long range = 0;
- int error;
+ ssize_t ret;
+
mutex_lock(&data->lock);
- error = strict_strtoul(buf, 10, &range);
- if (error)
- return error;
+ ret = strict_strtoul(buf, 10, &range);
+ if (ret)
+ goto exit;
dev_dbg(dev, "set range to %lu\n", range);
-
- if (range > RANGE_6_5)
- return -EINVAL;
+ if (range > RANGE_6_5) {
+ ret = -EINVAL;
+ goto exit;
+ }
data->range = range;
range = range << RANGE_GAIN_OFFSET;
- if (i2c_smbus_write_byte_data(client, this_attr->address, range))
- count = -EINVAL;
+ ret = i2c_smbus_write_byte_data(client, this_attr->address, range);
+exit:
mutex_unlock(&data->lock);
- return count;
-
+ if (!ret)
+ ret = count;
+ return ret;
}
static IIO_DEVICE_ATTR(magn_range,
S_IWUSR | S_IRUGO,
next reply other threads:[~2010-08-10 5:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-10 5:40 Dan Carpenter [this message]
2010-08-10 9:40 ` [patch 2/2] Staging: iio: unlock on error paths 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=20100810054005.GP9031@bicker \
--to=error27@gmail.com \
--cc=kernel-janitors@vger.kernel.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