From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C49F83FBB4F for ; Fri, 15 May 2026 15:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778859379; cv=none; b=lOVIP62mIrNIIbuhr2NL6yD2cBP9dbvHejJTnwTVWRT6YjBzzwodpqB5l3eMPsB80VOT0d2bwf1gJfdeyZW0FE6rQ4zQgAtIEaNybOsRxU7p+KD7z8EHztx91VisXjedHw47Sw7lClc599xn2Ltri0Nh+KK+g5/0A2YSf6fUq8s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778859379; c=relaxed/simple; bh=OpIq0AuK/NgSg/YHv3ys7p5ccwDBrLi/kqUfTEcAc5U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bSc/h7MA3ZhZT8wLI9E4mkpgnmjQzMf9mmQ7eO9pn35kYzAFszMajDB2k9ifdBqF22rsUCFdJrrqoUQFUPt1SoshaUVd7RiqKOq20oDiSbx0a56UrqtjwWiPUBqahxVZaz3nTXil6Ig84ZzUo/jL3AMc+3Wq5q+1sOmTO24Dfj0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FgW3OpPu; arc=none smtp.client-ip=74.125.82.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FgW3OpPu" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-30246cfd41aso5179552eec.1 for ; Fri, 15 May 2026 08:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778859376; x=1779464176; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vVj2OPx9OWN6THjcTj10qqvXFzA0offMmw+VDODEVjs=; b=FgW3OpPu3RokCuLW1AY8A1txASKChiXaO1UDVO7xAzXEkd0nDGmSC/E0CEdIon2m7F hGyBWUp0mqyfmEbKMOatSdqfB5vQntIYhJyzQPIQRYQcAZZVcLUlBQwbbbJAqNQ4AtmH EFxB7h3l1jwr+guabC8OQ6Qp9hqaIf1WpoYkEZ+y7Mk4vrMi+QR11xD4dpKSxX8KgSI0 Jdk4iLW+Z6/4uhcRFpcygRmY5m5sT2HYj7Jjp7Yn8f0LcRvEPF+eys6ye4oyC159buuH 2OplJXAiWCEui3z4Va27FIn1QhOJOl+dQ1njErgu9/oWfKCdaxbn5a8yLKmw3+HJIq18 +P3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778859376; x=1779464176; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vVj2OPx9OWN6THjcTj10qqvXFzA0offMmw+VDODEVjs=; b=bXLFIjvWnp1Qv3G3+6+tG4FEGzSt+ZP0ZdpYq9y1ixPpwTPs4cn7FtFbSWQbBHWeV/ zFP8UCsDEq825RyoRYFO0vZh3p7QhW+sEbgbIMAyzeum+K6xDpIjWMdWmAJQ9qiMekuc phT9IFxca/HvjmIL/W+G6tj4eNHLmsKjrMyO62CpA7HSwLC2JNUhmGCif2UmBUby3FoG PfvY/L40hfccSpdXeS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a478bee46e88-303986d6026mr2291069eec.35.1778859375353; Fri, 15 May 2026 08:36:15 -0700 (PDT) Received: from lima-kernel-dev.google.com (ec2-13-52-214-175.us-west-1.compute.amazonaws.com. [13.52.214.175]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302978b3cb2sm9322064eec.30.2026.05.15.08.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 08:36:14 -0700 (PDT) From: Manish Khadka To: linux-input@vger.kernel.org Cc: "Derek J . Clark" , Mark Pearson , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org Subject: [PATCH] HID: hid-lenovo-go: cancel cfg_setup work in hid_go_cfg_remove() Date: Fri, 15 May 2026 21:21:07 +0545 Message-ID: <20260515153607.76175-1-maskmemanish@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit hid_go_cfg_probe() initialises drvdata.go_cfg_setup and schedules it to run 2 ms later: INIT_DELAYED_WORK(&drvdata.go_cfg_setup, &cfg_setup); schedule_delayed_work(&drvdata.go_cfg_setup, msecs_to_jiffies(2)); cfg_setup() dereferences drvdata.hdev to issue MCU command requests. hid_go_cfg_remove() tears down sysfs and stops the HID device, ending with hid_set_drvdata(hdev, NULL), but never drains the delayed work. If the device is unbound within the 2 ms scheduling delay (a probe failure rolling back via remove, or a fast rmmod after probe), the work fires after hid_set_drvdata(NULL) has cleared the back pointer, leaving cfg_setup() with a NULL or stale drvdata.hdev. Mirror the sibling driver hid-lenovo-go-s.c, whose hid_gos_cfg_remove() already calls cancel_delayed_work_sync() on its analogous work, and drain go_cfg_setup at the top of hid_go_cfg_remove(). The cancel must come before guard(mutex)(&drvdata.cfg_mutex) because cfg_setup() acquires that mutex; reversing the order would deadlock. Fixes: d69ccfcbc955 ("HID: hid-lenovo-go: Add Lenovo Legion Go Series HID Driver") Cc: stable@vger.kernel.org Signed-off-by: Manish Khadka --- drivers/hid/hid-lenovo-go.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/hid/hid-lenovo-go.c b/drivers/hid/hid-lenovo-go.c index d4d26c783356..ef69869f0a00 100644 --- a/drivers/hid/hid-lenovo-go.c +++ b/drivers/hid/hid-lenovo-go.c @@ -2408,6 +2408,13 @@ static int hid_go_cfg_probe(struct hid_device *hdev, static void hid_go_cfg_remove(struct hid_device *hdev) { + /* + * cfg_setup is scheduled from hid_go_cfg_probe() with a 2 ms delay; + * drain it here before tearing down so the workqueue cannot run + * after hid_set_drvdata(NULL) and dereference a stale drvdata.hdev. + */ + cancel_delayed_work_sync(&drvdata.go_cfg_setup); + guard(mutex)(&drvdata.cfg_mutex); sysfs_remove_groups(&hdev->dev.kobj, top_level_attr_groups); hid_hw_close(hdev); -- 2.43.0