Skip to content

Commit f267b3f

Browse files
rafaeljwUlrich Hecht
authored andcommitted
platform/x86: classmate-laptop: Add missing NULL pointer checks
[ Upstream commit fe747d7112283f47169e9c16e751179a9b38611e ] In a few places in the Classmate laptop driver, code using the accel object may run before that object's address is stored in the driver data of the input device using it. For example, cmpc_accel_sensitivity_store_v4() is the "show" method of cmpc_accel_sensitivity_attr_v4 which is added in cmpc_accel_add_v4(), before calling dev_set_drvdata() for inputdev->dev. If the sysfs attribute is accessed prematurely, the dev_get_drvdata(&inputdev->dev) call in in cmpc_accel_sensitivity_store_v4() returns NULL which leads to a NULL pointer dereference going forward. Moreover, sysfs attributes using the input device are added before initializing that device by cmpc_add_acpi_notify_device() and if one of them is accessed before running that function, a NULL pointer dereference will occur. For example, cmpc_accel_sensitivity_attr_v4 is added before calling cmpc_add_acpi_notify_device() and if it is read prematurely, the dev_get_drvdata(&acpi->dev) call in cmpc_accel_sensitivity_show_v4() returns NULL which leads to a NULL pointer dereference going forward. Fix this by adding NULL pointer checks in all of the relevant places. Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 128e3b0 commit f267b3f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

drivers/platform/x86/classmate-laptop.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ static ssize_t cmpc_accel_sensitivity_show_v4(struct device *dev,
221221

222222
acpi = to_acpi_device(dev);
223223
inputdev = dev_get_drvdata(&acpi->dev);
224+
if (!inputdev)
225+
return -ENXIO;
226+
224227
accel = dev_get_drvdata(&inputdev->dev);
228+
if (!accel)
229+
return -ENXIO;
225230

226231
return sprintf(buf, "%d\n", accel->sensitivity);
227232
}
@@ -238,7 +243,12 @@ static ssize_t cmpc_accel_sensitivity_store_v4(struct device *dev,
238243

239244
acpi = to_acpi_device(dev);
240245
inputdev = dev_get_drvdata(&acpi->dev);
246+
if (!inputdev)
247+
return -ENXIO;
248+
241249
accel = dev_get_drvdata(&inputdev->dev);
250+
if (!accel)
251+
return -ENXIO;
242252

243253
r = kstrtoul(buf, 0, &sensitivity);
244254
if (r)
@@ -270,7 +280,12 @@ static ssize_t cmpc_accel_g_select_show_v4(struct device *dev,
270280

271281
acpi = to_acpi_device(dev);
272282
inputdev = dev_get_drvdata(&acpi->dev);
283+
if (!inputdev)
284+
return -ENXIO;
285+
273286
accel = dev_get_drvdata(&inputdev->dev);
287+
if (!accel)
288+
return -ENXIO;
274289

275290
return sprintf(buf, "%d\n", accel->g_select);
276291
}
@@ -287,7 +302,12 @@ static ssize_t cmpc_accel_g_select_store_v4(struct device *dev,
287302

288303
acpi = to_acpi_device(dev);
289304
inputdev = dev_get_drvdata(&acpi->dev);
305+
if (!inputdev)
306+
return -ENXIO;
307+
290308
accel = dev_get_drvdata(&inputdev->dev);
309+
if (!accel)
310+
return -ENXIO;
291311

292312
r = kstrtoul(buf, 0, &g_select);
293313
if (r)
@@ -316,6 +336,8 @@ static int cmpc_accel_open_v4(struct input_dev *input)
316336

317337
acpi = to_acpi_device(input->dev.parent);
318338
accel = dev_get_drvdata(&input->dev);
339+
if (!accel)
340+
return -ENXIO;
319341

320342
cmpc_accel_set_sensitivity_v4(acpi->handle, accel->sensitivity);
321343
cmpc_accel_set_g_select_v4(acpi->handle, accel->g_select);
@@ -570,7 +592,12 @@ static ssize_t cmpc_accel_sensitivity_show(struct device *dev,
570592

571593
acpi = to_acpi_device(dev);
572594
inputdev = dev_get_drvdata(&acpi->dev);
595+
if (!inputdev)
596+
return -ENXIO;
597+
573598
accel = dev_get_drvdata(&inputdev->dev);
599+
if (!accel)
600+
return -ENXIO;
574601

575602
return sprintf(buf, "%d\n", accel->sensitivity);
576603
}
@@ -587,7 +614,12 @@ static ssize_t cmpc_accel_sensitivity_store(struct device *dev,
587614

588615
acpi = to_acpi_device(dev);
589616
inputdev = dev_get_drvdata(&acpi->dev);
617+
if (!inputdev)
618+
return -ENXIO;
619+
590620
accel = dev_get_drvdata(&inputdev->dev);
621+
if (!accel)
622+
return -ENXIO;
591623

592624
r = kstrtoul(buf, 0, &sensitivity);
593625
if (r)

0 commit comments

Comments
 (0)