Skip to contentSkip to conversation

hwmon: (applesmc) Fix smc_sane() function

PATCH In review Dan Carpenter 2 participants 4 messages Nov 17, 2020

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

PATCH 1/1 hwmon: (applesmc) Fix smc_sane() function

This test is reversed so the function will return without sending the APPLESMC_READ_CMD or completing the rest of the function.

Fixes 4d64bb4ba5ec ("hwmon: (applesmc) Re-work SMC comms")
---
 drivers/hwmon/applesmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/applesmc.c +1 -1
index 79b498f816fe..289b39537683 100644
@@ -227,7 +227,7 @@ static int smc_sane(void)
 	int ret;
 
 	ret = wait_status(0, SMC_STATUS_BUSY);
-	if (!ret)
+	if (ret)
 		return ret;
 	ret = send_command(APPLESMC_READ_CMD);
 	if (ret)
Signature · 1 line
2.29.2
#1 lore raw

G’day Dan,

Have you tested that change on hardware?

Sent from an annoyingly small mobile device with no keyboard.

Quoted 28 lines · Dan Carpenter

This test is reversed so the function will return without sending the APPLESMC_READ_CMD or completing the rest of the function.

Fixes 4d64bb4ba5ec ("hwmon: (applesmc) Re-work SMC comms")

---
drivers/hwmon/applesmc.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/applesmc.c +1 -1
index 79b498f816fe..289b39537683 100644
@@ -227,7 +227,7 @@ static int smc_sane(void)
   int ret;
 
   ret = wait_status(0, SMC_STATUS_BUSY);
-    if (!ret)
+    if (ret)
       return ret;
   ret = send_command(APPLESMC_READ_CMD);
   if (ret)
Signature · 1 line
2.29.2
#2 lore raw
In reply to Dan Carpenter
Quoted 2 lines · Dan Carpenter

This test is reversed so the function will return without sending the APPLESMC_READ_CMD or completing the rest of the function.

That is as designed. The routine looks at the busy line and if it's already in the right state then it simply ends. If not then it tries to "re-align" the state machine by sending a new command.

Quoted 20 lines
Fixes 4d64bb4ba5ec ("hwmon: (applesmc) Re-work SMC comms")
---
 drivers/hwmon/applesmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/applesmc.c +1 -1
index 79b498f816fe..289b39537683 100644
@@ -227,7 +227,7 @@ static int smc_sane(void)
 	int ret;
 
 	ret = wait_status(0, SMC_STATUS_BUSY);
-	if (!ret)
+	if (ret)
 		return ret;
 	ret = send_command(APPLESMC_READ_CMD);
 	if (ret)
#3 lore raw
Quoted 7 lines · Brad Campbell
Quoted 2 lines · Dan Carpenter

This test is reversed so the function will return without sending the APPLESMC_READ_CMD or completing the rest of the function.

That is as designed. The routine looks at the busy line and if it's already in the right state then it simply ends. If not then it tries to "re-align" the state machine by sending a new command.

Ah. Ok. It looked like a typo. These "if (!ret) return ret;" typos are surprisingly common so I review them every time they are added. It's a static analysis warning, that I haven't published. I kind of feel like it would be more clearly intentional if it were written like so:

	ret = wait_status(0, SMC_STATUS_BUSY);
	if (!ret)
		return 0;

But I try not to get too bogged down with style so let's leave it.

regards,
dan carpenter