From nobody Thu Apr 2 15:41:25 2026 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.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 5523025A2B4 for ; Fri, 27 Mar 2026 19:11:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774638684; cv=none; b=iJK32PjNmhlilnw+mWpD/zizwKdEQ2onIuHxwwg+7WZsVvWezPiDZqaQR2pnysnM53CEqbTMzxgA0hcM78C2AM8dQKMkV7UT6F3mcIlUiM23X15E7UBXu+d4ipYmfdflVv5XCRpsUlVTcqhasbczLxVuT34HFZPYWYZvv1UZF5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774638684; c=relaxed/simple; bh=MY7cvhxbG7/wiNuf5e5sQpLEVRQoOMUVb6G8zWyUBs0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=drOKNJyGVwWp7K1h2aeRZVHP88CJJiHFOJ05YQ8owirvhHgnUfyEdIrmsLFF4GYblwyePZtQBcA0WxWd7CE2Ifea5MlDrOBhsfucDFRJHV+Zj2IDRBfsPhQywSiKMIfoBxWgSr+4HP33eZ5SGpXwPDhUe1wN5vhGlk4K2pARW5A= 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=HHqLCdt3; arc=none smtp.client-ip=74.125.82.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="HHqLCdt3" Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1279eced0b9so3757445c88.0 for ; Fri, 27 Mar 2026 12:11:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774638682; x=1775243482; 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=zCbLjBWf2b55Ge/3z8jm9aEiQT0X4UuXkcvJNvdHJnc=; b=HHqLCdt3HSwMxY8SYohSVOvhhyob2P4NRsXJ/z/ifCwWrpXxpXmxXLMA7STK1BD+Fd MYprgzZ/mS58Cbes6VYME0bfqbboBhlQQCXF1u+wlJ27nbBAO6D5GNzzPD3D4tUZDgdH Pu5ZsD+WYdx5gkmE9VhbQPIyezQSzlNd61mGUQMUtzH9NXgZVsKTorgzvBhU6Hr7nYMr X7ngEDqpKy3/hO3VV/32VkNLNpTMixvlPCBk5H5NC1y6Pim6rDVA0rOss4/Mx/84kOFr EwP/axiCkpc+085PcYoIWOs6pHO0sWRblbttDK63eye7Cij6ywhhnWzC0Jx7OAgbGjOF Pf/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774638682; x=1775243482; 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=zCbLjBWf2b55Ge/3z8jm9aEiQT0X4UuXkcvJNvdHJnc=; b=ks6cJPdskuqWx8bx/vkRz3ACWACcBBvQbLWeyc8rVWGsTUh7UiAmITCfLT14EbaUzH UipXLA3QElk20HKP3rNRvQiqA8gP91OdYARbHE/tcDZINkXAOvI3qCTcVic+zUyPJnW0 UEX5fyBhljybHM20AvnE3k5OxEcHDZcAsNBdZcnZk8Bx45R7WjikAQYOxS5BYVc0x+7Z 2X8lMiHAnfUzLAJfkra50RFFPJuC3a1ExCGgGzyR5Nyp6AM0yGND7VR/sBP/RS7OM08e XuSxwW1FVS08CcY86jJi1TEVfpEzfDPubXqFy3By2Q31FWxeBJ6rCY2LD9gIIrV4FRxU nhHA== X-Forwarded-Encrypted: i=1; AJvYcCXO0NeRnHiOBj5Q6pKandziuN2RKnSWa694woAXF/mKPls3clGN9ENSj7SFNIkgy/uhJW1oY0ePVq2bLgM=@vger.kernel.org X-Gm-Message-State: AOJu0YyHLRxV2X303P7+SDgXusK7XaV4HoxHlOEaH0eueh4YiolXr9P/ 8AUBxfONQ0WOfg9y2HV1un7UL2nJzdBs40yLQgwiWoI3pCw69xa+Jp8bMX1JSc3r X-Gm-Gg: ATEYQzxJEm51NeeQ4CTQvMEtayRbnLq2JtuOLPNOLKIFjeDS/ggJaqcFgeq9cNLy4MU T/bw/YbpPalj/4P7BvIHnrVzuO1hK9qREvd+Vt2+cYe3n/6oR5fVU+dNFXbya/kZhL+Ykf1PY8T cnn63zYr5ShrxODaAc1pwLAV0C25ubxy++TzHzuNd4AL9iNcDIO+VVX4EKURs/ljjN3HV4UZSwD hUcWrYLay8xnryx8ccNY4NAplyQgr9uX+H0jRJZBs7y/LL26jUm3/R94SmIDT9QhvjyFiPs5eCK yOZNml95ZeA/A1y5Qjaj03zlq3Frh9Ozui1etv4gPA47q9PsqkM8EtAYV95gwmnfmCjpP0BPADf 9I4WZxrv3DMe3CUDNQ6ZmkCcpe7xp7PkWjpDa6dj/PDG/tJqyJsy+DK9rvy4iFrJ9z3V2deO4L1 bvbvtsOcqFQ05KtBAkTyT461ZAh1dT4XYsU/CyaZoku78MSHuVCsnOjhk= X-Received: by 2002:a05:7022:6191:b0:127:3b1e:7e0e with SMTP id a92af1059eb24-12ab28cb779mr2194710c88.20.1774638682181; Fri, 27 Mar 2026 12:11:22 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2c3c46a0a84sm216527eec.9.2026.03.27.12.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 12:11:21 -0700 (PDT) From: Rosen Penev To: linux-omap@vger.kernel.org Cc: Aaro Koskinen , Andreas Kemnade , Kevin Hilman , Roger Quadros , Tony Lindgren , Russell King , Kees Cook , "Gustavo A. R. Silva" , linux-arm-kernel@lists.infradead.org (moderated list:ARM SUB-ARCHITECTURES), 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: [PATCHv2] ARM: omap2: simplify allocation for omap_device Date: Fri, 27 Mar 2026 12:11:04 -0700 Message-ID: <20260327191104.206512-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 to combine allocations. Add __counted_by for extra runtime analysis. Remove goto paths as they are not really needed anymore. Signed-off-by: Rosen Penev --- v2: remove kfree and fix compilation. arch/arm/mach-omap2/omap_device.c | 29 ++++++++++------------------- arch/arm/mach-omap2/omap_device.h | 4 ++-- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_d= evice.c index 79db4c49ffc9..77a75b0b9ae6 100644 --- a/arch/arm/mach-omap2/omap_device.c +++ b/arch/arm/mach-omap2/omap_device.c @@ -307,35 +307,27 @@ static struct omap_device *omap_device_alloc(struct p= latform_device *pdev, int ret =3D -ENOMEM; struct omap_device *od; int i; - struct omap_hwmod **hwmods; + struct omap_hwmod *hwmod; - od =3D kzalloc_obj(struct omap_device); - if (!od) - goto oda_exit1; + od =3D kzalloc_flex(*od, hwmods, oh_cnt); + if (!od) { + dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret); + return ERR_PTR(ret); + } od->hwmods_cnt =3D oh_cnt; + memcpy(od->hwmods, ohs, oh_cnt * sizeof(*od->hwmods)); - hwmods =3D kmemdup_array(ohs, oh_cnt, sizeof(*hwmods), GFP_KERNEL); - if (!hwmods) - goto oda_exit2; - - od->hwmods =3D hwmods; od->pdev =3D pdev; pdev->archdata.od =3D od; for (i =3D 0; i < oh_cnt; i++) { - hwmods[i]->od =3D od; - _add_hwmod_clocks_clkdev(od, hwmods[i]); + hwmod =3D od->hwmods[i]; + hwmod->od =3D od; + _add_hwmod_clocks_clkdev(od, hwmod); } return od; - -oda_exit2: - kfree(od); -oda_exit1: - dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret); - - return ERR_PTR(ret); } static void omap_device_delete(struct omap_device *od) @@ -344,7 +336,6 @@ static void omap_device_delete(struct omap_device *od) return; od->pdev->archdata.od =3D NULL; - kfree(od->hwmods); kfree(od); } diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_d= evice.h index aa8096ecb23c..fae09cfce137 100644 --- a/arch/arm/mach-omap2/omap_device.h +++ b/arch/arm/mach-omap2/omap_device.h @@ -37,11 +37,11 @@ /** * struct omap_device - omap_device wrapper for platform_devices * @pdev: platform_device - * @hwmods: (one .. many per omap_device) * @hwmods_cnt: ARRAY_SIZE() of @hwmods * @_state: one of OMAP_DEVICE_STATE_* (see above) * @flags: device flags * @_driver_status: one of BUS_NOTIFY_*_DRIVER from + * @hwmods: (one .. many per omap_device) * * Integrates omap_hwmod data into Linux platform_device. * @@ -51,11 +51,11 @@ */ struct omap_device { struct platform_device *pdev; - struct omap_hwmod **hwmods; unsigned long _driver_status; u8 hwmods_cnt; u8 _state; u8 flags; + struct omap_hwmod *hwmods[] __counted_by(hwmods_cnt); }; /* Device driver interface (call via platform_data fn ptrs) */ -- 2.53.0