Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 6cac446

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 potential crash condition in applesmc driver" * tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (applesmc) Check key count before proceeding
2 parents a7301fc + 5f45138 commit 6cac446

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/hwmon/applesmc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,16 +525,25 @@ static int applesmc_init_smcreg_try(void)
525525
{
526526
struct applesmc_registers *s = &smcreg;
527527
bool left_light_sensor, right_light_sensor;
528+
unsigned int count;
528529
u8 tmp[1];
529530
int ret;
530531

531532
if (s->init_complete)
532533
return 0;
533534

534-
ret = read_register_count(&s->key_count);
535+
ret = read_register_count(&count);
535536
if (ret)
536537
return ret;
537538

539+
if (s->cache && s->key_count != count) {
540+
pr_warn("key count changed from %d to %d\n",
541+
s->key_count, count);
542+
kfree(s->cache);
543+
s->cache = NULL;
544+
}
545+
s->key_count = count;
546+
538547
if (!s->cache)
539548
s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL);
540549
if (!s->cache)

0 commit comments

Comments
 (0)