From nobody Thu Apr 9 16:32:33 2026 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.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 21DCD305064 for ; Sat, 7 Mar 2026 03:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772854214; cv=none; b=FtKavfR3vS7d0LvqhRdFJ7WkjbcfXelRpus6UIUky4v5VlSPVkGuJ5G3jCTnaPYwDFRrp6Nyp/UsDO7Us0CCqD0R7pDfeKJIksoT24nOp9FnhIpfAzDKYl1iupDy+Ak9Ycy5Fn08y4qlKHeoUhapAxV2imdtVA4+Re4j1GXMduc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772854214; c=relaxed/simple; bh=En+FSzjm9b3yZ7RTDdGPtQq3dmB2SMEVaIrfb8fKjrE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oaokzwaW4dTbENnJs547UJyF24JOB4yXAx9uS/VN7oeG/9bCDHIPokniJUG1G1ddb6xGBvtu1EZnK7/m+hYLwRHeRBTyCZ1iqfc0XVDFjRgRpMW/R6CPzqebbSLQBgnsLqU1SPia5slsZXi9EIiN8YivIT7Ihq2SDNcM0f0ary4= 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=ZnPb8aPV; arc=none smtp.client-ip=209.85.216.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="ZnPb8aPV" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-354a18c48b5so8649132a91.1 for ; Fri, 06 Mar 2026 19:30:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772854212; x=1773459012; 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=HUfuF25BN8uUpJXhc6fQg9RcsbS0Xj7nnWqfeLrQ/Xc=; b=ZnPb8aPVEcsSzv3pUQlOjiBvIUeht/OoL4bvLu4RrDvunZjjKW28FRn1v2Su0Z4JPI WZF7fw11LztGRn/vXVVuAwtq7/p6mGEKUZU4ZDinBUcZiWA3ATbHBaCImwuwHkbSleR1 +HIHGvu9yixFMi41wJ//oYDx7gijFs6NIPDhnSiNqQQ9su69VTSx7xNusi7iQe9gjVTE H3k/z2ygPv1FUgS8iRkcgcYu+1gS9abQ3Nnw81dRtItFUTBlstZxu2Hn8NjlRiGo3JWM K8OmIeKtXt+s1ISIEIf0P0kFzxrl6z9HQ/i743yQlxmZki6khpjfLS6PARJ+wTNA2ktN H9tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772854212; x=1773459012; 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=HUfuF25BN8uUpJXhc6fQg9RcsbS0Xj7nnWqfeLrQ/Xc=; b=a6tX/67XHSyQd71yhk7ZmTLKkLcVZ8nexHsfmBsIy0s/H3h4a+JyBsZotm58ai0Jxb 8pl8X//A3unvECutJ0aT0WXW3GJ/Pa9RJDZ8sMobnZU0rL8rV573uOIl20tpFUsut6EK xReGgBxNGSGbuC/3oEVrtp9x4415+D/PTmgzyOGoPEEpMLAmpaMmAjnSKEN88nbQ9fcF 2wb3D+VICNOE7aC+rZCXGpC1kSEg1UaofJ/bkNIoGVRpOt8DRSw5Te8n/Bg7XovV0XYu m+1vPMh0eSIK3Kkd4mslg583V4BOHoXgKtP24Kt64L4S/2X3i3zpcs5Y8w3qpxNV543s mq4Q== X-Forwarded-Encrypted: i=1; AJvYcCUq8FIhiaX1usOov8HbxXbnJeWU1U0RGbZEN41ZrbFc8HvvSFubd6g0AmV7sA4cfwNjEcw2lTLQVQ89tWo=@vger.kernel.org X-Gm-Message-State: AOJu0YzVcxihcu8u0syj9Wv5Fhhd11KcOVS4NlYzrRSyAJSFVr1CI1Np B6bEAbyM7428mbsFZdOQ9jc1hzxABH+9ZLy+GIGUnDdMMyNp4Pvb+F+V X-Gm-Gg: ATEYQzwy2SMpcfeJuzXRr9imnZ58iZry84gVPqa/tlUakFWZ6/XHPLGtcqnAHmPpw0/ pdYYAL0BkGV/dlJVsyoTU+MQ115WH0xO/6BrfZ35Kb5ArW6S1aDohPtIUMqLTDTZyQlUI50bxDO 3RSGD/KH85UHk5YD/qrfgZ4joPWHdHD9QR3G9PCKarwSH+o8vnPmc45lYNMOchBg/+Yo9Y7TH+B 9CCUMnzxl4fHy3K5WDxx6o0G2pbgfEZuNfVoOQW/oxsuByK5tnOK4PLYdQnOExHmnCLeDNKJXm9 UgufH8CZrGmGlkyhfj1gc3k567N9zKooFF8/wNmBTq+QyAPPyMNGC5qP8hJJ+KILhJ4ESe1XhCz EZWHVbBschgha9C1DrKq79JFQUUAHVxedXCcEsmi5xcQnBceFottGHps1/PGD87DQLGlNIh7Qgp 8hb7TU8uiEcb/Ij188xyB1cr4Ud48Mmz4UzXyD6fY2b/H0TbNzJ7GmSfE= X-Received: by 2002:a17:90b:388a:b0:359:87ff:f34f with SMTP id 98e67ed59e1d1-359be2331d6mr4219798a91.3.1772854209474; Fri, 06 Mar 2026 19:30:09 -0800 (PST) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-359c003c51bsm3548732a91.1.2026.03.06.19.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 19:30:09 -0800 (PST) From: Rosen Penev To: linux-input@vger.kernel.org Cc: Jiri Kosina , linux-hardening@vger.kernel.org, gustavoars@kernel.org, Benjamin Tissoires , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] HID: core: use flex array allocation Date: Fri, 6 Mar 2026 19:29:52 -0800 Message-ID: <20260307032952.642014-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of embedding a pointer in the struct, use a flexible array member to avoid the + 1 trick to point to allocation after the struct. Signed-off-by: Rosen Penev --- drivers/hid/hid-core.c | 6 ++---- include/linux/hid.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 840a60113868..6bd6cbf26c6d 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -127,15 +127,13 @@ static struct hid_field *hid_register_field(struct hi= d_report *report, unsigned return NULL; } =20 - field =3D kvzalloc((sizeof(struct hid_field) + - usages * sizeof(struct hid_usage) + - 3 * usages * sizeof(unsigned int)), GFP_KERNEL); + field =3D kvzalloc(struct_size(field, usage, usages) + + 3 * usages * sizeof(unsigned int), GFP_KERNEL); if (!field) return NULL; =20 field->index =3D report->maxfield++; report->field[field->index] =3D field; - field->usage =3D (struct hid_usage *)(field + 1); field->value =3D (s32 *)(field->usage + usages); field->new_value =3D (s32 *)(field->value + usages); field->usages_priorities =3D (s32 *)(field->new_value + usages); diff --git a/include/linux/hid.h b/include/linux/hid.h index 2990b9f94cb5..e2c3e2528582 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -524,7 +524,6 @@ struct hid_field { unsigned physical; /* physical usage for this field */ unsigned logical; /* logical usage for this field */ unsigned application; /* application usage for this field */ - struct hid_usage *usage; /* usage table for this function */ unsigned maxusage; /* maximum usage index */ unsigned flags; /* main-item flags (i.e. volatile,array,constant) */ unsigned report_offset; /* bit offset in the report */ @@ -549,6 +548,7 @@ struct hid_field { struct hid_input *hidinput; /* associated input structure */ __u16 dpad; /* dpad input code */ unsigned int slot_idx; /* slot index in a report */ + struct hid_usage usage[]; /* usage table for this function */ }; =20 #define HID_MAX_FIELDS 256 --=20 2.53.0