A few small cleanups on top of the comms changes for applesmc.c :

send_byte() is always called with APPLESMC_CMD_PORT, so simplify.
Remove redundant check from smc_sane().
Consolidate writing length with other setup parameters.
Consolidate read and write error messages to a single statement each.

Length and error consolidation suggested by Henrik Rydberg <rydb...@bitmath.org>

Signed-off-by: Brad Campbell <b...@fnarfbargle.com>

Index: linux-stable/drivers/hwmon/applesmc.c
===================================================================
--- linux-stable.orig/drivers/hwmon/applesmc.c
+++ linux-stable/drivers/hwmon/applesmc.c
@@ -176,7 +176,7 @@ static int wait_status(u8 val, u8 mask)
 
 /* send_byte - Write to SMC data port. Callers must hold applesmc_lock. */
 
-static int send_byte(u8 cmd, u16 port)
+static int send_byte(u8 cmd)
 {
        int status;
 
@@ -186,7 +186,7 @@ static int send_byte(u8 cmd, u16 port)
        status = wait_status(SMC_STATUS_BUSY, SMC_STATUS_BUSY);
        if (status)
                return status;
-       outb(cmd, port);
+       outb(cmd, APPLESMC_DATA_PORT);
        return 0;
 }
 
@@ -219,10 +219,7 @@ static int smc_sane(void)
        ret = send_command(APPLESMC_READ_CMD);
        if (ret)
                return ret;
-       ret = wait_status(0, SMC_STATUS_BUSY);
-       if (!ret)
-               return ret;
-       return -EIO;
+       return wait_status(0, SMC_STATUS_BUSY);
 }
 
 static int send_argument(const char *key)
@@ -230,7 +227,7 @@ static int send_argument(const char *key
        int i;
 
        for (i = 0; i < 4; i++)
-               if (send_byte(key[i], APPLESMC_DATA_PORT))
+               if (send_byte(key[i]))
                        return -EIO;
        return 0;
 }
@@ -245,23 +242,14 @@ static int read_smc(u8 cmd, const char *
        if (ret)
                return ret;
 
-       if (send_command(cmd) || send_argument(key)) {
-               pr_warn("%.4s: read arg fail\n", key);
-               return -EIO;
-       }
-
-       /* This has no effect on newer (2012) SMCs */
-       if (send_byte(len, APPLESMC_DATA_PORT)) {
-               pr_warn("%.4s: read len fail\n", key);
-               return -EIO;
-       }
+       if (send_command(cmd) || send_argument(key) || send_byte(len))
+               goto err;
 
        for (i = 0; i < len; i++) {
                if (wait_status(SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY,
-                               SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY) < 
0) {
-                       pr_warn("%.4s: read data[%d] fail\n", key, i);
-                       return -EIO;
-               }
+                               SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY))
+                       goto err;
+
                buffer[i] = inb(APPLESMC_DATA_PORT);
        }
 
@@ -277,6 +265,9 @@ static int read_smc(u8 cmd, const char *
                pr_warn("flushed %d bytes, last value is: %d\n", i, data);
 
        return wait_status(0, SMC_STATUS_BUSY);
+err:
+       pr_warn("read cmd fail: %x %.4s %d\n", cmd, key, len);
+       return -EIO;
 }
 
 static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
@@ -288,24 +279,17 @@ static int write_smc(u8 cmd, const char
        if (ret)
                return ret;
 
-       if (send_command(cmd) || send_argument(key)) {
-               pr_warn("%s: write arg fail\n", key);
-               return -EIO;
-       }
+       if (send_command(cmd) || send_argument(key) || send_byte(len))
+               goto err;
 
-       if (send_byte(len, APPLESMC_DATA_PORT)) {
-               pr_warn("%.4s: write len fail\n", key);
-               return -EIO;
-       }
-
-       for (i = 0; i < len; i++) {
-               if (send_byte(buffer[i], APPLESMC_DATA_PORT)) {
-                       pr_warn("%s: write data fail\n", key);
-                       return -EIO;
-               }
-       }
+       for (i = 0; i < len; i++)
+               if (send_byte(buffer[i]))
+                       goto err;
 
        return wait_status(0, SMC_STATUS_BUSY);
+err:
+       pr_warn("write cmd fail: %x %.4s %d\n", cmd, key, len);
+       return -EIO;
 }
 
 static int read_register_count(unsigned int *count)

Reply via email to