Skip to contentSkip to conversation

drivers/power/regulator/max77686.c: Don't use switch() on bools

PATCH In review Tom Rini 4 participants 7 messages Jan 17, 2016 – Jan 19, 2016

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 drivers/power/regulator/max77686.c: Don't use switch() on bools

With gcc-5.3 we get a warning for using switch() on a bool type. Rewrite these sections as if/else and update the one section that was using 1/0 instead of true/false.

Cc Simon Glass <[email protected]>
Cc Przemyslaw Marczak <[email protected]>
---
 drivers/power/regulator/max77686.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
drivers/power/regulator/max77686.c +8 -20
index 71678b6..7479af7 100644
@@ -515,25 +515,19 @@ static int max77686_ldo_enable(struct udevice *dev, int op, bool *enable)
 
 		switch (on_off) {
 		case OPMODE_OFF:
-			*enable = 0;
+			*enable = false;
 			break;
 		case OPMODE_ON:
-			*enable = 1;
+			*enable = true;
 			break;
 		default:
 			return -EINVAL;
 		}
 	} else if (op == PMIC_OP_SET) {
-		switch (*enable) {
-		case 0:
-			on_off = OPMODE_OFF;
-			break;
-		case 1:
+		if (*enable)
 			on_off = OPMODE_ON;
-			break;
-		default:
-			return -EINVAL;
-		}
+		else
+			on_off = OPMODE_OFF;
 
 		ret = max77686_ldo_mode(dev, op, &on_off);
 		if (ret)
@@ -651,16 +645,10 @@ static int max77686_buck_enable(struct udevice *dev, int op, bool *enable)
 			return -EINVAL;
 		}
 	} else if (op == PMIC_OP_SET) {
-		switch (*enable) {
-		case 0:
-			on_off = OPMODE_OFF;
-			break;
-		case 1:
+		if (*enable)
 			on_off = OPMODE_ON;
-			break;
-		default:
-			return -EINVAL;
-		}
+		else
+			on_off = OPMODE_OFF;
 
 		ret = max77686_buck_mode(dev, op, &on_off);
 		if (ret)
Signature · 1 line
2.7.0.rc3
#1 lore raw

PATCH 1/1 drivers/power/regulator/max77686.c: Don't use switch() on bools

Quoted 11 lines · Tom Rini

With gcc-5.3 we get a warning for using switch() on a bool type. Rewrite these sections as if/else and update the one section that was using 1/0 instead of true/false.

Cc Simon Glass <[email protected]>
Cc Przemyslaw Marczak <[email protected]>
---
 drivers/power/regulator/max77686.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
#2 lore raw

PATCH 1/1 drivers/power/regulator/max77686.c: Don't use switch() on bools

In reply to Tom Rini

Hello Tom,

Quoted 57 lines · Tom Rini

With gcc-5.3 we get a warning for using switch() on a bool type. Rewrite these sections as if/else and update the one section that was using 1/0 instead of true/false.

Cc Simon Glass <[email protected]>
Cc Przemyslaw Marczak <[email protected]>
---
  drivers/power/regulator/max77686.c | 28 ++++++++--------------------
  1 file changed, 8 insertions(+), 20 deletions(-)
drivers/power/regulator/max77686.c +6 -16
index 71678b6..7479af7 100644
@@ -515,25 +515,19 @@ static int max77686_ldo_enable(struct udevice *dev, int op, bool *enable)
 
  		switch (on_off) {
  		case OPMODE_OFF:
-			*enable = 0;
+			*enable = false;
  			break;
  		case OPMODE_ON:
-			*enable = 1;
+			*enable = true;
  			break;
  		default:
  			return -EINVAL;
  		}
  	} else if (op == PMIC_OP_SET) {
-		switch (*enable) {
-		case 0:
-			on_off = OPMODE_OFF;
-			break;
-		case 1:
+		if (*enable)
  			on_off = OPMODE_ON;
-			break;
-		default:
-			return -EINVAL;
-		}
+		else
+			on_off = OPMODE_OFF;
 
  		ret = max77686_ldo_mode(dev, op, &on_off);
  		if (ret)
@@ -651,16 +645,10 @@ static int max77686_buck_enable(struct udevice *dev, int op, bool *enable)
  			return -EINVAL;
  		}
  	} else if (op == PMIC_OP_SET) {
-		switch (*enable) {
-		case 0:
-			on_off = OPMODE_OFF;
-			break;
-		case 1:
+		if (*enable)

drivers/power/regulator/max77686.c static int max77686_buck_enable(struct udevice *dev, int op, bool *enable) · line 654

Quoted 10 lines
drivers/power/regulator/max77686.c +2 -4
  			on_off = OPMODE_ON;
-			break;
-		default:
-			return -EINVAL;
-		}
+		else
+			on_off = OPMODE_OFF;
 
  		ret = max77686_buck_mode(dev, op, &on_off);
  		if (ret)

Thank you for pointing that:)

Best regards,

Signature · 4 lines
Przemyslaw Marczak
Samsung R&D Institute Poland
Samsung Electronics
p.marczak at samsung.com
#3 lore raw

PATCH 1/1 drivers/power/regulator/max77686.c: Don't use switch() on bools

In reply to Tom Rini

Hi

Quoted 11 lines · Tom Rini

With gcc-5.3 we get a warning for using switch() on a bool type. Rewrite these sections as if/else and update the one section that was using 1/0 instead of true/false.

Cc Simon Glass <[email protected]>
Cc Przemyslaw Marczak <[email protected]>
---
 drivers/power/regulator/max77686.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

I never seen subject that contains the path of a driver.

Michael

Quoted 62 lines
drivers/power/regulator/max77686.c +8 -21
index 71678b6..7479af7 100644
@@ -515,25 +515,19 @@ static int max77686_ldo_enable(struct udevice *dev, int op, bool *enable)
 
                switch (on_off) {
                case OPMODE_OFF:
-                       *enable = 0;
+                       *enable = false;
                        break;
                case OPMODE_ON:
-                       *enable = 1;
+                       *enable = true;
                        break;
                default:
                        return -EINVAL;
                }
        } else if (op == PMIC_OP_SET) {
-               switch (*enable) {
-               case 0:
-                       on_off = OPMODE_OFF;
-                       break;
-               case 1:
+               if (*enable)
                        on_off = OPMODE_ON;
-                       break;
-               default:
-                       return -EINVAL;
-               }
+               else
+                       on_off = OPMODE_OFF;
 
                ret = max77686_ldo_mode(dev, op, &on_off);
                if (ret)
@@ -651,16 +645,10 @@ static int max77686_buck_enable(struct udevice *dev, int op, bool *enable)
                        return -EINVAL;
                }
        } else if (op == PMIC_OP_SET) {
-               switch (*enable) {
-               case 0:
-                       on_off = OPMODE_OFF;
-                       break;
-               case 1:
+               if (*enable)
                        on_off = OPMODE_ON;
-                       break;
-               default:
-                       return -EINVAL;
-               }
+               else
+                       on_off = OPMODE_OFF;
 
                ret = max77686_buck_mode(dev, op, &on_off);
                if (ret)
--

2.7.0.rc3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
author
#4 lore raw

PATCH 1/1 drivers/power/regulator/max77686.c: Don't use switch() on bools

Quoted 15 lines · Michael Trimarchi

Hi

Quoted 11 lines · Tom Rini

With gcc-5.3 we get a warning for using switch() on a bool type. Rewrite these sections as if/else and update the one section that was using 1/0 instead of true/false.

Cc Simon Glass <[email protected]>
Cc Przemyslaw Marczak <[email protected]>
---
 drivers/power/regulator/max77686.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
Quoted 1 line

I never seen subject that contains the path of a driver.

Uncommon but done sometimes.

Quoted 73 lines

Michael

Quoted 62 lines
drivers/power/regulator/max77686.c +8 -21
index 71678b6..7479af7 100644
@@ -515,25 +515,19 @@ static int max77686_ldo_enable(struct udevice *dev, int op, bool *enable)
 
                switch (on_off) {
                case OPMODE_OFF:
-                       *enable = 0;
+                       *enable = false;
                        break;
                case OPMODE_ON:
-                       *enable = 1;
+                       *enable = true;
                        break;
                default:
                        return -EINVAL;
                }
        } else if (op == PMIC_OP_SET) {
-               switch (*enable) {
-               case 0:
-                       on_off = OPMODE_OFF;
-                       break;
-               case 1:
+               if (*enable)
                        on_off = OPMODE_ON;
-                       break;
-               default:
-                       return -EINVAL;
-               }
+               else
+                       on_off = OPMODE_OFF;
 
                ret = max77686_ldo_mode(dev, op, &on_off);
                if (ret)
@@ -651,16 +645,10 @@ static int max77686_buck_enable(struct udevice *dev, int op, bool *enable)
                        return -EINVAL;
                }
        } else if (op == PMIC_OP_SET) {
-               switch (*enable) {
-               case 0:
-                       on_off = OPMODE_OFF;
-                       break;
-               case 1:
+               if (*enable)
                        on_off = OPMODE_ON;
-                       break;
-               default:
-                       return -EINVAL;
-               }
+               else
+                       on_off = OPMODE_OFF;
 
                ret = max77686_buck_mode(dev, op, &on_off);
                if (ret)
--

2.7.0.rc3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160118/79bf7311/attachment.sig>
#5 lore raw

PATCH 1/1 drivers/power/regulator/max77686.c: Don't use switch() on bools

Hi

Quoted 16 lines · Tom Rini
Quoted 15 lines · Michael Trimarchi

Hi

Quoted 11 lines · Tom Rini

With gcc-5.3 we get a warning for using switch() on a bool type. Rewrite these sections as if/else and update the one section that was using 1/0 instead of true/false.

Cc Simon Glass <[email protected]>
Cc Przemyslaw Marczak <[email protected]>
---
 drivers/power/regulator/max77686.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
Quoted 4 lines
Quoted 1 line

I never seen subject that contains the path of a driver.

Uncommon but done sometimes.

Can you just fix it up and make more common? I think that patchwork in general organize better the emails too

Michael

Quoted 76 lines
Quoted 69 lines

Michael

Quoted 58 lines
drivers/power/regulator/max77686.c +8 -21
index 71678b6..7479af7 100644
@@ -515,25 +515,19 @@ static int max77686_ldo_enable(struct udevice *dev, int op, bool *enable)
 
                switch (on_off) {
                case OPMODE_OFF:
-                       *enable = 0;
+                       *enable = false;
                        break;
                case OPMODE_ON:
-                       *enable = 1;
+                       *enable = true;
                        break;
                default:
                        return -EINVAL;
                }
        } else if (op == PMIC_OP_SET) {
-               switch (*enable) {
-               case 0:
-                       on_off = OPMODE_OFF;
-                       break;
-               case 1:
+               if (*enable)
                        on_off = OPMODE_ON;
-                       break;
-               default:
-                       return -EINVAL;
-               }
+               else
+                       on_off = OPMODE_OFF;
 
                ret = max77686_ldo_mode(dev, op, &on_off);
                if (ret)
@@ -651,16 +645,10 @@ static int max77686_buck_enable(struct udevice *dev, int op, bool *enable)
                        return -EINVAL;
                }
        } else if (op == PMIC_OP_SET) {
-               switch (*enable) {
-               case 0:
-                       on_off = OPMODE_OFF;
-                       break;
-               case 1:
+               if (*enable)
                        on_off = OPMODE_ON;
-                       break;
-               default:
-                       return -EINVAL;
-               }
+               else
+                       on_off = OPMODE_OFF;
 
                ret = max77686_buck_mode(dev, op, &on_off);
                if (ret)
--

2.7.0.rc3

Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

--

Quoted 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

--
Tom

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
author
#6 lore raw
In reply to Tom Rini
Quoted 9 lines · Tom Rini

With gcc-5.3 we get a warning for using switch() on a bool type. Rewrite these sections as if/else and update the one section that was using 1/0 instead of true/false.

Reworded the subject and applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160119/da783e1f/attachment.sig>