From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 7D46930DD21 for ; Thu, 20 Nov 2025 14:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763648141; cv=none; b=Xdc/e9KU5gDXgx47CJzyBDKO5JRIdtFiIqX5sT6dq4H0iuCT+NLd2CBPX70htdVZfT+szRfbOBbZf3/eiKjj+ol7gVn59PG7ZJqJ0y5+xxKUkSK3L6Cx3pgX21kWdQkKBkwXKhVcMR57cOjNTRC4JqBq4QSdScTxSNebKwtZTKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763648141; c=relaxed/simple; bh=urNdyCZGES9rDj9ot6owCD8pdVfj5QPi//ZrMRJQUaI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KhKOgOZV8alGt0bvk/eFfqcNONOXHmMsxJU510YKRSopY34Z2fkl+scZzzF12GUwVC+prOnw21btpjF+aYWEmzXKKn+add2gRl86rZG/cYxUwNLG+AZHqCPahHVyHAjiDIWbiuGGsAkWiHh7EkTttDV2nGfGjVKD1mFPWS7g9YU= 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=J6rR0j86; arc=none smtp.client-ip=209.85.128.42 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="J6rR0j86" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-477a1c28778so11370755e9.3 for ; Thu, 20 Nov 2025 06:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763648138; x=1764252938; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=EdstboqPRYhjDwOMgRMYhYZ1S+MFFDi0TIYa6oOlKJg=; b=J6rR0j864i2Ns2RKc6vRk/uEqhzYtEeO5YlPRa5IgE9o8AEWA0ZrwIDA3GI+C7oNx2 slX0Gmy4xJWTyql1rpZO4ZkNxSnj8E4J7oDkQvVhoYAfiRXI7voxLZN+PCJ6oti4EpTb NgavtkvkSv+lHmHxd5IMhL5d9j0l8/nCXituFKbnr5bOWlzSuvYEnsCTZ6EQaeh4UNN6 7AY+t8cG+Fa3Me/UFq0j2unUOuRkbLm2UhVgZ/K1eyM60uIGN8mwqLYKzbrDp2PrWW8N 83xyQsIL+R1xfx620hOnVitRfbm4OQaZn9fCGgrxcaibcIrC2V+ncS3YHMrTVQ8YiuEw cA0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763648138; x=1764252938; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EdstboqPRYhjDwOMgRMYhYZ1S+MFFDi0TIYa6oOlKJg=; b=Wkklo/f9sU0X+Tizi7APAh88cZWOR2IxvTuKX56uxkbvm0u1wfhlSAA1k0Z8Zoe9rS NjU2xpKGRJsBmlwqmS7p6vW66f0cLBFVS/7tKsRMI9UOAlxwDbXLVDAx1gllJBdxR6Z5 zrag0EbPpYVFAQ/s2ZCKkaY/MN3ldrdzUkdVn0Afjh4Q5xmgpDg9ZYeF+6flzhguM/El WPNJBr7u1yE3ZkAD9cyTwCGgF075GcnJ0a3llmfi7TdFDNWYOVpZ+4quDZsztBr+Q8bK UMSmj9WZH/snac0M+rVLtH4uBm5gybTHl8IgxR2KyrFQY9TPBW07tXevc3zjbEqEWi9t HjRw== X-Gm-Message-State: AOJu0Yxfs8II9iTyspyb4+WoWSgmSN/MuMF8KcfEh8LWw64xF+Ey6BmB HD21VlMJvg377iIake2TjvyxbvBuHvQnDoQn+1kZWv5TSSGH5xudSscN X-Gm-Gg: ASbGnctcc36U0rtI5kYNbp9iiKDVwEAOSVfieSqI+7UrLPgT71OLLXNX5GsljKYBb1b zF1OMGSBxKKgzjW8zqs6pPXOUKk1j11pIbUjBAwXPI9xpvnV/99RUIdj+3q8GY2QnpBmA/Vj/tH 2oVzqb1GltggGn7vmFdgnyld9wOhV79YdKkQzS7QbRDpIITuJ2C2u8aMRumCeyq9nEKdO+e9nsG Ra9T/5Jq9O3oqGvfdGGfAzvNMbaJH6eY82/Dx4UPLO2N9ZzjfinzHtrSQUfp++j85UjEbHTfjHI 3OFE2VxbKQkvwzXrVLIOhMHDZBnVkNymi53Bwcy5jOuJtPORTEvU3kc7f3ridwJcXMaP+8jNesp q3NX0JZ5PkUHl3sCY5jMo1KA/vLUSZoDGXbVLC9vGEvKpOLEMk+db0IPDaUshc1KU7pOJe6GS/C Y3u5qfaEXgvuhLQX1FtxZ22iE= X-Google-Smtp-Source: AGHT+IHYCLxUUzMfIqKz+6vD/bwGFHltG0yeTPVBP3wciZeAXZG6KpFdnBXT/VaaV2Nu5EPMcWPgng== X-Received: by 2002:a05:600c:474a:b0:471:14b1:da13 with SMTP id 5b1f17b1804b1-477b8a53aedmr32233975e9.14.1763648137303; Thu, 20 Nov 2025 06:15:37 -0800 (PST) Received: from [192.168.1.121] ([176.206.93.222]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477a97213b8sm65019255e9.1.2025.11.20.06.15.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Nov 2025 06:15:36 -0800 (PST) Message-ID: <967761fb-3f55-4d51-be0b-23ad03258eff@gmail.com> Date: Thu, 20 Nov 2025 15:15:36 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 04/11] HID: asus: fortify keyboard handshake To: Antheas Kapenekakis , platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= References: <20251120094617.11672-1-lkml@antheas.dev> <20251120094617.11672-5-lkml@antheas.dev> Content-Language: en-US, it-IT, en-US-large From: Denis Benato In-Reply-To: <20251120094617.11672-5-lkml@antheas.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/20/25 10:46, Antheas Kapenekakis wrote: > Handshaking with an Asus device involves sending it a feature report > with the string "ASUS Tech.Inc." and then reading it back to verify the > handshake was successful, under the feature ID the interaction will > take place. > > Currently, the driver only does the first part. Add the readback to > verify the handshake was successful. As this could cause breakages, > allow the verification to fail with a dmesg error until we verify > all devices work with it (they seem to). > > Since the response is more than 16 bytes, increase the buffer size > to 64 as well to avoid overflow errors. > > Signed-off-by: Antheas Kapenekakis > --- > drivers/hid/hid-asus.c | 32 +++++++++++++++++++++++++++++--- > 1 file changed, 29 insertions(+), 3 deletions(-) > > diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c > index 6de402d215d0..5149dc7edfc5 100644 > --- a/drivers/hid/hid-asus.c > +++ b/drivers/hid/hid-asus.c > @@ -48,7 +48,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); > #define FEATURE_REPORT_ID 0x0d > #define INPUT_REPORT_ID 0x5d > #define FEATURE_KBD_REPORT_ID 0x5a > -#define FEATURE_KBD_REPORT_SIZE 16 > +#define FEATURE_KBD_REPORT_SIZE 64 > #define FEATURE_KBD_LED_REPORT_ID1 0x5d > #define FEATURE_KBD_LED_REPORT_ID2 0x5e > > @@ -394,14 +394,40 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bu > > static int asus_kbd_init(struct hid_device *hdev, u8 report_id) > { > + /* > + * The handshake is first sent as a set_report, then retrieved > + * from a get_report. They should be equal. > + */ > const u8 buf[] = { report_id, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54, > 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 }; > + u8 *readbuf; > int ret; > > ret = asus_kbd_set_report(hdev, buf, sizeof(buf)); > - if (ret < 0) > - hid_err(hdev, "Asus failed to send init command: %d\n", ret); > + if (ret < 0) { > + hid_err(hdev, "Asus failed to send handshake: %d\n", ret); > + return ret; > + } > + > + readbuf = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL); I see my suggestion to use __free here didn't materialize in code using it even after Ilpo kindly wrote how to correctly use it. I think you can move the readbuf assignment right below buf and take into account what Ilpo said. I don't expect new variables will be added here ever again, but I agree with Ilpo that it's a good idea here to write code accounting for that possibility. It is my understanding that who proposes patches is expected to resolve discussions when changes are proposed or to take into account requested changes and submit a modified version. > + if (!readbuf) > + return -ENOMEM; > + > + ret = hid_hw_raw_request(hdev, report_id, readbuf, > + FEATURE_KBD_REPORT_SIZE, HID_FEATURE_REPORT, > + HID_REQ_GET_REPORT); > + if (ret < 0) { > + hid_err(hdev, "Asus failed to receive handshake ack: %d\n", ret); > + } else if (memcmp(readbuf, buf, sizeof(buf)) != 0) { > + hid_warn(hdev, "Asus handshake returned invalid response: %*ph\n", > + FEATURE_KBD_REPORT_SIZE, readbuf); > + /* > + * Do not return error if handshake is wrong until this is > + * verified to work for all devices. > + */ > + } > > + kfree(readbuf); > return ret; > } >