From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 1AF861DE3B7 for ; Thu, 19 Feb 2026 15:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771515825; cv=none; b=PbqE+Bu1xfmuntN+gQu6p+/mr/UoTDnWibLzwd/gIY/Laqiw7aO/keN27H3oDlFUPtDotMd43dfP++2qGl6wi/tOxvg+zLsgvE4E1wxyXjfa+DbE0XzVaggLT05faglJuNzXsczDjSU45xQei5+GpVSCqr0s2Y/eIYZYZOld4CY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771515825; c=relaxed/simple; bh=k/mZGNFbYJVGUQLTPBRFxzyhjOSMNfSriHKxNk3JQbE=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Jtt7wrQli5YiGjeJx0jbvEA64ucIFov78/8Rk6J6s9lhO5+m4Afen1yluFQYMtmIrlV0n+I4WOkcB1sa8f1d2HdtRyXsEADhP68siUkir8ne0g/H+JBW5/ghdktb1F0debm/hmSI1JF9y3iCgCRboOhuH6lkSCWYdA3qifQTTMc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--gnoack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TkREOPF1; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--gnoack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TkREOPF1" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-483a24db6ecso7758875e9.1 for ; Thu, 19 Feb 2026 07:43:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771515822; x=1772120622; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=UNR1MuA+Pyvpko/0Fgd9uDMMRmZKO2L4hGIPiJga7R0=; b=TkREOPF1f7aK6uaELhccsskPpizIQ+FLcvP9pJtrchXRj6UkdU3bJAExL096AjhxRH XYb1Uzmbm0zIO5XHk+7mKU06vAngVASQMBGn8FdNX26WToa2TqMCE9+9dwrzjEeCkGWQ AoOZgxKvLOCZh+TmT8PYJSP2Bs4Je7ogWiBQHoUQs1N86WmdFEL9mA/giuOBDUNSk4Bz Fa6EpslYG1FHldC+/LWF4ZDylhSpDzPaSz0Plnur2Rme4xRbuirjpl+xNrg6dk0ArGVm p83Th3LuqHo3vmFqqtzx7jpa7Y86bJFVS2EDErGeSisTykRctVzduRgEBequ0LUikwEa IcaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771515822; x=1772120622; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UNR1MuA+Pyvpko/0Fgd9uDMMRmZKO2L4hGIPiJga7R0=; b=dKYt5lSsjaH+PZU74L+ytS0MIE8V58JQGYL6rNZtCdOVMc6D6x3NIb+KNsB5aj+48v TKmd7byTpkCTv1pkBzUtYdxyIFFHQ4FSIUik6gyswWQJFJbH52HEZVcvV7dkt15mdBrg 000DZH/bB08bBDy+HMnk2KOD3zzO3MbKcBwM+dJZr0v2b7p9JA+TDiGQmbDKNnmWzhgV pJQpRICrvVxbFduJ/XDYSVLMc6D7WJP3dLV/eNpBlWoqSfOxrcCMnqcsNoKFZ6YEot2d tADA494Sto/4yfHd9rQ94xtGDTyTCSKLTLUDnF9YC+Cbj0lLUxrVBIHFZ3/SFlROJZOO aryw== X-Forwarded-Encrypted: i=1; AJvYcCUrBK7PaueCeSvQGluCJA+kznlObzKOjOGCmftV5QBQTtZCGK/IxonuL5KBWJF/Qd5czC+hI3rcWqwkJF0=@vger.kernel.org X-Gm-Message-State: AOJu0YygTEcRu58jh7U8OaBx0ccMBFBYvlnl69DBPbHeIJVEJ5xhLryR 4Q3Ipk1AMKBzBrT6ZROS2c3CsBqKPTr/7DHgXtW2rXFe1IONWxI/bvrxVmL9wOROAXg45b4zGye eDj+ikg== X-Received: from wmhj10.prod.google.com ([2002:a05:600c:300a:b0:480:4a03:7b59]) (user=gnoack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:310d:b0:47e:e57d:404 with SMTP id 5b1f17b1804b1-48398b0acdcmr119294285e9.16.1771515821777; Thu, 19 Feb 2026 07:43:41 -0800 (PST) Date: Thu, 19 Feb 2026 16:43:34 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.371.g1d285c8824-goog Message-ID: <20260219154338.786625-1-gnoack@google.com> Subject: [PATCH v2 0/4] HID: Fix some memory leaks in drivers/hid From: "=?UTF-8?q?G=C3=BCnther=20Noack?=" To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, "=?UTF-8?q?G=C3=BCnther=20Noack?=" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello! These patches fix a few memory leaks in HID report descriptor fixups. FWIW, a good ad-hoc way to look for usages of allocation functions in these is: awk '/static.*report_fixup.*/,/^}/ { print FILENAME, $0 }' drivers/hid/hi= d-*.c \ | grep -E '(malloc|kzalloc|kcalloc|kmemdup)' The devm_* variants are safe in this context, because they tie the allocated memory to the lifetime of the driver. For transparency, I generated these commits with Gemini-CLI, starting with this prompt: We are working in the Linux kernel. In the HID drivers in `drivers/hid/hid-*.c`, the `report_fixup` driver hook is a function that gets a byte buffer (with size) as input and that may modify that byte buffer, and optionally return a pointer to a new byte buffer and update the size. The returned value is *not* memory-managed by the caller though and will not be freed subsequently. When the `report_fixup` implementation allocates a new buffer and returns that, that will not get freed by the caller. Validate this assessment and fix up all HID drivers where that mistake is made. (and then a little bit of additional nudging for the details). =E2=80=94G=C3=BCnther --- Revision history: V2: * Add a commit documenting the memory allocation properties of report_fix= up(). * Reword the commit message for the three memory leak fixes. V1: Original patch set https://lore.kernel.org/all/20260217160125.1097578-1-gnoack@google.com/ G=C3=BCnther Noack (4): HID: Document memory allocation properties of report_fixup() HID: apple: avoid memory leak in apple_report_fixup() HID: magicmouse: avoid memory leak in magicmouse_report_fixup() HID: asus: avoid memory leak in asus_report_fixup() drivers/hid/hid-apple.c | 4 +--- drivers/hid/hid-asus.c | 15 +++++++++++---- drivers/hid/hid-magicmouse.c | 4 +--- include/linux/hid.h | 6 ++++++ 4 files changed, 19 insertions(+), 10 deletions(-) --=20 2.53.0.371.g1d285c8824-goog