From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A55A41CF7D4; Wed, 2 Oct 2024 14:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727878746; cv=none; b=bp4Fj/pMPJOn0H0K1DkZZRzTcqZ49eLXa5lkGQ2Fz+kQvVA0HxGeYTK7r2lf4R3mTsrHy2TWtXHY4lTZDzOMZQZHH2c6Uar0h8sxVGGE6+HLRS6EroAq5pwFrhneySXbwagZQ+HA84PV8/YLrK8Nih0xVMxGlrsIHQ77zu4hTTE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727878746; c=relaxed/simple; bh=1u8hHB9f9VWguE2oUJW40Pr1A50pE1mWkOoZHIbb6RU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K6GfFJwF960SGxW5mYJurZSd/4++u2JOmFoioDN7d1p5Gx8WnodkGtRnnDJusgk1/wlvzH3o8Mo2Ezuf1TgKMCK8CpVfLyodVNEeWnT2urMmgwHI0LCyZtIwLpTlkC0S3SebH8I//1K/1ewpTZX0jim62E27EY5CHORCzzlHJPI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oNZ7HsIA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oNZ7HsIA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EAE0C4CECD; Wed, 2 Oct 2024 14:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1727878746; bh=1u8hHB9f9VWguE2oUJW40Pr1A50pE1mWkOoZHIbb6RU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oNZ7HsIAn0BFOyMcHI1YHGaWUJ5R7vm+1fBtsR1wAhwCgASMNA92Achh+N62SdsHK YMWj34fQloLk7V1xCfq5oJwUeONH6MluAaHsUCEMWjG+iRmbkQlYhLDlPpNw5NuGjn /94qClUE/1eAclgGsNl1ZV2ZoeW4JxzZbm2A6Wyk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Oliver Neukum Subject: [PATCH 6.10 519/634] USB: appledisplay: close race between probe and completion handler Date: Wed, 2 Oct 2024 15:00:19 +0200 Message-ID: <20241002125831.594802881@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241002125811.070689334@linuxfoundation.org> References: <20241002125811.070689334@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oliver Neukum commit 8265d06b7794493d82c5c21a12d7ba43eccc30cb upstream. 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 CC: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240912123317.1026049-1-oneukum@suse.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/appledisplay.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c @@ -107,7 +107,12 @@ static void appledisplay_complete(struct case ACD_BTN_BRIGHT_UP: case ACD_BTN_BRIGHT_DOWN: pdata->button_pressed = 1; - schedule_delayed_work(&pdata->work, 0); + /* + * there is a window during which no device + * is registered + */ + if (pdata->bd ) + schedule_delayed_work(&pdata->work, 0); break; case ACD_BTN_NONE: default: @@ -202,6 +207,7 @@ static int appledisplay_probe(struct usb const struct usb_device_id *id) { struct backlight_properties props; + struct backlight_device *backlight; struct appledisplay *pdata; struct usb_device *udev = interface_to_usbdev(iface); struct usb_endpoint_descriptor *endpoint; @@ -272,13 +278,14 @@ static int appledisplay_probe(struct usb memset(&props, 0, sizeof(struct backlight_properties)); props.type = BACKLIGHT_RAW; props.max_brightness = 0xff; - pdata->bd = backlight_device_register(bl_name, NULL, pdata, + backlight = backlight_device_register(bl_name, NULL, pdata, &appledisplay_bl_data, &props); - if (IS_ERR(pdata->bd)) { + if (IS_ERR(backlight)) { dev_err(&iface->dev, "Backlight registration failed\n"); - retval = PTR_ERR(pdata->bd); + retval = PTR_ERR(backlight); goto error; } + pdata->bd = backlight; /* Try to get brightness */ brightness = appledisplay_bl_get_brightness(pdata->bd);