Fix potential crash condition in applesmc driver

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIcBAABAgAGBQJSRFZjAAoJEMsfJm/On5mBF3oP/2RQ5I2gDzE8BUBsjqjnyJVM
 8dlBhdTmy7K19Rmu1cJAtKqIpBsaMW9r4Z1CYxC/3w0Q9H0lxbn61qxwNmow2iFo
 nn4hNWmm+QD97TTYTeKOFQLNsKNDddBrzy9vk1yODRL9hUcPG9tsYT5xfRKWMK2D
 G5g03vShF4yLiMcrjbhXd+HEbsVBeVydhUdH96ggRzcGLaFOdB1of4sM96in+3KM
 ECMqiS2Dmzyb/eP0SQTuzRd3xJqg0t/MUtP41zrrw0M7Dx5BawfdwCLb16qxR/Cq
 cSxRnifF//mZqapW8m8KDDyMRpX2Y53nZET+2nGOxR5FJh9MROOLKQ3C7knpldxi
 lw94SP5ZTD0q3uben0TSk3JaKuPwIvk5w+r4HcBNsgVLish1lFEt15w0I9CnzBcL
 ORD2hRYUk8fvmGFEmxwppOH5EF+vyGVs6y4yYutL0G+AO+3nyGjLZE3jce9eqvQS
 pu64HBDLa8fEYl5niJpiMC0EbgPWeTf6j7LwRCufmBhECnmX2SO0wTGuNlcFC8/O
 XdLje5uBjGQ1Cw4GItb+QwY4Zr9W9X7CNIzBnNqdMC0AM2fKAVLfK0g8AcMRQm8q
 jmwsBB99VrSgP67vPaj8o9H0ApHfh4JoCD9HrJl5XzNsNUp/goZdthTjIFc7+ygx
 pij5e9IJUzMwqI1W3jcD
 =/G2c
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2013-09-27 10:07:47 -07:00
Родитель a7301fcc12 5f45138643
Коммит 6cac446bd3
1 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -525,16 +525,25 @@ static int applesmc_init_smcreg_try(void)
{
struct applesmc_registers *s = &smcreg;
bool left_light_sensor, right_light_sensor;
unsigned int count;
u8 tmp[1];
int ret;
if (s->init_complete)
return 0;
ret = read_register_count(&s->key_count);
ret = read_register_count(&count);
if (ret)
return ret;
if (s->cache && s->key_count != count) {
pr_warn("key count changed from %d to %d\n",
s->key_count, count);
kfree(s->cache);
s->cache = NULL;
}
s->key_count = count;
if (!s->cache)
s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL);
if (!s->cache)