From patchwork Thu Jan 26 00:24:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13116435 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85A6BC54EAA for ; Thu, 26 Jan 2023 00:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbjAZAZY (ORCPT ); Wed, 25 Jan 2023 19:25:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235840AbjAZAZW (ORCPT ); Wed, 25 Jan 2023 19:25:22 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 340F864683 for ; Wed, 25 Jan 2023 16:25:20 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id ud5so1139596ejc.4 for ; Wed, 25 Jan 2023 16:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rBEBor+gnsfUYPOUW+OLBqnWMEjDoXQsh85+8ApHEhw=; b=kYwY+kVYV/Q1HAOK4nSWSqU2aS/vnszT5DoWgnuvCPJlFXba9yQLFA32M1r81JvmLW k1po+3OJS2h04DoboLdK9AkYAfNIgjf6/OU6G6hwVSzXajteF2EdZ9HvGJFRvNheNsBh r938rP9fDZbvnBT/zlgk1G3bNX5iZ4ZLw0/Qg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rBEBor+gnsfUYPOUW+OLBqnWMEjDoXQsh85+8ApHEhw=; b=V/+p4yjN8MOs6aD073xSA1TYBQ8XccVxX0ZmPNBTmaNx/Iv/mfW/QDF2JcUrp3K0Sw BIoA3amACau6INYm2NJYQfSk/CN9PjceIb3KoowBs+dHpF+vDgnt6KrmMRVJGehQOh1+ gT4golws+/f0ixFY2IrWipXHT5S5rZHyE1p7h4tRjisMutFUD86/PV5FOpMb78qX2H8T myt1lTdpFu6Ar3Vrx5j20kFHuql9fpZWFib0I63m9Kqb0TXGxQ7B4yXmuCAeUsTy/1vK jeqWjCXaxkNJkmObS5nu4ZeZkydl6e7UUa5H5b0PQFt4162eE61U2RsR1bX/YBwDuDHg qBmA== X-Gm-Message-State: AFqh2kq66i4c3YmUnpw9dS6MPWqEEaQcqbZpt0uST4FfIIYBYQDakPiV kBiHTQBJOpX02cWvLBSEy4Zdzg== X-Google-Smtp-Source: AMrXdXvJIC2UGnr/1hfI3axwW49AFykjf04VfF8qw+mj4LupHpC31heF7B0mpWUctTgn/O1q9rIN/A== X-Received: by 2002:a17:906:6c97:b0:870:34c:97cd with SMTP id s23-20020a1709066c9700b00870034c97cdmr36269656ejr.25.1674692718718; Wed, 25 Jan 2023 16:25:18 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id jy12-20020a170907762c00b008784e808553sm555707ejc.6.2023.01.25.16.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 16:25:18 -0800 (PST) From: Pietro Borrello Date: Thu, 26 Jan 2023 00:24:57 +0000 Subject: [PATCH 5/5] HID: sony_remove: manually unregister leds MIME-Version: 1.0 Message-Id: <20230125-hid-unregister-leds-v1-5-9a5192dcef16@diag.uniroma1.it> References: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> In-Reply-To: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Hanno Zulla , Carlo Caione , Pavel Machek , Lee Jones , Roderick Colenbrander , Sven Eckelmann Cc: linux-leds@vger.kernel.org, Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Roderick Colenbrander , Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1674692715; l=1310; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=ZOrIdJOdwJPCFoQ8po11GD9ZIwbv+SiF+0joUOhG2lc=; b=yDx0s+P1ZVx5mqJlSm2mB+LHUgB4rhTcR2ZrYHpbnNZXiW2UzAypHnRsFGPsPUP2VDdK7g70wdPh 6a6ui0PpAfe1uO8u0jYA4LK0oT6VyntdmYWUHPnsYRHg9jDtnQJr X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Unregister the LED controller before device removal, as sony_led_set_brightness() may schedule sc->state_worker after the structure has been freed, causing a use-after-free. Fixes: 0a286ef27852 ("HID: sony: Add LED support for Sixaxis/Dualshock3 USB") Signed-off-by: Pietro Borrello Reviewed-by: Sven Eckelmann --- drivers/hid/hid-sony.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 13125997ab5e..146677c8319c 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -3083,6 +3083,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) static void sony_remove(struct hid_device *hdev) { struct sony_sc *sc = hid_get_drvdata(hdev); + int n; if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) { del_timer_sync(&sc->ghl_poke_timer); @@ -3100,6 +3101,13 @@ static void sony_remove(struct hid_device *hdev) if (sc->hw_version_created) device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); + if (sc->quirks & SONY_LED_SUPPORT) { + for (n = 0; n < sc->led_count; n++) { + if (sc->leds[n]) + devm_led_classdev_unregister(&hdev->dev, sc->leds[n]); + } + } + sony_cancel_work_sync(sc); sony_remove_dev_list(sc);