Skip to content

Commit e3e8ded

Browse files
committed
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fix from Guenter Roeck: "Fix root cause of crash/error seen in applesmc driver" * tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (applesmc) Always read until end of data
2 parents 2d9d028 + 25f2bd7 commit e3e8ded

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/hwmon/applesmc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,15 @@ static int send_argument(const char *key)
230230

231231
static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
232232
{
233+
u8 status, data = 0;
233234
int i;
234235

235236
if (send_command(cmd) || send_argument(key)) {
236237
pr_warn("%.4s: read arg fail\n", key);
237238
return -EIO;
238239
}
239240

241+
/* This has no effect on newer (2012) SMCs */
240242
if (send_byte(len, APPLESMC_DATA_PORT)) {
241243
pr_warn("%.4s: read len fail\n", key);
242244
return -EIO;
@@ -250,6 +252,17 @@ static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
250252
buffer[i] = inb(APPLESMC_DATA_PORT);
251253
}
252254

255+
/* Read the data port until bit0 is cleared */
256+
for (i = 0; i < 16; i++) {
257+
udelay(APPLESMC_MIN_WAIT);
258+
status = inb(APPLESMC_CMD_PORT);
259+
if (!(status & 0x01))
260+
break;
261+
data = inb(APPLESMC_DATA_PORT);
262+
}
263+
if (i)
264+
pr_warn("flushed %d bytes, last value is: %d\n", i, data);
265+
253266
return 0;
254267
}
255268

0 commit comments

Comments
 (0)