From nobody Tue Apr 7 19:54:45 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 D294D313520 for ; Wed, 11 Mar 2026 23:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773271345; cv=none; b=kP1eMSh83Lb7H81TCdtUiFMT/nMmgMF2tNxNwzin20dmKN9aNfxQ6zRxgdT4LvZR8p2ztP0GtnLcW5WpQpV4dUztkxKp2ex3i7JjE7qeJpyVzKrKLjA3AOve/7zmLKlWVTXis9L+MWCc9Khhip0jXeDPhPKyq8HWX13lmZNMG48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773271345; c=relaxed/simple; bh=3b/UX2M7aFcJWInuUSq55ZwYF94bNSeG7Wja6ecHKnc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=es/fHIaUe27xAdSmtwmFzy5TrEUKBHiMz8WgtIkGdghtQyL7C2xDy8P5OPX9FyIdQNsX5ytLZayjs1JhEzZCDLG7YEv8dudQrLA2SKaDn2Pzs0V0WG+9r8yIhCNkBvS7C8Kq61lSfo8i5Ro0/zPGBWYyuI1Ns3VhwJMcTvj7v0o= 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=ij2E9rIO; arc=none smtp.client-ip=209.85.216.52 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="ij2E9rIO" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-35a094cc3e9so221028a91.3 for ; Wed, 11 Mar 2026 16:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773271344; x=1773876144; 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=/y9dleBR2reXEEDZPM2b1qrma+w8Y5dsVKybDsJlCkg=; b=ij2E9rIOE3cyTQ1BBG/rXGGHkdfv4vGCnm9tmxa5aX9g7FqyCKdiiWcVtC5wnw4dj1 V+nqnMvIedzyhd9DCeX4duCGPGXxPp8Dtak7Kdps05Bx97vmZvsOTNXy/NzKBy7Se0xO aCmbhV4MylpY6YJIN+hQeU9VbC2eoPN+gckYeuZAwFk2hDblaTkhoMChG1JX5Yb//ikN gAK7dMyoXp/OnnZVIhclm7qqtLvCvnu7+HPG1YJvgTsSTB9nv84pB/7EJm6L5fI64K0o w9JPNrg/rGr18h9PVrDHnzZOLAIz9YT1t++3nfPZnGwbzx4vlHu0cJLJPm7x3Ehxu+YW htYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773271344; x=1773876144; 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=/y9dleBR2reXEEDZPM2b1qrma+w8Y5dsVKybDsJlCkg=; b=C3MRhjSjMb/j+dxI4gRgxnoh/kTowOHQJ9yY/jKRVaQ0igHQhhp3JvdHyyl/j2dHUl lSH7nwuM0g7YqzoTGCD9X1yToy6Rep74m5RzcytIqdbHU5lHOAWmEGYaT/BAuNhVHYd5 2QFis6MtrS7yZ0QLwBgYn4g4XIcdyv1+KgGUdo5Y6r/VrA3jcYLbMGNjuMyVuIY/dcfh 5lQc4x23M4pRl9e/Y1CsRMwkX7keb2R+5lKS5LgZUORJOSnQh6G3SieUESPyNM1RWPf9 Q4sYEpoTxOSjfxnHpx5mgXUcHmiZNHoYZE9LEDTM9uKItUhs/sVq4ja562noz7x/D56W QHZA== X-Forwarded-Encrypted: i=1; AJvYcCUre9KT2BwGLLsIxjhI9uYq00yv+EDO51+PsAGGlegBb2oZaiZ5HyEtiBJ8tsPFoWHAnbRgtt4hmTxmZqU=@vger.kernel.org X-Gm-Message-State: AOJu0YynSmVj0PtddecmKevwJxdCsi/hL8FQws/sjbc1dF6/wSnh+wtG OgNhKaPX74LUz1IuJV27uB1I8nuyv6TDeDzCX9vE8QKCVyqQaTi3SYWB X-Gm-Gg: ATEYQzwXsaFCPmTSpyMRLjJsmrHc3jYJDfU9KNu8wW4IZIQwaD+IagKpty4AEbzpiLw SGZpo3l+YOTWq4yVVoeGokbu/MtfHvXyl9uwTcgBtJQepg001YqmDQuj0KPpjbauWwDz5ZHZp9b 4VqlqCjmhYUwe3LKggeMZW1YCV0XIyawlqWFXUCI2RQNV9pA7qAqTEI+qTjuOZthdKA0Ce9xMl6 ccebhQIh8m+zv1nNqHomMggTZ14PCPu1sewIvP23BVOi35glb4yvA/rZpNgiJAEePAue21DLtIb aX9aFNkOHUbYN8iNj4N5dryCFfyvZZis97Luo+lqPFA0e6ldQDJr7cf+Pu9FJSEyb87utJ01lmS NvNXuIy2+r0WcVj1O5UMo7lkDluJJCs4BNXA5MSVZpWyi8N+KULJEalcw3+gxgjJLWcuXgMk0es QoqNaG32u5JKvKbLVSE8epsBdy0EYNrNU0R43udArwBcOKHgF8UbF4GA== X-Received: by 2002:a17:90a:d446:b0:356:2c7b:c026 with SMTP id 98e67ed59e1d1-35a01301cf1mr3659933a91.23.1773271343988; Wed, 11 Mar 2026 16:22:23 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35a031aa12dsm1290014a91.10.2026.03.11.16.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 16:22:23 -0700 (PDT) From: Rosen Penev To: linux-usb@vger.kernel.org Cc: Andreas Noever , Mika Westerberg , Yehezkel Bernat , 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] thunderbolt: use kzalloc_flex Date: Wed, 11 Mar 2026 16:22:05 -0700 Message-ID: <20260311232205.18137-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" Simplifies allocation by using a flexible arraay member. Added __counted_by for extra runtime analysis. Signed-off-by: Rosen Penev --- drivers/thunderbolt/path.c | 24 ++++++------------------ drivers/thunderbolt/tb.h | 3 ++- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/thunderbolt/path.c b/drivers/thunderbolt/path.c index 22fb4a1e1acd..3af5d263ac74 100644 --- a/drivers/thunderbolt/path.c +++ b/drivers/thunderbolt/path.c @@ -150,22 +150,17 @@ struct tb_path *tb_path_discover(struct tb_port *src,= int src_hopid, num_hops++; } =20 - path =3D kzalloc_obj(*path); + path =3D kzalloc_flex(*path, hops, num_hops); if (!path) return NULL; =20 + path->path_length =3D num_hops; + path->name =3D name; path->tb =3D src->sw->tb; - path->path_length =3D num_hops; path->activated =3D true; path->alloc_hopid =3D alloc_hopid; =20 - path->hops =3D kzalloc_objs(*path->hops, num_hops); - if (!path->hops) { - kfree(path); - return NULL; - } - tb_dbg(path->tb, "discovering %s path starting from %llx:%u\n", path->name, tb_route(src->sw), src->port); =20 @@ -245,10 +240,6 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb= _port *src, int src_hopid, size_t num_hops; int i, ret; =20 - path =3D kzalloc_obj(*path); - if (!path) - return NULL; - first_port =3D last_port =3D NULL; i =3D 0; tb_for_each_port_on_path(src, dst, in_port) { @@ -267,12 +258,11 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct t= b_port *src, int src_hopid, /* Each hop takes two ports */ num_hops =3D i / 2; =20 - path->hops =3D kzalloc_objs(*path->hops, num_hops); - if (!path->hops) { - kfree(path); + path =3D kzalloc_flex(*path, hops, num_hops); + if (!path) return NULL; - } =20 + path->path_length =3D num_hops; path->alloc_hopid =3D true; =20 in_hopid =3D src_hopid; @@ -339,7 +329,6 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_= port *src, int src_hopid, } =20 path->tb =3D tb; - path->path_length =3D num_hops; path->name =3D name; =20 return path; @@ -372,7 +361,6 @@ void tb_path_free(struct tb_path *path) } } =20 - kfree(path->hops); kfree(path); } =20 diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index e96474f17067..4e66b53860dd 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -440,9 +440,10 @@ struct tb_path { bool drop_packages; bool activated; bool clear_fc; - struct tb_path_hop *hops; int path_length; bool alloc_hopid; + + struct tb_path_hop hops[] __counted_by(path_length); }; =20 /* HopIDs 0-7 are reserved by the Thunderbolt protocol */ --=20 2.53.0