Skip to contentSkip to conversation

IIO: accel: fixed coding style issues

PATCH In review Paul Lemmermann 3 participants 6 messages Mar 28, 2022 – Apr 2, 2022 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IIO: accel: fixed coding style issues

Fixed case statement issues and spacing issues.

---
 drivers/iio/accel/bmc150-accel-core.c | 15 +++++++++++----
 drivers/iio/accel/dmard09.c           |  2 +-
 drivers/iio/accel/kxsd9-spi.c         |  4 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)
drivers/iio/accel/bmc150-accel-core.c +11 -4
index d11f66801..f7dd7ec2c 100644
@@ -432,10 +432,17 @@ static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev,
 
 		for (j = 0; j < 3; j++) {
 			switch (val[j]) {
-			case -1: str = "-1"; break;
-			case 0:  str = "0";  break;
-			case 1:  str = "1";  break;
-			default: goto unknown_format;
+			case -1:
+				str = "-1";
+				break;
+			case 0:
+				str = "0";
+				break;
+			case 1:
+				str = "1";
+				break;
+			default:
+				goto unknown_format;
 			}
 			orientation->rotation[i * 3 + j] = str;
 		}
drivers/iio/accel/dmard09.c +1 -1
index e6e28c964..87bc38d4d 100644
@@ -24,7 +24,7 @@
 #define DMARD09_AXIS_Y 1
 #define DMARD09_AXIS_Z 2
 #define DMARD09_AXIS_X_OFFSET ((DMARD09_AXIS_X + 1) * 2)
-#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1 )* 2)
+#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1) * 2)
 #define DMARD09_AXIS_Z_OFFSET ((DMARD09_AXIS_Z + 1) * 2)
 
 struct dmard09_data {
drivers/iio/accel/kxsd9-spi.c +2 -2
index 57c451cfb..989f53fb0 100644
@@ -44,8 +44,8 @@ static const struct spi_device_id kxsd9_spi_id[] = {
 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
 
 static const struct of_device_id kxsd9_of_match[] = {
-        { .compatible = "kionix,kxsd9" },
-        { },
+	{ .compatible = "kionix,kxsd9" },
+	{ },
 };
 MODULE_DEVICE_TABLE(of, kxsd9_of_match);
 
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 3 lines · On Mon, 28 Mar 2022 10:05:08 -0500 Paul Lemmermann…

Fixed case statement issues and spacing issues.

Hi Paul,

Thanks for the patch.

These are drivers written / maintained by different authors, so one patch per driver preferred. Particularly handy as people might not agree with all of them so separate patches would allow me to pick and choose which ones to pick up.

Comments inline.

Please state how you identified the changes btw. Script?

Jonathan

Quoted 19 lines
---
 drivers/iio/accel/bmc150-accel-core.c | 15 +++++++++++----
 drivers/iio/accel/dmard09.c           |  2 +-
 drivers/iio/accel/kxsd9-spi.c         |  4 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)
drivers/iio/accel/bmc150-accel-core.c +1 -4
index d11f66801..f7dd7ec2c 100644
@@ -432,10 +432,17 @@ static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev,
 
 		for (j = 0; j < 3; j++) {
 			switch (val[j]) {
-			case -1: str = "-1"; break;
-			case 0:  str = "0";  break;
-			case 1:  str = "1";  break;
-			default: goto unknown_format;
+			case -1:

drivers/iio/accel/bmc150-accel-core.c static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev, · line 445

Quoted 10 lines
drivers/iio/accel/bmc150-accel-core.c +10 -0
+				str = "-1";
+				break;
+			case 0:
+				str = "0";
+				break;
+			case 1:
+				str = "1";
+				break;
+			default:
+				goto unknown_format;

I'm not seeing any clear advantage to this change.

drivers/iio/accel/dmard09.c line 27

Quoted 13 lines
drivers/iio/accel/bmc150-accel-core.c +0 -0
 			}
 			orientation->rotation[i * 3 + j] = str;
 		}
drivers/iio/accel/dmard09.c +1 -1
index e6e28c964..87bc38d4d 100644
@@ -24,7 +24,7 @@
 #define DMARD09_AXIS_Y 1
 #define DMARD09_AXIS_Z 2
 #define DMARD09_AXIS_X_OFFSET ((DMARD09_AXIS_X + 1) * 2)
-#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1 )* 2)
+#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1) * 2)

This is one is good.

Quoted 8 lines
drivers/iio/accel/dmard09.c +0 -0
 #define DMARD09_AXIS_Z_OFFSET ((DMARD09_AXIS_Z + 1) * 2)
 
 struct dmard09_data {
drivers/iio/accel/kxsd9-spi.c +0 -0
index 57c451cfb..989f53fb0 100644

drivers/iio/accel/kxsd9-spi.c static const struct spi_device_id kxsd9_spi_id[] = { · line 47

Quoted 6 lines
drivers/iio/accel/kxsd9-spi.c +1 -2
@@ -44,8 +44,8 @@ static const struct spi_device_id kxsd9_spi_id[] = {
 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
 
 static const struct of_device_id kxsd9_of_match[] = {
-        { .compatible = "kionix,kxsd9" },
-        { },
+	{ .compatible = "kionix,kxsd9" },

Also good to clean up.

Thanks,

Jonathan

Quoted 4 lines
drivers/iio/accel/kxsd9-spi.c +1 -0
+	{ },
 };
 MODULE_DEVICE_TABLE(of, kxsd9_of_match);
 
#2 lore raw
Quoted 10 lines · Jonathan Cameron
Quoted 3 lines · On Mon, 28 Mar 2022 10:05:08 -0500 Paul Lemmermann…

Fixed case statement issues and spacing issues.

Hi Paul,

Thanks for the patch.

Quoted 8 lines

These are drivers written / maintained by different authors, so one patch per driver preferred. Particularly handy as people might not agree with all of them so separate patches would allow me to pick and choose which ones to pick up.

Comments inline.

Please state how you identified the changes btw. Script?

I used the checkpatch.pl script to identify these changes.

Quoted 26 lines

Jonathan

Quoted 23 lines
---
 drivers/iio/accel/bmc150-accel-core.c | 15 +++++++++++----
 drivers/iio/accel/dmard09.c           |  2 +-
 drivers/iio/accel/kxsd9-spi.c         |  4 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)
drivers/iio/accel/bmc150-accel-core.c +5 -4
index d11f66801..f7dd7ec2c 100644
@@ -432,10 +432,17 @@ static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev,
 
 		for (j = 0; j < 3; j++) {
 			switch (val[j]) {
-			case -1: str = "-1"; break;
-			case 0:  str = "0";  break;
-			case 1:  str = "1";  break;
-			default: goto unknown_format;
+			case -1:
+				str = "-1";
+				break;
+			case 0:
+				str = "0";
Quoted 9 lines

drivers/iio/accel/bmc150-accel-core.c static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev, · line 445

Quoted 6 lines
drivers/iio/accel/bmc150-accel-core.c +6 -0
+				break;
+			case 1:
+				str = "1";
+				break;
+			default:
+				goto unknown_format;

I'm not seeing any clear advantage to this change.

The reason for this change is that most, if not all, case statements in
the kernel are multiple lines. Also, in the kernel docs (https://docs.kernel.org/process/coding-style.html)
it says, to not put multiple statements on one line.

Thanks,
Paul

Quoted 44 lines
Quoted 9 lines
drivers/iio/accel/bmc150-accel-core.c +0 -0
 			}
 			orientation->rotation[i * 3 + j] = str;
 		}
drivers/iio/accel/dmard09.c +0 -0
index e6e28c964..87bc38d4d 100644

drivers/iio/accel/dmard09.c line 27

Quoted 5 lines
drivers/iio/accel/dmard09.c +1 -1
@@ -24,7 +24,7 @@
 #define DMARD09_AXIS_Y 1
 #define DMARD09_AXIS_Z 2
 #define DMARD09_AXIS_X_OFFSET ((DMARD09_AXIS_X + 1) * 2)
-#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1 )* 2)
+#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1) * 2)

This is one is good.

Quoted 8 lines
drivers/iio/accel/dmard09.c +0 -0
 #define DMARD09_AXIS_Z_OFFSET ((DMARD09_AXIS_Z + 1) * 2)
 
 struct dmard09_data {
drivers/iio/accel/kxsd9-spi.c +0 -0
index 57c451cfb..989f53fb0 100644

drivers/iio/accel/kxsd9-spi.c static const struct spi_device_id kxsd9_spi_id[] = { · line 47

Quoted 6 lines
drivers/iio/accel/kxsd9-spi.c +1 -2
@@ -44,8 +44,8 @@ static const struct spi_device_id kxsd9_spi_id[] = {
 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
 
 static const struct of_device_id kxsd9_of_match[] = {
-        { .compatible = "kionix,kxsd9" },
-        { },
+	{ .compatible = "kionix,kxsd9" },

Also good to clean up.

Thanks,

Jonathan

Quoted 4 lines
drivers/iio/accel/kxsd9-spi.c +1 -0
+	{ },
 };
 MODULE_DEVICE_TABLE(of, kxsd9_of_match);
 
maintainer
#3 lore raw
Quoted 16 lines · On Mon, 28 Mar 2022 14:17:51 -0500 Paul Lemmermann…
Quoted 15 lines · Jonathan Cameron
Quoted 3 lines · On Mon, 28 Mar 2022 10:05:08 -0500 Paul Lemmermann…

Fixed case statement issues and spacing issues.

Hi Paul,

Thanks for the patch.

These are drivers written / maintained by different authors, so one patch per driver preferred. Particularly handy as people might not agree with all of them so separate patches would allow me to pick and choose which ones to pick up.

Quoted 5 lines
Quoted 3 lines

Comments inline.

Please state how you identified the changes btw. Script?

I used the checkpatch.pl script to identify these changes.

Please mention that in patch descriptions in future. It's useful to anyone tracking this sort of information.

I added it to the broken out patches whilst applying.

Thanks,

Jonathan

Quoted 86 lines
Quoted 27 lines

Jonathan

Quoted 23 lines
---
 drivers/iio/accel/bmc150-accel-core.c | 15 +++++++++++----
 drivers/iio/accel/dmard09.c           |  2 +-
 drivers/iio/accel/kxsd9-spi.c         |  4 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)
drivers/iio/accel/bmc150-accel-core.c +5 -4
index d11f66801..f7dd7ec2c 100644
@@ -432,10 +432,17 @@ static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev,
 
 		for (j = 0; j < 3; j++) {
 			switch (val[j]) {
-			case -1: str = "-1"; break;
-			case 0:  str = "0";  break;
-			case 1:  str = "1";  break;
-			default: goto unknown_format;
+			case -1:
+				str = "-1";
+				break;
+			case 0:
+				str = "0";
Quoted 9 lines

drivers/iio/accel/bmc150-accel-core.c static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev, · line 445

Quoted 6 lines
drivers/iio/accel/bmc150-accel-core.c +6 -0
+				break;
+			case 1:
+				str = "1";
+				break;
+			default:
+				goto unknown_format;  

I'm not seeing any clear advantage to this change.

The reason for this change is that most, if not all, case statements in
the kernel are multiple lines. Also, in the kernel docs (https://docs.kernel.org/process/coding-style.html)
it says, to not put multiple statements on one line.

Thanks,
Paul

Quoted 44 lines
Quoted 9 lines
drivers/iio/accel/bmc150-accel-core.c +0 -0
 			}
 			orientation->rotation[i * 3 + j] = str;
 		}
drivers/iio/accel/dmard09.c +0 -0
index e6e28c964..87bc38d4d 100644

drivers/iio/accel/dmard09.c line 27

Quoted 5 lines
drivers/iio/accel/dmard09.c +1 -1
@@ -24,7 +24,7 @@
 #define DMARD09_AXIS_Y 1
 #define DMARD09_AXIS_Z 2
 #define DMARD09_AXIS_X_OFFSET ((DMARD09_AXIS_X + 1) * 2)
-#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1 )* 2)
+#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1) * 2)  

This is one is good.

Quoted 8 lines
drivers/iio/accel/dmard09.c +0 -0
 #define DMARD09_AXIS_Z_OFFSET ((DMARD09_AXIS_Z + 1) * 2)
 
 struct dmard09_data {
drivers/iio/accel/kxsd9-spi.c +0 -0
index 57c451cfb..989f53fb0 100644

drivers/iio/accel/kxsd9-spi.c static const struct spi_device_id kxsd9_spi_id[] = { · line 47

Quoted 6 lines
drivers/iio/accel/kxsd9-spi.c +1 -2
@@ -44,8 +44,8 @@ static const struct spi_device_id kxsd9_spi_id[] = {
 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
 
 static const struct of_device_id kxsd9_of_match[] = {
-        { .compatible = "kionix,kxsd9" },
-        { },
+	{ .compatible = "kionix,kxsd9" },  

Also good to clean up.

Thanks,

Jonathan

Quoted 4 lines
drivers/iio/accel/kxsd9-spi.c +1 -0
+	{ },
 };
 MODULE_DEVICE_TABLE(of, kxsd9_of_match);
 
#4 lore raw
In reply to Paul Lemmermann
Quoted 2 lines · Paul Lemmermann

Fixed case statement issues and spacing issues.

...

Quoted 7 lines
                        switch (val[j]) {
drivers/iio/accel/bmc150-accel-core.c +2 -4
-                       case -1: str = "-1"; break;
-                       case 0:  str = "0";  break;
-                       case 1:  str = "1";  break;
-                       default: goto unknown_format;
+                       case -1:
+                               str = "-1";

drivers/iio/accel/bmc150-accel-core.c static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev, · line 446

Quoted 10 lines
drivers/iio/accel/bmc150-accel-core.c +9 -0
+                               break;
+                       case 0:
+                               str = "0";
+                               break;
+                       case 1:
+                               str = "1";
+                               break;
+                       default:
+                               goto unknown_format;
                        }

What you cited from documentation mostly affects the new code, but this code is already in the kernel and modifying it, esp. taking into account 3x LOCs count, looks like an unneeded churn, even if documentation thinks otherwise.

What I could acknowledge from your proposal is the default case. Otherwise just leave it to the point if we touch this code for something else in the future.

...

drivers/iio/accel/kxsd9-spi.c static const struct spi_device_id kxsd9_spi_id[] = {

Quoted 6 lines

static const struct of_device_id kxsd9_of_match[] = {

drivers/iio/accel/kxsd9-spi.c +2 -2
-        { .compatible = "kionix,kxsd9" },
-        { },
+       { .compatible = "kionix,kxsd9" },
 
+       { },

I dunno why you touched this line (likely TABs vs. spaces), but please remove the comma as well here.

Quoted 1 line

};

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 41 lines · Andy Shevchenko
Quoted 2 lines · Paul Lemmermann

Fixed case statement issues and spacing issues.

...

Quoted 7 lines
                        switch (val[j]) {
drivers/iio/accel/bmc150-accel-core.c +2 -4
-                       case -1: str = "-1"; break;
-                       case 0:  str = "0";  break;
-                       case 1:  str = "1";  break;
-                       default: goto unknown_format;
+                       case -1:
+                               str = "-1";

drivers/iio/accel/bmc150-accel-core.c static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev, · line 446

Quoted 10 lines
drivers/iio/accel/bmc150-accel-core.c +9 -0
+                               break;
+                       case 0:
+                               str = "0";
+                               break;
+                       case 1:
+                               str = "1";
+                               break;
+                       default:
+                               goto unknown_format;
                        }

What you cited from documentation mostly affects the new code, but this code is already in the kernel and modifying it, esp. taking into account 3x LOCs count, looks like an unneeded churn, even if documentation thinks otherwise.

What I could acknowledge from your proposal is the default case. Otherwise just leave it to the point if we touch this code for something else in the future.

...

Quoted 4 lines

static const struct of_device_id kxsd9_of_match[] = {

drivers/iio/accel/kxsd9-spi.c +1 -2
-        { .compatible = "kionix,kxsd9" },
-        { },
+       { .compatible = "kionix,kxsd9" },
Quoted 4 lines
Quoted 1 line

+ { },

I dunno why you touched this line (likely TABs vs. spaces), but please remove the comma as well here.

Yes, that is exactly why this patch exists.

Thank you, I will take these thoughts into account and submit a new patch.

Thanks!
Paul

Quoted 6 lines
Quoted 2 lines

};

Signature · 2 lines
With Best Regards,
Andy Shevchenko