Code:
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 0162f55..d0eb86e 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -194,11 +194,11 @@ static int send_command(u8 cmd)
return -EIO;
}
-static int send_argument(const char *key)
+static int send_argument(const char *key, int keylen)
{
int i;
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < keylen; i++) {
outb(key[i], APPLESMC_DATA_PORT);
if (__wait_status(0x04))
return -EIO;
@@ -206,11 +206,11 @@ static int send_argument(const char *key)
return 0;
}
-static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
+static int read_smc(u8 cmd, const char *key, int keylen, u8 *buffer, u8 len)
{
int i;
- if (send_command(cmd) || send_argument(key)) {
+ if (send_command(cmd) || send_argument(key, keylen)) {
pr_warn("%.4s: read arg fail\n", key);
return -EIO;
}
@@ -219,12 +219,14 @@ static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
for (i = 0; i < len; i++) {
if (__wait_status(0x05)) {
- pr_warn("%.4s: read data fail\n", key);
+ pr_warn("%.*s: read data fail\n", keylen, key);
return -EIO;
}
buffer[i] = inb(APPLESMC_DATA_PORT);
}
return 0;
}
@@ -232,7 +234,7 @@ static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
{
int i;
- if (send_command(cmd) || send_argument(key)) {
+ if (send_command(cmd) || send_argument(key, 4)) {
pr_warn("%s: write arg fail\n", key);
return -EIO;
}
@@ -255,7 +257,7 @@ static int read_register_count(unsigned int *count)
__be32 be;
int ret;
- ret = read_smc(APPLESMC_READ_CMD, KEY_COUNT_KEY, (u8 *)&be, 4);
+ ret = read_smc(APPLESMC_READ_CMD, KEY_COUNT_KEY, 4, (u8 *)&be, 4);
if (ret)
return ret;
@@ -278,7 +280,7 @@ static int applesmc_read_entry(const struct applesmc_entry *entry,
if (entry->len != len)
return -EINVAL;
mutex_lock(&smcreg.mutex);
- ret = read_smc(APPLESMC_READ_CMD, entry->key, buf, len);
+ ret = read_smc(APPLESMC_READ_CMD, entry->key, 4, buf, len);
mutex_unlock(&smcreg.mutex);
return ret;
@@ -301,7 +303,7 @@ static const struct applesmc_entry *applesmc_get_entry_by_index(int index)
{
struct applesmc_entry *cache = &smcreg.cache[index];
u8 key[4], info[6];
- __be32 be;
+ __be16 be;
int ret = 0;
if (cache->valid)
@@ -311,11 +313,11 @@ static const struct applesmc_entry *applesmc_get_entry_by_index(int index)
if (cache->valid)
goto out;
- be = cpu_to_be32(index);
- ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, key, 4);
+ be = cpu_to_be16(index);
+ ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, 2, key, 4);
if (ret)
goto out;
- ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, key, info, 6);
+ ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, key, 4, info, 6);
if (ret)
goto out;
Thanks!
Bookmarks