Skip to contentSkip to conversation

iio: cros_ec_accel_legacy: Refactor code in cros_ec_accel_legacy_probe

PATCH In review Gustavo A. R. Silva 4 participants 4 messages Feb 21, 2019 – Mar 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: cros_ec_accel_legacy: Refactor code in cros_ec_accel_legacy_probe

Refactor some code in order to fix both the technical implementation and the following warnings:

drivers/iio/accel/cros_ec_accel_legacy.c: In function ‘cros_ec_accel_legacy_probe’:
drivers/iio/accel/cros_ec_accel_legacy.c:387:36: warning: this statement may fall through [-Wimplicit-fallthrough=]

    ec_accel_channels[X].scan_index = Y;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~

drivers/iio/accel/cros_ec_accel_legacy.c:388:3: note: here
case Y:
^~~~
drivers/iio/accel/cros_ec_accel_legacy.c:389:36: warning: this statement may fall through [-Wimplicit-fallthrough=]

    ec_accel_channels[Y].scan_index = X;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~

drivers/iio/accel/cros_ec_accel_legacy.c:390:3: note: here
case Z:
^~~~

Notice that neither the for loop nor the switch statement is needed. Also, "state->sign[Y] = 1" should be unconditional.

This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.

---
 drivers/iio/accel/cros_ec_accel_legacy.c | 27 +++++++++++-------------
 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/iio/accel/cros_ec_accel_legacy.c +12 -15
index 063e89eff791..021f9f5cd3bb 100644
@@ -353,7 +353,7 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
 	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
 	struct iio_dev *indio_dev;
 	struct cros_ec_accel_legacy_state *state;
-	int ret, i;
+	int ret;
 
 	if (!ec || !ec->ec_dev) {
 		dev_warn(&pdev->dev, "No EC device found.\n");
@@ -381,20 +381,17 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
 	 * Present the channel using HTML5 standard:
 	 * need to invert X and Y and invert some lid axis.
 	 */
-	for (i = X ; i < MAX_AXIS; i++) {
-		switch (i) {
-		case X:
-			ec_accel_channels[X].scan_index = Y;
-		case Y:
-			ec_accel_channels[Y].scan_index = X;
-		case Z:
-			ec_accel_channels[Z].scan_index = Z;
-		}
-		if (state->sensor_num == MOTIONSENSE_LOC_LID && i != Y)
-			state->sign[i] = -1;
-		else
-			state->sign[i] = 1;
-	}
+	ec_accel_channels[X].scan_index = Y;
+	ec_accel_channels[Y].scan_index = X;
+	ec_accel_channels[Z].scan_index = Z;
+
+	state->sign[Y] = 1;
+
+	if (state->sensor_num == MOTIONSENSE_LOC_LID)
+		state->sign[X] = state->sign[Z] = -1;
+	else
+		state->sign[X] = state->sign[Z] = 1;
+
 	indio_dev->num_channels = ARRAY_SIZE(ec_accel_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &cros_ec_accel_legacy_info;
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Gustavo A. R. Silva

Refactor some code in order to fix both the technical implementation and the following warnings:

drivers/iio/accel/cros_ec_accel_legacy.c: In function ‘cros_ec_accel_legacy_probe’:
drivers/iio/accel/cros_ec_accel_legacy.c:387:36: warning: this statement may fall through [-Wimplicit-fallthrough=]

    ec_accel_channels[X].scan_index = Y;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drivers/iio/accel/cros_ec_accel_legacy.c:388:3: note: here
   case Y:
   ^~~~
drivers/iio/accel/cros_ec_accel_legacy.c:389:36: warning: this statement may fall through [-Wimplicit-fallthrough=]
    ec_accel_channels[Y].scan_index = X;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drivers/iio/accel/cros_ec_accel_legacy.c:390:3: note: here
   case Z:
   ^~~~
Quoted 7 lines

Notice that neither the for loop nor the switch statement is needed. Also, "state->sign[Y] = 1" should be unconditional.

This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.

-Kees

Quoted 52 lines
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 27 +++++++++++-------------
 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/iio/accel/cros_ec_accel_legacy.c +12 -16
index 063e89eff791..021f9f5cd3bb 100644
@@ -353,7 +353,7 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
        struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
        struct iio_dev *indio_dev;
        struct cros_ec_accel_legacy_state *state;
-       int ret, i;
+       int ret;
 
        if (!ec || !ec->ec_dev) {
                dev_warn(&pdev->dev, "No EC device found.\n");
@@ -381,20 +381,17 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
         * Present the channel using HTML5 standard:
         * need to invert X and Y and invert some lid axis.
         */
-       for (i = X ; i < MAX_AXIS; i++) {
-               switch (i) {
-               case X:
-                       ec_accel_channels[X].scan_index = Y;
-               case Y:
-                       ec_accel_channels[Y].scan_index = X;
-               case Z:
-                       ec_accel_channels[Z].scan_index = Z;
-               }
-               if (state->sensor_num == MOTIONSENSE_LOC_LID && i != Y)
-                       state->sign[i] = -1;
-               else
-                       state->sign[i] = 1;
-       }
+       ec_accel_channels[X].scan_index = Y;
+       ec_accel_channels[Y].scan_index = X;
+       ec_accel_channels[Z].scan_index = Z;
+
+       state->sign[Y] = 1;
+
+       if (state->sensor_num == MOTIONSENSE_LOC_LID)
+               state->sign[X] = state->sign[Z] = -1;
+       else
+               state->sign[X] = state->sign[Z] = 1;
+
        indio_dev->num_channels = ARRAY_SIZE(ec_accel_channels);
        indio_dev->dev.parent = &pdev->dev;
        indio_dev->info = &cros_ec_accel_legacy_info;
--

2.20.1

Signature · 1 line
Kees Cook
#2 lore raw
Quoted 23 lines · Kees Cook
Quoted 21 lines · Gustavo A. R. Silva

Refactor some code in order to fix both the technical implementation and the following warnings:

drivers/iio/accel/cros_ec_accel_legacy.c: In function ‘cros_ec_accel_legacy_probe’:
drivers/iio/accel/cros_ec_accel_legacy.c:387:36: warning: this statement may fall through [-Wimplicit-fallthrough=]

    ec_accel_channels[X].scan_index = Y;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drivers/iio/accel/cros_ec_accel_legacy.c:388:3: note: here
   case Y:
   ^~~~
drivers/iio/accel/cros_ec_accel_legacy.c:389:36: warning: this statement may fall through [-Wimplicit-fallthrough=]
    ec_accel_channels[Y].scan_index = X;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drivers/iio/accel/cros_ec_accel_legacy.c:390:3: note: here
   case Z:
   ^~~~

Notice that neither the for loop nor the switch statement is needed. Also, "state->sign[Y] = 1" should be unconditional.

Quoted 7 lines
Quoted 4 lines

This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.

Thanks,
Enric

Quoted 56 lines

-Kees

Quoted 52 lines
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 27 +++++++++++-------------
 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/iio/accel/cros_ec_accel_legacy.c +12 -16
index 063e89eff791..021f9f5cd3bb 100644
@@ -353,7 +353,7 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
        struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
        struct iio_dev *indio_dev;
        struct cros_ec_accel_legacy_state *state;
-       int ret, i;
+       int ret;
 
        if (!ec || !ec->ec_dev) {
                dev_warn(&pdev->dev, "No EC device found.\n");
@@ -381,20 +381,17 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
         * Present the channel using HTML5 standard:
         * need to invert X and Y and invert some lid axis.
         */
-       for (i = X ; i < MAX_AXIS; i++) {
-               switch (i) {
-               case X:
-                       ec_accel_channels[X].scan_index = Y;
-               case Y:
-                       ec_accel_channels[Y].scan_index = X;
-               case Z:
-                       ec_accel_channels[Z].scan_index = Z;
-               }
-               if (state->sensor_num == MOTIONSENSE_LOC_LID && i != Y)
-                       state->sign[i] = -1;
-               else
-                       state->sign[i] = 1;
-       }
+       ec_accel_channels[X].scan_index = Y;
+       ec_accel_channels[Y].scan_index = X;
+       ec_accel_channels[Z].scan_index = Z;
+
+       state->sign[Y] = 1;
+
+       if (state->sensor_num == MOTIONSENSE_LOC_LID)
+               state->sign[X] = state->sign[Z] = -1;
+       else
+               state->sign[X] = state->sign[Z] = 1;
+
        indio_dev->num_channels = ARRAY_SIZE(ec_accel_channels);
        indio_dev->dev.parent = &pdev->dev;
        indio_dev->info = &cros_ec_accel_legacy_info;
--

2.20.1

maintainer
#3 lore raw
Quoted 27 lines · On Thu, 21 Feb 2019 09:03:39 +0100 Enric Balletbo i Serra…
Quoted 26 lines · Kees Cook
Quoted 24 lines · Gustavo A. R. Silva

Refactor some code in order to fix both the technical implementation and the following warnings:

drivers/iio/accel/cros_ec_accel_legacy.c: In function ‘cros_ec_accel_legacy_probe’:
drivers/iio/accel/cros_ec_accel_legacy.c:387:36: warning: this statement may fall through [-Wimplicit-fallthrough=]

    ec_accel_channels[X].scan_index = Y;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drivers/iio/accel/cros_ec_accel_legacy.c:388:3: note: here
   case Y:
   ^~~~
drivers/iio/accel/cros_ec_accel_legacy.c:389:36: warning: this statement may fall through [-Wimplicit-fallthrough=]
    ec_accel_channels[Y].scan_index = X;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drivers/iio/accel/cros_ec_accel_legacy.c:390:3: note: here
   case Z:
   ^~~~

Notice that neither the for loop nor the switch statement is needed. Also, "state->sign[Y] = 1" should be unconditional.

This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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

This will probably only make it upstream at the 'next' merge window given the timing.

Jonathan

Quoted 60 lines

Thanks,
Enric

Quoted 56 lines

-Kees

Quoted 52 lines
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 27 +++++++++++-------------
 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/iio/accel/cros_ec_accel_legacy.c +12 -16
index 063e89eff791..021f9f5cd3bb 100644
@@ -353,7 +353,7 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
        struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
        struct iio_dev *indio_dev;
        struct cros_ec_accel_legacy_state *state;
-       int ret, i;
+       int ret;
 
        if (!ec || !ec->ec_dev) {
                dev_warn(&pdev->dev, "No EC device found.\n");
@@ -381,20 +381,17 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
         * Present the channel using HTML5 standard:
         * need to invert X and Y and invert some lid axis.
         */
-       for (i = X ; i < MAX_AXIS; i++) {
-               switch (i) {
-               case X:
-                       ec_accel_channels[X].scan_index = Y;
-               case Y:
-                       ec_accel_channels[Y].scan_index = X;
-               case Z:
-                       ec_accel_channels[Z].scan_index = Z;
-               }
-               if (state->sensor_num == MOTIONSENSE_LOC_LID && i != Y)
-                       state->sign[i] = -1;
-               else
-                       state->sign[i] = 1;
-       }
+       ec_accel_channels[X].scan_index = Y;
+       ec_accel_channels[Y].scan_index = X;
+       ec_accel_channels[Z].scan_index = Z;
+
+       state->sign[Y] = 1;
+
+       if (state->sensor_num == MOTIONSENSE_LOC_LID)
+               state->sign[X] = state->sign[Z] = -1;
+       else
+               state->sign[X] = state->sign[Z] = 1;
+
        indio_dev->num_channels = ARRAY_SIZE(ec_accel_channels);
        indio_dev->dev.parent = &pdev->dev;
        indio_dev->info = &cros_ec_accel_legacy_info;
--

2.20.1