From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 968DC199E9D for ; Thu, 20 Nov 2025 14:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763649071; cv=none; b=L/25Dqth5oKhlhia3V7e1GVEe4QTcuPiCSPc+jP5ITabshsM3A4DKDwszjzvtyDyDRjfSzBq/CdJ3YPRsdS2iK0eaxyyX0YhTHEEeQH6DZxZu6UfXECwkNl4O0VdALpRri3uQkZUrfd26L0M5JJyge/pVOBu4BrVIwDjB2+lgLM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763649071; c=relaxed/simple; bh=VjIpb9UGuVBbynzJsGpQLvFYKrdn58W/poFnKCcRyRE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QjItNEjyCqo8ZjBC9pY+XZt00GCEaWEhZiA0pL7fRGCtvOAxNZ1XNSt2bke2PbWTGUz4sDZzMeWkjK2fNA0CzbWlN6Vw9GYj69muMonzz2LTj5C6S+fcPXqiDbVDW3e577zNXtlxajYY+mmlj8ZMjRwDM1wmAGs33mr3dpWNFT4= 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=Nm2TvaVv; arc=none smtp.client-ip=209.85.128.41 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="Nm2TvaVv" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-47755de027eso5667565e9.0 for ; Thu, 20 Nov 2025 06:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763649068; x=1764253868; 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=T73HM0puozBRi2+pOPwiTjM3PEATffqq8BLe2CmdD0Y=; b=Nm2TvaVvz7XwpDY3lR2zHHszmRaUbt3NAiibp2wwOFT+Rh2VrpO0xOhjnfokmRoaYU +2upkzrhOgOfLlZxouUnEcHC0p1Xhi0KxfJvTzZ4sAPOe/97R99QHYrT4g85lbKgEEu2 p1Btwe1ApBZRaPa2XyGSCMkwYCtO/UXG99lUlAanKAnX9UuD+X4pXNRpWE80hPtOC9/4 9N+cOpK0nq+tDDfYgH8h+Jaya0vKybiqKata6/Jud5wAb0TNuZGKLvoVj0sdggcHd9Vu TkntRnFJ+wzOPaRmaNAgf8x2SOpBNoMYYI02cxUMO9sMdjD9yP4Zf/s4Ri+j+IPKOZ/a 4I6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763649068; x=1764253868; 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=T73HM0puozBRi2+pOPwiTjM3PEATffqq8BLe2CmdD0Y=; b=bYCvlrJiU4Ch+HzWsTLoUgEB+QP4yOSkRhNzSegk+SHJuO5Oy3ufAfp7O5QUNJ8Mno EZlKM6+v0T1gQlMTI0v2DLNpgnecvC45TRuHUE78GYOLt7yaxl3c+G5dyrANgIad29zs CsS7GSFGH66jR8ZRob0WTUhl1ysM8lnr505zfT99308ISJ4bybP+tuQIOQSvd6r0oymb 6183LP/XUabjXrC3Nr/Adf7oZRpm1cuCwdxPHiccl3jdYykt2JN80B1x3+0Mo9EGA9Ct d/+Umjz+XzDKrg3erlWt5d/h3iseAywwcKpGdJgcuBTpbbQAOfqqNIKB2t5gS9nEN+NM KjWA== X-Gm-Message-State: AOJu0YyEnIXOQ5XqlQ8KvYh4IfyP39yeW9MYWjven1H3tddzhh6Cmxih efUuXl+nlvaY+dDSvzXKLI1G1w7vx5q9ysMCuTy2qFsSfqsB7p4Jtw8G X-Gm-Gg: ASbGncsxEiYEtHviNAYls5qrjqcMfrgv58IeswY0QpC64GqpZgjK1uIKpsdVLsavAQX ncK5/KDwpkmh7oM1J1Jspsj8FcuFyzW5AoJc9pl6EvNEIIYA21m1as0+tn5jd4lmiBHpRfA37NP 9CYG8VrgdKx48fwXvOBwvyP65Y3lIj3uzpzQ0Rz2X7+nrcTNRK9dTdLKPmys0hejcSdJRK1N4ar 37ks2KhrFEUH6UHHBAdKuoNZTS8kjbT0izZz/ynX9N0trbnW0gXgAnaEoien/GSRQxf4uc9zsxH CgLVJOs7Vt6LWsrBopKzat0B67JSqfDjzFTjve7gpcUfApH4XVxtV+dhqgpfY/Nwrtnao8its1/ RG/+xlk8xJoerWkD+fJvWROGIK4ZJRAlqFZxHld8glI5L6X6LWyFILOGPo5bfPstC7DgLO00lDX 9qi6Gihs0s6hsJ3QC6VnSf+Gs= X-Google-Smtp-Source: AGHT+IHllMaFM9RYyCxrxpU/uPalPcB+kKn6aFhED520P2mWS73tM93EHdi0KqQ9Y/EiHt6hgx2JuQ== X-Received: by 2002:a05:600c:1c97:b0:477:9cc3:7971 with SMTP id 5b1f17b1804b1-477b8a98ec2mr36555785e9.20.1763649067701; Thu, 20 Nov 2025 06:31:07 -0800 (PST) Received: from [192.168.1.121] ([176.206.93.222]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477b82cc6b9sm51345235e9.3.2025.11.20.06.31.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Nov 2025 06:31:07 -0800 (PST) Message-ID: <6a34198c-aceb-46cb-b84e-c49e4f529907@gmail.com> Date: Thu, 20 Nov 2025 15:31:06 +0100 Precedence: bulk X-Mailing-List: platform-driver-x86@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 Cc: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org, 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> <967761fb-3f55-4d51-be0b-23ad03258eff@gmail.com> Content-Language: en-US, it-IT, en-US-large From: Denis Benato In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/20/25 15:28, Antheas Kapenekakis wrote: > On Thu, 20 Nov 2025 at 15:15, Denis Benato wrote: >> >> 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. > It was ambiguous. I interpreted Ilpo's email as a dismissal > > I will try to incorporate it if I do another revision. Although I do > not think it improves things in this case as the function does not > have multiple return statements. I will leave this decision to Ilpo, if he thinks there is no point in using __free here I will add my Reviewed-by tag. >>> + 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; >>> } >>>