Skip to content

Commit 8265d06

Browse files
oneukumgregkh
authored andcommitted
USB: appledisplay: close race between probe and completion handler
There is a small window during probing when IO is running but the backlight is not registered. Processing events during that time will crash. The completion handler needs to check for a backlight before scheduling work. The bug is as old as the driver. Signed-off-by: Oliver Neukum <[email protected]> CC: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b41c1fa commit 8265d06

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/usb/misc/appledisplay.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ static void appledisplay_complete(struct urb *urb)
107107
case ACD_BTN_BRIGHT_UP:
108108
case ACD_BTN_BRIGHT_DOWN:
109109
pdata->button_pressed = 1;
110-
schedule_delayed_work(&pdata->work, 0);
110+
/*
111+
* there is a window during which no device
112+
* is registered
113+
*/
114+
if (pdata->bd )
115+
schedule_delayed_work(&pdata->work, 0);
111116
break;
112117
case ACD_BTN_NONE:
113118
default:
@@ -202,6 +207,7 @@ static int appledisplay_probe(struct usb_interface *iface,
202207
const struct usb_device_id *id)
203208
{
204209
struct backlight_properties props;
210+
struct backlight_device *backlight;
205211
struct appledisplay *pdata;
206212
struct usb_device *udev = interface_to_usbdev(iface);
207213
struct usb_endpoint_descriptor *endpoint;
@@ -272,13 +278,14 @@ static int appledisplay_probe(struct usb_interface *iface,
272278
memset(&props, 0, sizeof(struct backlight_properties));
273279
props.type = BACKLIGHT_RAW;
274280
props.max_brightness = 0xff;
275-
pdata->bd = backlight_device_register(bl_name, NULL, pdata,
281+
backlight = backlight_device_register(bl_name, NULL, pdata,
276282
&appledisplay_bl_data, &props);
277-
if (IS_ERR(pdata->bd)) {
283+
if (IS_ERR(backlight)) {
278284
dev_err(&iface->dev, "Backlight registration failed\n");
279-
retval = PTR_ERR(pdata->bd);
285+
retval = PTR_ERR(backlight);
280286
goto error;
281287
}
288+
pdata->bd = backlight;
282289

283290
/* Try to get brightness */
284291
brightness = appledisplay_bl_get_brightness(pdata->bd);

0 commit comments

Comments
 (0)