From nobody Tue Apr 7 13:00:54 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.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 133A022B594 for ; Fri, 13 Mar 2026 00:35:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773362116; cv=none; b=knmB5F/BBJMTEObGtVoHlunrLgq+1azxjeDs6CHmDjgU7wMVY50FA+JIb2jl2FtcuQWuU+GaERpRwQy3RziAfR6O2sdQTeaQa7MuXhhvdZL3NJ8ImrKMcFLJVHHCbw3Ju6YSx+9lXYj2c9kB2p14XRTYkjDdm8YdHzzW+vuLA/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773362116; c=relaxed/simple; bh=w+4eBmfvEhip5bCDa4fv8QpZ35nYLDz1KYW1f0RZbes=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MU7WumEI64gtSLKWStNrJtszfuoAMAnHF50NOThV2KQm3zXsVIceAch44M2QKAixBYfe8goBgpUh71viCgLHcz8PcLuGkrrTq8lTxMjtEf5Y4sOQBh0ALBDH70E1BA6Q3q2nPvjYppMUFUqN/ASkjP2+F9pBEtLyEGrO1ZKB3QI= 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=G9gW4T/8; arc=none smtp.client-ip=209.85.210.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="G9gW4T/8" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-829759ca646so982786b3a.2 for ; Thu, 12 Mar 2026 17:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773362113; x=1773966913; 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=5g1oxOZuD0TjRJopzLlGiiDsTi7txtKncHU5UC9/URc=; b=G9gW4T/8oz0UAiw+37C6LcNiL8J9cEKvHyQUdWaG+ZzMoz9UozGsRI76SPcmhQwDuO ahxiJcsMQsieo2UoD8lyRMZxLpl1nuYEDEKDwdUWK0kTp/1nypP/qQ1D+aRQReLii60x skc663FGHYdDnpff/VMUDN6oSEePAhkg0yMFe78g2rNCGlIKb9X82hok3WXS1j0tVAom P8VDPbW+t6fGk0wbaEHvTo0CCq8FA9FhLei5I/bRpGS1qKqAB53wr7+Xo90rh9MaKKvt OCngVtBmhP7u5l5K7FOa5nOhIv11ipPZrUtMBInXfTc0Sb/qGN9CRr9crbQxc7uu4+EP 5YZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773362113; x=1773966913; 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=5g1oxOZuD0TjRJopzLlGiiDsTi7txtKncHU5UC9/URc=; b=cdzpI7uIwG5fUa1Ciy2qVmCjvenxM32ap93cnFqdMGmuFHu3n+nhafcpClEggsXbgE 9oKtPuFfMIfwuyyfqHwx8dCu5qKDFbWEzKgGcnU4aXrvwOfpBRNvSn+YmxPrmowXPevI XFSauYhMvWJH7+pwvYWLsMo1325vFQXTpXQC1dMS0yQxck144mLwZRX0euvPP7JWJjOJ LlYKq5hnQ5T6+WAhYWlvSP5Twzsed+avGwWS6+iuutyCQBjtYhu23XyOs0OaJlzST8Gj AWTPUxZsUyA+oEG/Op8TaAl1eJLqj+sNfg1Cyv9b46162EpnnkFlf784dKevE2pQLIaR WTfg== X-Forwarded-Encrypted: i=1; AJvYcCWyi37FtOO5/gBqFL7mEpBwfNYGKO+L1xJVfz/CQ7mnnJ9Kz6BqxX3l4dP4C02KwHUlrHZSx5uEKicQksI=@vger.kernel.org X-Gm-Message-State: AOJu0YyA48BlAZdDnA5AfZsjtmhw5QQmdXPHzUIUs7Vv7t06diOOUZqE CndWaC2k4wePKHnS7oj50tInnHexh7v8t8HuuPMNVBw6RoPmrOvbKtv5 X-Gm-Gg: ATEYQzwhsE6MpwUrggz04IhAQI6O7hNVI05YqnasOpeXftcTjExrgWKVl7bJsvFwj87 HEIZBdph3ueTp8WN2iCa96cjJCAyWsU+tD6vXUMM7VhnsDfDOoh5+DdeWH+ba6c+icaI5UVZN1A 3ZeRO6nF3nvpbbCBn0rlPw/uEV9nXxlPnN56uIQ7QbisI81Xw96KD89UMODzDRdoqzb2Fq1sdM3 R/CgmLEuwjFA7pLchK/83Hzvpdys2+DqzM8v7HZo9UJ912mwCXh+3OxwgELH4dGxnfGwDvDZg9d nfLO4B2HLI9BsL9HSnkhvDDx66zII5jjABrk1L0ZfjwZf+sPhc+r7kw0en6+00/Hh+6MCCjpowf LPfikJeBAqHVgt7mU+gWo5Wd7DCQK4ZOAbfGo6/Tvs1RUEfPhnmb3iEtEnzJR8shFKNEkH5xdRY Xx6LlzibnACrcWjwraEBIW3BxlLr/OkvQ/PU/HWzsSKV+nljKr6bZ1dUW3xI3DAWji X-Received: by 2002:a05:6a00:2e90:b0:82a:1380:417d with SMTP id d2e1a72fcca58-82a198fcf29mr1117576b3a.52.1773362113369; Thu, 12 Mar 2026 17:35:13 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82a0727f2fcsm4032305b3a.28.2026.03.12.17.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 17:35:12 -0700 (PDT) From: Rosen Penev To: linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] usb: fhci: use kzalloc_flex for priv struct Date: Thu, 12 Mar 2026 17:34:55 -0700 Message-ID: <20260313003456.124270-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" Convert kzalloc_obj(s) to kzalloc_flex to save an allocation. Add __counted_by to get extra runtime analysis. Move counting variable assignment immediately after allocation as required by __counted_by. Signed-off-by: Rosen Penev --- drivers/usb/host/fhci-hcd.c | 15 +++------------ drivers/usb/host/fhci.h | 3 ++- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c index 271bcbe9b326..71e785f445a3 100644 --- a/drivers/usb/host/fhci-hcd.c +++ b/drivers/usb/host/fhci-hcd.c @@ -426,16 +426,11 @@ static int fhci_urb_enqueue(struct usb_hcd *hcd, stru= ct urb *urb, } =20 /* allocate the private part of the URB */ - urb_priv =3D kzalloc_obj(*urb_priv, mem_flags); + urb_priv =3D kzalloc_flex(*urb_priv, tds, size, mem_flags); if (!urb_priv) return -ENOMEM; =20 - /* allocate the private part of the URB */ - urb_priv->tds =3D kzalloc_objs(*urb_priv->tds, size, mem_flags); - if (!urb_priv->tds) { - kfree(urb_priv); - return -ENOMEM; - } + urb_priv->num_of_tds =3D size; =20 spin_lock_irqsave(&fhci->lock, flags); =20 @@ -444,8 +439,6 @@ static int fhci_urb_enqueue(struct usb_hcd *hcd, struct= urb *urb, goto err; =20 /* fill the private part of the URB */ - urb_priv->num_of_tds =3D size; - urb->status =3D -EINPROGRESS; urb->actual_length =3D 0; urb->error_count =3D 0; @@ -453,10 +446,8 @@ static int fhci_urb_enqueue(struct usb_hcd *hcd, struc= t urb *urb, =20 fhci_queue_urb(fhci, urb); err: - if (ret) { - kfree(urb_priv->tds); + if (ret) kfree(urb_priv); - } spin_unlock_irqrestore(&fhci->lock, flags); return ret; } diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h index 1f57b0989485..e221b28e8608 100644 --- a/drivers/usb/host/fhci.h +++ b/drivers/usb/host/fhci.h @@ -387,9 +387,10 @@ struct urb_priv { int tds_cnt; int state; =20 - struct td **tds; struct ed *ed; struct timer_list time_out; + + struct td *tds[] __counted_by(num_of_tds); }; =20 struct endpoint { --=20 2.53.0