From nobody Tue Apr 7 14:36:48 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 380E33B1B3 for ; Fri, 13 Mar 2026 00:06:39 +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=1773360400; cv=none; b=iBvRdkA40YyhZ5zYKZyL9bgicEAck6g3CgVGhr08wamXzh4LVVsrXS7W8g6HGbNoS4q5BdnDwyNnU+9w56Al+1xvMYzcTdaOxqYZg7hfe46iafltcp3H33nMOjXMB7ZSzDf8X9PnnkrFCTaVPG9wpxYT9EDPAL4MUowQKG3R90w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773360400; c=relaxed/simple; bh=RNBDhx6SP9Dlnjslw2G6n/SBRm1RMP3mTWySGwZB16E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uaDQF9KtooPoexVBiXEXQyKkUcgJTLS0EtQNl0P4NZWpwCfyC4tNoHzp963+VHuK5vGP/MuPajnYs1euHotyOuH4BS5SA6P7bC93ifepqlFJ2BMPgNwuVtMM2210n5UvxuLnXh6b+kvxbOEJc8H0dKArp3wPw5ELgK7jEj5h8Uo= 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=KgbjLUm3; 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="KgbjLUm3" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-35a18b65515so857754a91.1 for ; Thu, 12 Mar 2026 17:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773360398; x=1773965198; 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=nuLpHvR1fwObt/8Xvj3rrc9Oc9+CrLWMV9LCtsBGyrI=; b=KgbjLUm3nIeMZItgPA/7XBSfz/Ya6u1teNAkKqZhGdLX3XOwyA0cXv/b8CjvPfo9NQ DBrsKidCHEbeCpWs4qO5JY4anvQ2AuLb/sAtAEoP/CTDYZVMBbkEV2qXIWop+BGdLRsA m971uTr7hzBLZte4GLEA8Vz40/uE8kegf2i3mp5TnChtkstrBguh1LaaD5dRX1+R6QrO RxuknpeZPxq/QYkAzQt4m4mHCjQbVqs0WJjB2o45W2ZAMxeBNn3kIzm2Cyxil6FXbrH0 J9dgyQP4izr3NIiHKLkWvlIeZ2n9dUnFP2slZOk/NSN+w9/lTKtQ/nHaZveiQer0CQeN EwWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773360398; x=1773965198; 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=nuLpHvR1fwObt/8Xvj3rrc9Oc9+CrLWMV9LCtsBGyrI=; b=QeBV1NA1l9mKNoaHJV8/FAilwoyB3LFoz3dLPbeaxB6g9NcqNtenN2bidKDVk78L4u YKKuDiQFUjtH5rJxXutuKyb13hbgnmvwsRB17TMPNAonJr16K0/nooMfE/NqqPlORmRf ldQnqOIqTT0h4CLytVBvaSJlOH+mRyKVgsgj09iIMcQEIrqIdJfwhsCqBoEmZ4DMZ9uH aRMNKnCZzYuRar4MGHMtYsdnXHxSlh4b2dTqpKSXiZzAkVfmw6SgPKcMlq0uCVks1KwH kmKOCFGfiH3cQGGLQZGtF8ISqCnRX5iPAn/XVtyUV61vpt+mEguFt9Vcd7VEK+6rAiqb qaog== X-Forwarded-Encrypted: i=1; AJvYcCUhhLXkQGIavitEKg5GhMRhadP4IJgAnP7RqoFPoX0lxK0N8OmFGyv4mwKNPMzr7zh2ItJ4P7xHSBgHk4g=@vger.kernel.org X-Gm-Message-State: AOJu0Yx60I7G51cu14s95DuJ4LlxDNq1Ykk8t8W1cuJeZvo8VnPHlUuT VJh16BEs2sTSjJE6ZC1xDUmv76JHdoQFPmz2tpCFkfeiD9aZL5ew6YFy X-Gm-Gg: ATEYQzxKzIh31U5PwVFpiRLt0ivwT+DCwIlI7Mv9z4EYvMcmqUkOkZ/mTeEiEPM1dDu 26mbUQ+jW3HWBH+ceanQU8+clpXygcmZVXwYnuUsfRgrVvwBPCwgGW7F62JCzf3QrdWTtByO821 LY8x5mLgnUrIMaVz9x26HYAXdbMPuHZ1QRyxiChFcsuTmz5ggxog+az4JEBLuSKkGvLKv45ESWF WyTZGNz1YRog7TOa0x/15b6EPgFM6tkEMKW4N4VpDEeTBAjtIsGLw0Da6DoOEx52Jvt7zhkJH5q 1n/dZYR+ZyTkAvesLwUTnIQG8TMIPlo2wvTdbcufT8khhD9zyARcx7dJbuPFb+jf3wQ1WN2pttp LiBUcfzIzG4S7+5YXgmd6R9zF2ddiLwAx4W4jrYD0ntCKr6QyMu6l6j+W9BIBJM9G5m26jYXLGl 7h6B0Gni2jXlzTk+A+H4xqdg3pXRUrIJAmmldXtcYUe8kF3FrWoFSPug== X-Received: by 2002:a17:90b:3848:b0:359:f2e1:58fc with SMTP id 98e67ed59e1d1-35a220cf0ddmr1186924a91.30.1773360398558; Thu, 12 Mar 2026 17:06:38 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35a07f0a365sm6192261a91.13.2026.03.12.17.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 17:06:37 -0700 (PDT) From: Rosen Penev To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , 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] drm: property: use kzalloc_flex Date: Thu, 12 Mar 2026 17:06:20 -0700 Message-ID: <20260313000620.117065-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" Don't allocate values separately to simplify allocation. Add __counted_by for extra runtime analysis. Move the counting variable assignment to right after allocation as required by __counted_by. Signed-off-by: Rosen Penev --- drivers/gpu/drm/drm_property.c | 14 ++------------ include/drm/drm_property.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c index f38f2c5437e6..a6008e5c2b58 100644 --- a/drivers/gpu/drm/drm_property.c +++ b/drivers/gpu/drm/drm_property.c @@ -107,25 +107,18 @@ struct drm_property *drm_property_create(struct drm_d= evice *dev, if (WARN_ON(strlen(name) >=3D DRM_PROP_NAME_LEN)) return NULL; =20 - property =3D kzalloc_obj(struct drm_property); + property =3D kzalloc_flex(*property, values, num_values); if (!property) return NULL; =20 + property->num_values =3D num_values; property->dev =3D dev; =20 - if (num_values) { - property->values =3D kcalloc(num_values, sizeof(uint64_t), - GFP_KERNEL); - if (!property->values) - goto fail; - } - ret =3D drm_mode_object_add(dev, &property->base, DRM_MODE_OBJECT_PROPERT= Y); if (ret) goto fail; =20 property->flags =3D flags; - property->num_values =3D num_values; INIT_LIST_HEAD(&property->enum_list); =20 strscpy_pad(property->name, name, DRM_PROP_NAME_LEN); @@ -134,7 +127,6 @@ struct drm_property *drm_property_create(struct drm_dev= ice *dev, =20 return property; fail: - kfree(property->values); kfree(property); return NULL; } @@ -447,8 +439,6 @@ void drm_property_destroy(struct drm_device *dev, struc= t drm_property *property) kfree(prop_enum); } =20 - if (property->num_values) - kfree(property->values); drm_mode_object_unregister(dev, &property->base); list_del(&property->head); kfree(property); diff --git a/include/drm/drm_property.h b/include/drm/drm_property.h index aa49b5a42bb5..8c7cef4418c4 100644 --- a/include/drm/drm_property.h +++ b/include/drm/drm_property.h @@ -175,14 +175,6 @@ struct drm_property { */ uint32_t num_values; =20 - /** - * @values: - * - * Array with limits and values for the property. The - * interpretation of these limits is dependent upon the type per @flags. - */ - uint64_t *values; - /** * @dev: DRM device */ @@ -195,6 +187,14 @@ struct drm_property { * enum and bitmask values. */ struct list_head enum_list; + + /** + * @values: + * + * Array with limits and values for the property. The + * interpretation of these limits is dependent upon the type per @flags. + */ + uint64_t values[] __counted_by(num_values); }; =20 /** --=20 2.53.0