From nobody Thu Apr 2 18:46:12 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 C324020C029 for ; Fri, 27 Mar 2026 02:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774579862; cv=none; b=NIfRniubMocNBhINGE2tghZOUrTXWZbHyMJvma0+D0PlRZrRihMLuu1YoNU0NIubwl2dzkO1zI3P/vavmHtWI4sqTaXVPrghzwmaAhewwpcAsVV4pics2ng6A0EICUu5rApBnTnlhAQrmzFKvWfIiJQ8oxNSlVXyY3lsrloc3Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774579862; c=relaxed/simple; bh=PhK1uiwCqLIJI3ueMcn4+tjHbQ8klTqD3ZDxXIovspU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XU1dw5WKw7l6O8FUrE+EtyHFEdOdwlDtq0adqEVcy5QuvUTRX62AbewJMPYAhkFwdjU4oiXIpd0Y0GxL9q3Z/X9BFb1wAHbA6lhwRh/Ahd6rCjWU9mVnJc9VrVLmiqo+8WbfkyOINc1wTiquxKdeXWZmLg1q7oSER0wDSLN/UMo= 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=I7GaevoJ; arc=none smtp.client-ip=209.85.216.53 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="I7GaevoJ" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-35c0e7b751aso1605762a91.2 for ; Thu, 26 Mar 2026 19:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774579861; x=1775184661; 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=SX5+VodhRV2hJI3/ddIJ/j9D3gWCV2wOSdzAThk9yJY=; b=I7GaevoJG7rZ1bxnX7qR8Kui4uSmkux6ryLsLZD6hq8B+GX0TnA0pc05IfFFHjs/q9 zMd6m91ZmyrYv8ei9Erd3A4zT5ySD41DqlyBuwvA6LcojbUJUnXW7hdlQea3zDAPbW7W s00F1sNmOQNHHUkOTVI6+whocKZX4WgPs317Z12W5DR/0VBMkciNrBhIQmIRP3aIsr01 GsCCbfOjk8WKn5egO3aF+zqV7wqo7i7yHhLEYV+Sn6xyjgaT/P6CZpHCxEQdD8X/ZBWI MUmXYlkuGO77gawLVV3ibONKFc9oebyhe5X6bwkbKeyIoibLVsI2s71g7MdvLeed24CE LcSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774579861; x=1775184661; 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=SX5+VodhRV2hJI3/ddIJ/j9D3gWCV2wOSdzAThk9yJY=; b=FtQlWxzxgM60X3u3U43LirPZmPOmpVrKLYVbtwGBlcYiEByLcKoQmOwbL0RAmaVzos 8RNHo4IZ1eXPT2HpUh9CJWegKKwhh02k3GVcljmUeZusTBp4lBOd9VUsZQp3EiOyXdtJ ef+COaXEnk8VgKsU1W96QlbU9y/AUClGmfS/SdHVy0ifC1UtkeIxCDbjECK88P7pgkNV ynwHvdARNTxE9kYgKco7WtxA1ZlBDDZCwZTx5uD3rnyt8vgZCm8abUY/syI2PlUm5j2K HZy7JHTgYfY8JpVTRuyCf+KU8lelmUwECFarNvnxk4Y9xnN8VWYAyTV1cR0cuG4k9JvS IGDg== X-Forwarded-Encrypted: i=1; AJvYcCUAATctHoq0teAeZF2NPxWBupVOQSi7nSRazfkzKiIL9BBjnZSBif1YEGyKyaNJY4XHOcKBeiwNN2J5q6g=@vger.kernel.org X-Gm-Message-State: AOJu0YyBGCM9jCN79CO7sxNThtMosZjuwPyzsoJckLQSYRiBNpZDFv+7 lwgIjl83DaFjflvwfl26Qp7AcxPvjn99NIrrGETvWAe0JRh/Qc3cSXU3 X-Gm-Gg: ATEYQzxl1qQI2BI5dMMhs3FWgHOZ9mjhOuUccSlBBBHxTd4OB0ANLy4YsHXhspeqIKb YEKYv+dPcFe/CY3wEdhAT5imAMpOPEVAwIW0W08fHfNNJiQvvSc9kM8K7UAz1sNKAEVvwaMl+U6 FnmFUTwXL68wot9ufABmcicWDmL/eEJuc9ErOhDWjUrgNefK61qxAZSN2GoctJV6tcJdx5lTtJ7 r6rHY61tBkYdmpvVFQII7aWICCxcTcgaeceHQMBV1lUNOksravXYJeiXoIXMNt6eY9FRhkJVDzt PIFQJEfrBmY8iKNi/8g9geLvrdEP/n6vqRzo56TNGXySFLrEXal9uwgo29vmWhHHfuLR96/cT0W UDiEzeZDGr0UHgd18EpgudKdSyNyA2uzlkPW9vCierfPvFg3sZ281kisx6osm+ws48wfHldIL+S Ok5aygTgry8Qr34AQmJ0I75RyY0Isbf7DQGWszUVJ15+KOiy8GQGcZa7A= X-Received: by 2002:a17:903:28f:b0:2b0:67a7:5c4b with SMTP id d9443c01a7336-2b0cdcb0791mr9021885ad.28.1774579861001; Thu, 26 Mar 2026 19:51:01 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b0bc8c6895sm54574445ad.64.2026.03.26.19.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 19:51:00 -0700 (PDT) From: Rosen Penev To: linux-ide@vger.kernel.org Cc: Damien Le Moal , Niklas Cassel , Hans de Goede , 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] ata: libahci_platform: remove kcalloc Date: Thu, 26 Mar 2026 19:50:43 -0700 Message-ID: <20260327025043.7565-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" Use a flexible array member with struct_size to combine the allocations. Added __counted_by support for extra runtime analysis. Signed-off-by: Rosen Penev --- drivers/ata/ahci.h | 3 ++- drivers/ata/libahci_platform.c | 33 +++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index 293b7fb216b5..9e8b6319025c 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -357,7 +357,6 @@ struct ahci_host_priv { * If platform uses PHYs. There is a 1:1 relation between the port number= and * the PHY position in this array. */ - struct phy **phys; unsigned nports; /* Number of ports */ void *plat_data; /* Other platform data */ unsigned int irq; /* interrupt line */ @@ -379,6 +378,8 @@ struct ahci_host_priv { /* only required for per-port MSI(-X) support */ int (*get_irq_vector)(struct ata_host *host, int port); + + struct phy *phys[] __counted_by(nports); }; =20 /* diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index f37247e7a5cb..6e072d681341 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -482,15 +482,29 @@ struct ahci_host_priv *ahci_platform_get_resources(st= ruct platform_device *pdev, struct ahci_host_priv *hpriv; u32 mask_port_map =3D 0; u32 max_port; + int nports; =20 if (!devres_open_group(dev, NULL, GFP_KERNEL)) return ERR_PTR(-ENOMEM); =20 - hpriv =3D devres_alloc(ahci_platform_put_resources, sizeof(*hpriv), + /* find maximum port id for allocating structures */ + max_port =3D ahci_platform_find_max_port_id(dev); + /* + * Set nports according to maximum port id. Clamp at + * AHCI_MAX_PORTS, warning message for invalid port id + * is generated later. + * When DT has no sub-nodes max_port is 0, nports is 1, + * in order to be able to use the + * ahci_platform_[en|dis]able_[phys|regulators] functions. + */ + nports =3D min(AHCI_MAX_PORTS, max_port + 1); + hpriv =3D devres_alloc(ahci_platform_put_resources, struct_size(hpriv, ph= ys, nports), GFP_KERNEL); if (!hpriv) goto err_out; =20 + hpriv->nports =3D nports; + devres_add(dev, hpriv); =20 /* @@ -573,23 +587,6 @@ struct ahci_host_priv *ahci_platform_get_resources(str= uct platform_device *pdev, goto err_out; } =20 - /* find maximum port id for allocating structures */ - max_port =3D ahci_platform_find_max_port_id(dev); - /* - * Set nports according to maximum port id. Clamp at - * AHCI_MAX_PORTS, warning message for invalid port id - * is generated later. - * When DT has no sub-nodes max_port is 0, nports is 1, - * in order to be able to use the - * ahci_platform_[en|dis]able_[phys|regulators] functions. - */ - hpriv->nports =3D min(AHCI_MAX_PORTS, max_port + 1); - - hpriv->phys =3D devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GF= P_KERNEL); - if (!hpriv->phys) { - rc =3D -ENOMEM; - goto err_out; - } /* * We cannot use devm_ here, since ahci_platform_put_resources() uses * target_pwrs after devm_ have freed memory --=20 2.53.0