mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: dri-devel@lists.freedesktop.org, kernel-janitors@vger.kernel.org,
	Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>
Cc: LKML <linux-kernel@vger.kernel.org>, cocci@inria.fr
Subject: [PATCH 3/3] drm: property: Improve four size determinations
Date: Tue, 26 Dec 2023 10:42:43 +0100	[thread overview]
Message-ID: <29dea8dc-5a57-4c07-a857-e2c6a86c5c06@web.de> (raw)
In-Reply-To: <ff7ce5d0-59fa-470c-8dd6-68dbe65c18e5@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 26 Dec 2023 09:45:36 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator “sizeof” to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/gpu/drm/drm_property.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index ea365f00e890..1fe54cbf1c83 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -107,7 +107,7 @@ struct drm_property *drm_property_create(struct drm_device *dev,
 	if (WARN_ON(strlen(name) >= DRM_PROP_NAME_LEN))
 		return NULL;

-	property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
+	property = kzalloc(sizeof(*property), GFP_KERNEL);
 	if (!property)
 		return NULL;

@@ -418,7 +418,7 @@ int drm_property_add_enum(struct drm_property *property,
 	if (WARN_ON(index >= property->num_values))
 		return -EINVAL;

-	prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
+	prop_enum = kzalloc(sizeof(*prop_enum), GFP_KERNEL);
 	if (!prop_enum)
 		return -ENOMEM;

@@ -560,10 +560,10 @@ drm_property_create_blob(struct drm_device *dev, size_t length,
 	struct drm_property_blob *blob;
 	int ret;

-	if (!length || length > INT_MAX - sizeof(struct drm_property_blob))
+	if (!length || length > INT_MAX - sizeof(*blob))
 		return ERR_PTR(-EINVAL);

-	blob = kvzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
+	blob = kvzalloc(sizeof(*blob) + length, GFP_KERNEL);
 	if (!blob)
 		return ERR_PTR(-ENOMEM);

--
2.43.0


  parent reply	other threads:[~2023-12-26  9:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-26  9:36 [PATCH 0/3] drm: property: Adjustments for three function implementations Markus Elfring
2023-12-26  9:38 ` [PATCH 1/3] drm: property: One function call less in drm_property_create() after error detection Markus Elfring
2024-01-03 15:16   ` Michel Dänzer
2024-01-03 16:24     ` Markus Elfring
2024-01-03 17:18       ` Michel Dänzer
2024-01-03 18:08         ` [1/3] " Markus Elfring
2024-01-04  9:26           ` Michel Dänzer
2024-01-04 12:21             ` Markus Elfring
2024-01-04 15:26         ` [PATCH 1/3] " Dan Carpenter
2023-12-26  9:40 ` [PATCH 2/3] drm: property: Delete an unnecessary initialisation in drm_property_create() Markus Elfring
2023-12-26  9:42 ` Markus Elfring [this message]
2023-12-26 10:10   ` [PATCH 3/3] drm: property: Improve four size determinations Simon Ser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=29dea8dc-5a57-4c07-a857-e2c6a86c5c06@web.de \
    --to=markus.elfring@web.de \
    --cc=airlied@gmail.com \
    --cc=cocci@inria.fr \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®