Skip to contentSkip to conversation

bmc150-accel fixes and cleanup

PATCH Applied Hartmut Knaack 3 participants 10 messages Jun 15, 2015 – Jun 21, 2015 IIO

lore
Share & tools
lore
#0 lore raw

cover bmc150-accel fixes and cleanup

This series adresses some issues that got introduced this year, as well as some that checkpatch.pl pointed out.

Hartmut Knaack (3):
iio:accel:bmc150-accel: fix counting direction iio:accel:bmc150-accel: make use of mask definition iio:accel:bmc150-accel: code style cleanup

 drivers/iio/accel/bmc150-accel.c | 95 +++++++++++++++++++++-------------------
 1 file changed, 51 insertions(+), 44 deletions(-)
Signature · 1 line
2.3.6
#1 lore raw

PATCH 1/3 iio:accel:bmc150-accel: fix counting direction

In bmc150_accel_unregister_triggers() triggers should be unregistered in reverse order of registration. Trigger registration starts with number 0, counting up. In consequence, trigger number needs to be count down here.

---
 drivers/iio/accel/bmc150-accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bmc150-accel.c +1 -1
index 4e70f51..cc5a357 100644
@@ -1464,7 +1464,7 @@ static void bmc150_accel_unregister_triggers(struct bmc150_accel_data *data,
 {
 	int i;
 
-	for (i = from; i >= 0; i++) {
+	for (i = from; i >= 0; i--) {
 		if (data->triggers[i].indio_trig) {
 			iio_trigger_unregister(data->triggers[i].indio_trig);
 			data->triggers[i].indio_trig = NULL;
Signature · 1 line
2.3.6
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] iio:accel:bmc150-accel: fix counting direction

Quoted 6 lines · Hartmut Knaack

In bmc150_accel_unregister_triggers() triggers should be unregistered in reverse order of registration. Trigger registration starts with number 0, counting up. In consequence, trigger number needs to be count down here.

Quoted 20 lines
---
 drivers/iio/accel/bmc150-accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bmc150-accel.c +1 -2
index 4e70f51..cc5a357 100644
@@ -1464,7 +1464,7 @@ static void bmc150_accel_unregister_triggers(struct bmc150_accel_data *data,
 {
        int i;
 
-       for (i = from; i >= 0; i++) {
+       for (i = from; i >= 0; i--) {
                if (data->triggers[i].indio_trig) {
                        iio_trigger_unregister(data->triggers[i].indio_trig);
                        data->triggers[i].indio_trig = NULL;
--

2.3.6

maintainer Applied
#3 lore raw

Re: [PATCH 1/3] iio:accel:bmc150-accel: fix counting direction

Quoted 9 lines · Octavian Purdila
Quoted 6 lines · Hartmut Knaack

In bmc150_accel_unregister_triggers() triggers should be unregistered in reverse order of registration. Trigger registration starts with number 0, counting up. In consequence, trigger number needs to be count down here.

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 14 lines
Quoted 14 lines

---
 drivers/iio/accel/bmc150-accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bmc150-accel.c +0 -0
index 4e70f51..cc5a357 100644
@@ -1464,7 +1464,7 @@ static void bmc150_accel_unregister_triggers(struct bmc150_accel_data *data,
 {
        int i;
 
Quoted 13 lines
Quoted 8 lines
drivers/iio/accel/bmc150-accel.c +1 -2
-       for (i = from; i >= 0; i++) {
+       for (i = from; i >= 0; i--) {
                if (data->triggers[i].indio_trig) {
                        iio_trigger_unregister(data->triggers[i].indio_trig);
                        data->triggers[i].indio_trig = NULL;
--

2.3.6

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in

#4 lore raw

PATCH 2/3 iio:accel:bmc150-accel: make use of mask definition

In reply to Hartmut Knaack

BMC150_ACCEL_SLOPE_THRES_MASK was defined some time ago, but its 'magic' value got used instead in bmc150_accel_write_event(). Make use of it for improved readability.

---
 drivers/iio/accel/bmc150-accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bmc150-accel.c +1 -1
index cc5a357..36a9cd5 100644
@@ -776,7 +776,7 @@ static int bmc150_accel_write_event(struct iio_dev *indio_dev,
 
 	switch (info) {
 	case IIO_EV_INFO_VALUE:
-		data->slope_thres = val & 0xFF;
+		data->slope_thres = val & BMC150_ACCEL_SLOPE_THRES_MASK;
 		break;
 	case IIO_EV_INFO_PERIOD:
 		data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK;
Signature · 1 line
2.3.6
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] iio:accel:bmc150-accel: make use of mask definition

Quoted 5 lines · Hartmut Knaack

BMC150_ACCEL_SLOPE_THRES_MASK was defined some time ago, but its 'magic' value got used instead in bmc150_accel_write_event(). Make use of it for improved readability.

Quoted 24 lines
---
 drivers/iio/accel/bmc150-accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bmc150-accel.c +1 -2
index cc5a357..36a9cd5 100644
@@ -776,7 +776,7 @@ static int bmc150_accel_write_event(struct iio_dev *indio_dev,
 
        switch (info) {
        case IIO_EV_INFO_VALUE:
-               data->slope_thres = val & 0xFF;
+               data->slope_thres = val & BMC150_ACCEL_SLOPE_THRES_MASK;
                break;
        case IIO_EV_INFO_PERIOD:
                data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK;
--

2.3.6

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#6 lore raw

Re: [PATCH 2/3] iio:accel:bmc150-accel: make use of mask definition

Quoted 8 lines · Octavian Purdila
Quoted 5 lines · Hartmut Knaack

BMC150_ACCEL_SLOPE_THRES_MASK was defined some time ago, but its 'magic' value got used instead in bmc150_accel_write_event(). Make use of it for improved readability.

Applied to the togreg branch of iio.git - initially pushed out as testing etc etc.

Quoted 21 lines
Quoted 21 lines
---
 drivers/iio/accel/bmc150-accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bmc150-accel.c +1 -2
index cc5a357..36a9cd5 100644
@@ -776,7 +776,7 @@ static int bmc150_accel_write_event(struct iio_dev *indio_dev,
 
        switch (info) {
        case IIO_EV_INFO_VALUE:
-               data->slope_thres = val & 0xFF;
+               data->slope_thres = val & BMC150_ACCEL_SLOPE_THRES_MASK;
                break;
        case IIO_EV_INFO_PERIOD:
                data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK;
--

2.3.6

Quoted 9 lines
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in

#7 lore raw

PATCH 3/3 iio:accel:bmc150-accel: code style cleanup

In reply to Hartmut Knaack

Apply the following coding style changes as indicated by checkpatch.pl in strict mode:
- Please don't use multiple blank lines
- braces {} should be used on all arms of this statement (if/else)
- Alignment should match open parenthesis
- Please don't use multiple blank lines
- Blank lines aren't necessary after an open brace '{'
- Missing a blank line after declarations
- No space is necessary after a cast

Also wrap/consolidate error messages to fit 80 characters per line and rework a comment.

---
 drivers/iio/accel/bmc150-accel.c | 91 +++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 42 deletions(-)
drivers/iio/accel/bmc150-accel.c +49 -42
index 36a9cd5..e84e2a1 100644
@@ -241,7 +241,6 @@ static const struct {
 				       {500000, BMC150_ACCEL_SLEEP_500_MS},
 				       {1000000, BMC150_ACCEL_SLEEP_1_SEC} };
 
-
 static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
 				 enum bmc150_power_modes mode,
 				 int dur_us)
@@ -259,8 +258,9 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
 				dur_val =
 				bmc150_accel_sleep_value_table[i].reg_value;
 		}
-	} else
+	} else {
 		dur_val = 0;
+	}
 
 	if (dur_val < 0)
 		return -EINVAL;
@@ -288,7 +288,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
 
 	for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
 		if (bmc150_accel_samp_freq_table[i].val == val &&
-				bmc150_accel_samp_freq_table[i].val2 == val2) {
+		    bmc150_accel_samp_freq_table[i].val2 == val2) {
 			ret = i2c_smbus_write_byte_data(
 				data->client,
 				BMC150_ACCEL_REG_PMU_BW,
@@ -351,8 +351,7 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 
 	ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
 	if (ret < 0) {
-		dev_err(&data->client->dev,
-			"Error: Reading chip id\n");
+		dev_err(&data->client->dev, "Error: Reading chip id\n");
 		return ret;
 	}
 
@@ -376,8 +375,7 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 					BMC150_ACCEL_REG_PMU_RANGE,
 					BMC150_ACCEL_DEF_RANGE_4G);
 	if (ret < 0) {
-		dev_err(&data->client->dev,
-					"Error writing reg_pmu_range\n");
+		dev_err(&data->client->dev, "Error writing reg_pmu_range\n");
 		return ret;
 	}
 
@@ -437,12 +435,13 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
 {
 	int ret;
 
-	if (on)
+	if (on) {
 		ret = pm_runtime_get_sync(&data->client->dev);
-	else {
+	} else {
 		pm_runtime_mark_last_busy(&data->client->dev);
 		ret = pm_runtime_put_autosuspend(&data->client->dev);
 	}
+
 	if (ret < 0) {
 		dev_err(&data->client->dev,
 			"Failed: bmc150_accel_set_power_state for %d\n", on);
@@ -514,13 +513,13 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
 	}
 
 	/*
-	 * We will expect the enable and disable to do operation in
-	 * in reverse order. This will happen here anyway as our
-	 * resume operation uses sync mode runtime pm calls, the
-	 * suspend operation will be delayed by autosuspend delay
-	 * So the disable operation will still happen in reverse of
-	 * enable operation. When runtime pm is disabled the mode
-	 * is always on so sequence doesn't matter
+	 * We will expect the enable and disable to do operation in reverse
+	 * order. This will happen here anyway, as our resume operation uses
+	 * sync mode runtime pm calls. The suspend operation will be delayed
+	 * by autosuspend delay.
+	 * So the disable operation will still happen in reverse order of
+	 * enable operation. When runtime pm is disabled the mode is always on,
+	 * so sequence doesn't matter.
 	 */
 	ret = bmc150_accel_set_power_state(data, state);
 	if (ret < 0)
@@ -574,7 +573,6 @@ out_fix_power_state:
 	return ret;
 }
 
-
 static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
 {
 	int ret, i;
@@ -674,8 +672,9 @@ static int bmc150_accel_read_raw(struct iio_dev *indio_dev,
 		if (chan->type == IIO_TEMP) {
 			*val = BMC150_ACCEL_TEMP_CENTER_VAL;
 			return IIO_VAL_INT;
-		} else
+		} else {
 			return -EINVAL;
+		}
 	case IIO_CHAN_INFO_SCALE:
 		*val = 0;
 		switch (chan->type) {
@@ -793,7 +792,6 @@ static int bmc150_accel_read_event_config(struct iio_dev *indio_dev,
 					  enum iio_event_type type,
 					  enum iio_event_direction dir)
 {
-
 	struct bmc150_accel_data *data = iio_priv(indio_dev);
 
 	return data->ev_enable_state;
@@ -827,7 +825,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
 }
 
 static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev,
-				   struct iio_trigger *trig)
+					 struct iio_trigger *trig)
 {
 	struct bmc150_accel_data *data = iio_priv(indio_dev);
 	int i;
@@ -963,6 +961,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
 	u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
 	int64_t tstamp;
 	uint64_t sample_period;
+
 	ret = i2c_smbus_read_byte_data(data->client,
 				       BMC150_ACCEL_REG_FIFO_STATUS);
 	if (ret < 0) {
@@ -1255,7 +1254,7 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig)
 }
 
 static int bmc150_accel_trigger_set_state(struct iio_trigger *trig,
-						   bool state)
+					  bool state)
 {
 	struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig);
 	struct bmc150_accel_data *data = t->data;
@@ -1314,26 +1313,32 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
 		dir = IIO_EV_DIR_RISING;
 
 	if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
-		iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-							0,
-							IIO_MOD_X,
-							IIO_EV_TYPE_ROC,
-							dir),
-							data->timestamp);
+		iio_push_event(indio_dev,
+			       IIO_MOD_EVENT_CODE(IIO_ACCEL,
+						  0,
+						  IIO_MOD_X,
+						  IIO_EV_TYPE_ROC,
+						  dir),
+			       data->timestamp);
+
 	if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
-		iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-							0,
-							IIO_MOD_Y,
-							IIO_EV_TYPE_ROC,
-							dir),
-							data->timestamp);
+		iio_push_event(indio_dev,
+			       IIO_MOD_EVENT_CODE(IIO_ACCEL,
+						  0,
+						  IIO_MOD_Y,
+						  IIO_EV_TYPE_ROC,
+						  dir),
+			       data->timestamp);
+
 	if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
-		iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-							0,
-							IIO_MOD_Z,
-							IIO_EV_TYPE_ROC,
-							dir),
-							data->timestamp);
+		iio_push_event(indio_dev,
+			       IIO_MOD_EVENT_CODE(IIO_ACCEL,
+						  0,
+						  IIO_MOD_Z,
+						  IIO_EV_TYPE_ROC,
+						  dir),
+			       data->timestamp);
+
 	return ret;
 }
 
@@ -1365,7 +1370,9 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private)
 					BMC150_ACCEL_INT_MODE_LATCH_INT |
 					BMC150_ACCEL_INT_MODE_LATCH_RESET);
 		if (ret)
-			dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n");
+			dev_err(&data->client->dev,
+				"Error writing reg_int_rst_latch\n");
+
 		ret = IRQ_HANDLED;
 	} else {
 		ret = IRQ_NONE;
@@ -1412,13 +1419,13 @@ static const char *bmc150_accel_match_acpi_device(struct device *dev, int *data)
 	if (!id)
 		return NULL;
 
-	*data = (int) id->driver_data;
+	*data = (int)id->driver_data;
 
 	return dev_name(dev);
 }
 
 static int bmc150_accel_gpio_probe(struct i2c_client *client,
-					struct bmc150_accel_data *data)
+				   struct bmc150_accel_data *data)
 {
 	struct device *dev;
 	struct gpio_desc *gpio;
Signature · 1 line
2.3.6
Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] iio:accel:bmc150-accel: code style cleanup

Quoted 10 lines · Hartmut Knaack

Apply the following coding style changes as indicated by checkpatch.pl in strict mode:
- Please don't use multiple blank lines
- braces {} should be used on all arms of this statement (if/else)
- Alignment should match open parenthesis
- Please don't use multiple blank lines
- Blank lines aren't necessary after an open brace '{'
- Missing a blank line after declarations
- No space is necessary after a cast

Quoted 4 lines

Also wrap/consolidate error messages to fit 80 characters per line and rework a comment.

Quoted 227 lines
---
 drivers/iio/accel/bmc150-accel.c | 91 +++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 42 deletions(-)
drivers/iio/accel/bmc150-accel.c +49 -43
index 36a9cd5..e84e2a1 100644
@@ -241,7 +241,6 @@ static const struct {
                                       {500000, BMC150_ACCEL_SLEEP_500_MS},
                                       {1000000, BMC150_ACCEL_SLEEP_1_SEC} };
 
-
 static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
                                 enum bmc150_power_modes mode,
                                 int dur_us)
@@ -259,8 +258,9 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
                                dur_val =
                                bmc150_accel_sleep_value_table[i].reg_value;
                }
-       } else
+       } else {
                dur_val = 0;
+       }
 
        if (dur_val < 0)
                return -EINVAL;
@@ -288,7 +288,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
 
        for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
                if (bmc150_accel_samp_freq_table[i].val == val &&
-                               bmc150_accel_samp_freq_table[i].val2 == val2) {
+                   bmc150_accel_samp_freq_table[i].val2 == val2) {
                        ret = i2c_smbus_write_byte_data(
                                data->client,
                                BMC150_ACCEL_REG_PMU_BW,
@@ -351,8 +351,7 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 
        ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
        if (ret < 0) {
-               dev_err(&data->client->dev,
-                       "Error: Reading chip id\n");
+               dev_err(&data->client->dev, "Error: Reading chip id\n");
                return ret;
        }
 
@@ -376,8 +375,7 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
                                        BMC150_ACCEL_REG_PMU_RANGE,
                                        BMC150_ACCEL_DEF_RANGE_4G);
        if (ret < 0) {
-               dev_err(&data->client->dev,
-                                       "Error writing reg_pmu_range\n");
+               dev_err(&data->client->dev, "Error writing reg_pmu_range\n");
                return ret;
        }
 
@@ -437,12 +435,13 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
 {
        int ret;
 
-       if (on)
+       if (on) {
                ret = pm_runtime_get_sync(&data->client->dev);
-       else {
+       } else {
                pm_runtime_mark_last_busy(&data->client->dev);
                ret = pm_runtime_put_autosuspend(&data->client->dev);
        }
+
        if (ret < 0) {
                dev_err(&data->client->dev,
                        "Failed: bmc150_accel_set_power_state for %d\n", on);
@@ -514,13 +513,13 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
        }
 
        /*
-        * We will expect the enable and disable to do operation in
-        * in reverse order. This will happen here anyway as our
-        * resume operation uses sync mode runtime pm calls, the
-        * suspend operation will be delayed by autosuspend delay
-        * So the disable operation will still happen in reverse of
-        * enable operation. When runtime pm is disabled the mode
-        * is always on so sequence doesn't matter
+        * We will expect the enable and disable to do operation in reverse
+        * order. This will happen here anyway, as our resume operation uses
+        * sync mode runtime pm calls. The suspend operation will be delayed
+        * by autosuspend delay.
+        * So the disable operation will still happen in reverse order of
+        * enable operation. When runtime pm is disabled the mode is always on,
+        * so sequence doesn't matter.
         */
        ret = bmc150_accel_set_power_state(data, state);
        if (ret < 0)
@@ -574,7 +573,6 @@ out_fix_power_state:
        return ret;
 }
 
-
 static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
 {
        int ret, i;
@@ -674,8 +672,9 @@ static int bmc150_accel_read_raw(struct iio_dev *indio_dev,
                if (chan->type == IIO_TEMP) {
                        *val = BMC150_ACCEL_TEMP_CENTER_VAL;
                        return IIO_VAL_INT;
-               } else
+               } else {
                        return -EINVAL;
+               }
        case IIO_CHAN_INFO_SCALE:
                *val = 0;
                switch (chan->type) {
@@ -793,7 +792,6 @@ static int bmc150_accel_read_event_config(struct iio_dev *indio_dev,
                                          enum iio_event_type type,
                                          enum iio_event_direction dir)
 {
-
        struct bmc150_accel_data *data = iio_priv(indio_dev);
 
        return data->ev_enable_state;
@@ -827,7 +825,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
 }
 
 static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev,
-                                  struct iio_trigger *trig)
+                                        struct iio_trigger *trig)
 {
        struct bmc150_accel_data *data = iio_priv(indio_dev);
        int i;
@@ -963,6 +961,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
        u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
        int64_t tstamp;
        uint64_t sample_period;
+
        ret = i2c_smbus_read_byte_data(data->client,
                                       BMC150_ACCEL_REG_FIFO_STATUS);
        if (ret < 0) {
@@ -1255,7 +1254,7 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig)
 }
 
 static int bmc150_accel_trigger_set_state(struct iio_trigger *trig,
-                                                  bool state)
+                                         bool state)
 {
        struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig);
        struct bmc150_accel_data *data = t->data;
@@ -1314,26 +1313,32 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
                dir = IIO_EV_DIR_RISING;
 
        if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
-               iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-                                                       0,
-                                                       IIO_MOD_X,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       data->timestamp);
+               iio_push_event(indio_dev,
+                              IIO_MOD_EVENT_CODE(IIO_ACCEL,
+                                                 0,
+                                                 IIO_MOD_X,
+                                                 IIO_EV_TYPE_ROC,
+                                                 dir),
+                              data->timestamp);
+
        if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
-               iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-                                                       0,
-                                                       IIO_MOD_Y,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       data->timestamp);
+               iio_push_event(indio_dev,
+                              IIO_MOD_EVENT_CODE(IIO_ACCEL,
+                                                 0,
+                                                 IIO_MOD_Y,
+                                                 IIO_EV_TYPE_ROC,
+                                                 dir),
+                              data->timestamp);
+
        if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
-               iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-                                                       0,
-                                                       IIO_MOD_Z,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       data->timestamp);
+               iio_push_event(indio_dev,
+                              IIO_MOD_EVENT_CODE(IIO_ACCEL,
+                                                 0,
+                                                 IIO_MOD_Z,
+                                                 IIO_EV_TYPE_ROC,
+                                                 dir),
+                              data->timestamp);
+
        return ret;
 }
 
@@ -1365,7 +1370,9 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private)
                                        BMC150_ACCEL_INT_MODE_LATCH_INT |
                                        BMC150_ACCEL_INT_MODE_LATCH_RESET);
                if (ret)
-                       dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n");
+                       dev_err(&data->client->dev,
+                               "Error writing reg_int_rst_latch\n");
+
                ret = IRQ_HANDLED;
        } else {
                ret = IRQ_NONE;
@@ -1412,13 +1419,13 @@ static const char *bmc150_accel_match_acpi_device(struct device *dev, int *data)
        if (!id)
                return NULL;
 
-       *data = (int) id->driver_data;
+       *data = (int)id->driver_data;
 
        return dev_name(dev);
 }
 
 static int bmc150_accel_gpio_probe(struct i2c_client *client,
-                                       struct bmc150_accel_data *data)
+                                  struct bmc150_accel_data *data)
 {
        struct device *dev;
        struct gpio_desc *gpio;
--

2.3.6

maintainer
#9 lore raw

Re: [PATCH 3/3] iio:accel:bmc150-accel: code style cleanup

Quoted 11 lines · Octavian Purdila
Quoted 10 lines · Hartmut Knaack

Apply the following coding style changes as indicated by checkpatch.pl in strict mode:
- Please don't use multiple blank lines
- braces {} should be used on all arms of this statement (if/else)
- Alignment should match open parenthesis
- Please don't use multiple blank lines
- Blank lines aren't necessary after an open brace '{'
- Missing a blank line after declarations
- No space is necessary after a cast

Quoted 6 lines
Quoted 4 lines

Also wrap/consolidate error messages to fit 80 characters per line and rework a comment.

Applied to the togreg branch of iio.git, initially pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 219 lines
Quoted 219 lines
---
 drivers/iio/accel/bmc150-accel.c | 91 +++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 42 deletions(-)
drivers/iio/accel/bmc150-accel.c +48 -41
index 36a9cd5..e84e2a1 100644
@@ -241,7 +241,6 @@ static const struct {
                                       {500000, BMC150_ACCEL_SLEEP_500_MS},
                                       {1000000, BMC150_ACCEL_SLEEP_1_SEC} };
 
-
 static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
                                 enum bmc150_power_modes mode,
                                 int dur_us)
@@ -259,8 +258,9 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
                                dur_val =
                                bmc150_accel_sleep_value_table[i].reg_value;
                }
-       } else
+       } else {
                dur_val = 0;
+       }
 
        if (dur_val < 0)
                return -EINVAL;
@@ -288,7 +288,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
 
        for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
                if (bmc150_accel_samp_freq_table[i].val == val &&
-                               bmc150_accel_samp_freq_table[i].val2 == val2) {
+                   bmc150_accel_samp_freq_table[i].val2 == val2) {
                        ret = i2c_smbus_write_byte_data(
                                data->client,
                                BMC150_ACCEL_REG_PMU_BW,
@@ -351,8 +351,7 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 
        ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
        if (ret < 0) {
-               dev_err(&data->client->dev,
-                       "Error: Reading chip id\n");
+               dev_err(&data->client->dev, "Error: Reading chip id\n");
                return ret;
        }
 
@@ -376,8 +375,7 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
                                        BMC150_ACCEL_REG_PMU_RANGE,
                                        BMC150_ACCEL_DEF_RANGE_4G);
        if (ret < 0) {
-               dev_err(&data->client->dev,
-                                       "Error writing reg_pmu_range\n");
+               dev_err(&data->client->dev, "Error writing reg_pmu_range\n");
                return ret;
        }
 
@@ -437,12 +435,13 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
 {
        int ret;
 
-       if (on)
+       if (on) {
                ret = pm_runtime_get_sync(&data->client->dev);
-       else {
+       } else {
                pm_runtime_mark_last_busy(&data->client->dev);
                ret = pm_runtime_put_autosuspend(&data->client->dev);
        }
+
        if (ret < 0) {
                dev_err(&data->client->dev,
                        "Failed: bmc150_accel_set_power_state for %d\n", on);
@@ -514,13 +513,13 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
        }
 
        /*
-        * We will expect the enable and disable to do operation in
-        * in reverse order. This will happen here anyway as our
-        * resume operation uses sync mode runtime pm calls, the
-        * suspend operation will be delayed by autosuspend delay
-        * So the disable operation will still happen in reverse of
-        * enable operation. When runtime pm is disabled the mode
-        * is always on so sequence doesn't matter
+        * We will expect the enable and disable to do operation in reverse
+        * order. This will happen here anyway, as our resume operation uses
+        * sync mode runtime pm calls. The suspend operation will be delayed
+        * by autosuspend delay.
+        * So the disable operation will still happen in reverse order of
+        * enable operation. When runtime pm is disabled the mode is always on,
+        * so sequence doesn't matter.
         */
        ret = bmc150_accel_set_power_state(data, state);
        if (ret < 0)
@@ -574,7 +573,6 @@ out_fix_power_state:
        return ret;
 }
 
-
 static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
 {
        int ret, i;
@@ -674,8 +672,9 @@ static int bmc150_accel_read_raw(struct iio_dev *indio_dev,
                if (chan->type == IIO_TEMP) {
                        *val = BMC150_ACCEL_TEMP_CENTER_VAL;
                        return IIO_VAL_INT;
-               } else
+               } else {
                        return -EINVAL;
+               }
        case IIO_CHAN_INFO_SCALE:
                *val = 0;
                switch (chan->type) {
@@ -793,7 +792,6 @@ static int bmc150_accel_read_event_config(struct iio_dev *indio_dev,
                                          enum iio_event_type type,
                                          enum iio_event_direction dir)
 {
-
        struct bmc150_accel_data *data = iio_priv(indio_dev);
 
        return data->ev_enable_state;
@@ -827,7 +825,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
 }
 
 static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev,
-                                  struct iio_trigger *trig)
+                                        struct iio_trigger *trig)
 {
        struct bmc150_accel_data *data = iio_priv(indio_dev);
        int i;
@@ -963,6 +961,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
        u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
        int64_t tstamp;
        uint64_t sample_period;
+
        ret = i2c_smbus_read_byte_data(data->client,
                                       BMC150_ACCEL_REG_FIFO_STATUS);
        if (ret < 0) {
@@ -1255,7 +1254,7 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig)
 }
 
 static int bmc150_accel_trigger_set_state(struct iio_trigger *trig,
-                                                  bool state)
+                                         bool state)
 {
        struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig);
        struct bmc150_accel_data *data = t->data;
@@ -1314,26 +1313,32 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
                dir = IIO_EV_DIR_RISING;
 
        if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
-               iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-                                                       0,
-                                                       IIO_MOD_X,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       data->timestamp);
+               iio_push_event(indio_dev,
+                              IIO_MOD_EVENT_CODE(IIO_ACCEL,
+                                                 0,
+                                                 IIO_MOD_X,
+                                                 IIO_EV_TYPE_ROC,
+                                                 dir),
+                              data->timestamp);
+
        if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
-               iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-                                                       0,
-                                                       IIO_MOD_Y,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       data->timestamp);
+               iio_push_event(indio_dev,
+                              IIO_MOD_EVENT_CODE(IIO_ACCEL,
+                                                 0,
+                                                 IIO_MOD_Y,
+                                                 IIO_EV_TYPE_ROC,
+                                                 dir),
+                              data->timestamp);
+
        if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
-               iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
-                                                       0,
-                                                       IIO_MOD_Z,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       data->timestamp);
+               iio_push_event(indio_dev,
+                              IIO_MOD_EVENT_CODE(IIO_ACCEL,
+                                                 0,
+                                                 IIO_MOD_Z,
+                                                 IIO_EV_TYPE_ROC,
+                                                 dir),
+                              data->timestamp);
+
        return ret;
 }
 
@@ -1365,7 +1370,9 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private)
                                        BMC150_ACCEL_INT_MODE_LATCH_INT |
                                        BMC150_ACCEL_INT_MODE_LATCH_RESET);
                if (ret)
-                       dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n");
+                       dev_err(&data->client->dev,
+                               "Error writing reg_int_rst_latch\n");
+
                ret = IRQ_HANDLED;
        } else {
                ret = IRQ_NONE;
@@ -1412,13 +1419,13 @@ static const char *bmc150_accel_match_acpi_device(struct device *dev, int *data)
        if (!id)
                return NULL;
 
-       *data = (int) id->driver_data;
+       *data = (int)id->driver_data;
 
        return dev_name(dev);
 }
 
Quoted 9 lines
Quoted 9 lines
drivers/iio/accel/bmc150-accel.c +1 -2
 static int bmc150_accel_gpio_probe(struct i2c_client *client,
-                                       struct bmc150_accel_data *data)
+                                  struct bmc150_accel_data *data)
 {
        struct device *dev;
        struct gpio_desc *gpio;
--

2.3.6

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in