A couple of small cleanups on top of the comms changes for applesmc.c : send_byte() is always called with APPLESMC_CMD_PORT. Consolidate writing length with other setup parameters. Consolidate read and write error messages to a single statement each. Suggested-by: Henrik Rydberg <rydberg@xxxxxxxxxxx> Signed-off-by: Brad Campbell <brad@xxxxxxxxxxxxxxx> --- Changelog : v1 : Initial cleanup v2 : Re-work to suit smc-comms rework v6 Index: linux-stable/drivers/hwmon/applesmc.c =================================================================== --- linux-stable.orig/drivers/hwmon/applesmc.c +++ linux-stable/drivers/hwmon/applesmc.c @@ -182,7 +182,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; @@ -199,7 +199,7 @@ static int send_byte(u8 cmd, u16 port) if (status) return status; - outb(cmd, port); + outb(cmd, APPLESMC_DATA_PORT); return 0; } @@ -240,7 +240,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; } @@ -255,23 +255,13 @@ 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)) { - 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); } @@ -287,6 +277,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) @@ -298,24 +291,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_byte(len, APPLESMC_DATA_PORT)) { - pr_warn("%.4s: write 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 (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)