Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1535557 > unrolled thread
| Started by | Brian Masney <masneyb@onstation.org> |
|---|---|
| First post | 2016-12-04 03:30 +0100 |
| Last post | 2016-12-04 12:10 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 01/19] staging: iio: isl29028: remove nested if statements Brian Masney <masneyb@onstation.org> - 2016-12-04 03:30 +0100
Re: [PATCH 01/19] staging: iio: isl29028: remove nested if statements Jonathan Cameron <jic23@kernel.org> - 2016-12-04 12:10 +0100
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-12-04 03:30 +0100 |
| Subject | [PATCH 01/19] staging: iio: isl29028: remove nested if statements |
| Message-ID | <sKuIV-194-5@gated-at.bofh.it> |
There are two callers to the function isl29028_set_als_ir_mode() and
both instances use a nested if statement to only change the chip state
if it is not in the proper mode. This patch moves this check into the
isl29028_set_als_ir_mode() function to remove the nested if
statements.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/isl29028.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c
index aa413e5..4e35d00 100644
--- a/drivers/staging/iio/light/isl29028.c
+++ b/drivers/staging/iio/light/isl29028.c
@@ -124,6 +124,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
{
int ret = 0;
+ if (chip->als_ir_mode == mode)
+ return 0;
+
switch (mode) {
case ISL29028_MODE_ALS:
ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
@@ -160,6 +163,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
/* Need to wait for conversion time if ALS/IR mode enabled */
mdelay(ISL29028_CONV_TIME_MS);
+
+ chip->als_ir_mode = mode;
+
return 0;
}
@@ -223,14 +229,10 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
int ret;
int als_ir_data;
- if (chip->als_ir_mode != ISL29028_MODE_ALS) {
- ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
- if (ret < 0) {
- dev_err(dev,
- "Error in enabling ALS mode err %d\n", ret);
- return ret;
- }
- chip->als_ir_mode = ISL29028_MODE_ALS;
+ ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
+ if (ret < 0) {
+ dev_err(dev, "Error in enabling ALS mode err %d\n", ret);
+ return ret;
}
ret = isl29028_read_als_ir(chip, &als_ir_data);
@@ -256,14 +258,10 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
struct device *dev = regmap_get_device(chip->regmap);
int ret;
- if (chip->als_ir_mode != ISL29028_MODE_IR) {
- ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
- if (ret < 0) {
- dev_err(dev,
- "Error in enabling IR mode err %d\n", ret);
- return ret;
- }
- chip->als_ir_mode = ISL29028_MODE_IR;
+ ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
+ if (ret < 0) {
+ dev_err(dev, "Error in enabling IR mode err %d\n", ret);
+ return ret;
}
return isl29028_read_als_ir(chip, ir_data);
}
--
2.7.4
[toc] | [next] | [standalone]
| From | Jonathan Cameron <jic23@kernel.org> |
|---|---|
| Date | 2016-12-04 12:10 +0100 |
| Message-ID | <sKCQ9-6pF-5@gated-at.bofh.it> |
| In reply to | #1535557 |
On 04/12/16 02:19, Brian Masney wrote:
> There are two callers to the function isl29028_set_als_ir_mode() and
> both instances use a nested if statement to only change the chip state
> if it is not in the proper mode. This patch moves this check into the
> isl29028_set_als_ir_mode() function to remove the nested if
> statements.
>
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Sensible little clean up.
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it. (If I can get a push out in the last 3 mins
of my free 15 of wifi on this train!)
Thanks,
Jonathan
> ---
> drivers/staging/iio/light/isl29028.c | 30 ++++++++++++++----------------
> 1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c
> index aa413e5..4e35d00 100644
> --- a/drivers/staging/iio/light/isl29028.c
> +++ b/drivers/staging/iio/light/isl29028.c
> @@ -124,6 +124,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
> {
> int ret = 0;
>
> + if (chip->als_ir_mode == mode)
> + return 0;
> +
> switch (mode) {
> case ISL29028_MODE_ALS:
> ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
> @@ -160,6 +163,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
>
> /* Need to wait for conversion time if ALS/IR mode enabled */
> mdelay(ISL29028_CONV_TIME_MS);
> +
> + chip->als_ir_mode = mode;
> +
> return 0;
> }
>
> @@ -223,14 +229,10 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
> int ret;
> int als_ir_data;
>
> - if (chip->als_ir_mode != ISL29028_MODE_ALS) {
> - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
> - if (ret < 0) {
> - dev_err(dev,
> - "Error in enabling ALS mode err %d\n", ret);
> - return ret;
> - }
> - chip->als_ir_mode = ISL29028_MODE_ALS;
> + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
> + if (ret < 0) {
> + dev_err(dev, "Error in enabling ALS mode err %d\n", ret);
> + return ret;
> }
>
> ret = isl29028_read_als_ir(chip, &als_ir_data);
> @@ -256,14 +258,10 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
> struct device *dev = regmap_get_device(chip->regmap);
> int ret;
>
> - if (chip->als_ir_mode != ISL29028_MODE_IR) {
> - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
> - if (ret < 0) {
> - dev_err(dev,
> - "Error in enabling IR mode err %d\n", ret);
> - return ret;
> - }
> - chip->als_ir_mode = ISL29028_MODE_IR;
> + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
> + if (ret < 0) {
> + dev_err(dev, "Error in enabling IR mode err %d\n", ret);
> + return ret;
> }
> return isl29028_read_als_ir(chip, ir_data);
> }
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web