From: SF Markus Elfring <elfring@users.sourceforge.net>
To: dri-devel@lists.freedesktop.org,
"Bhaktipriya Shridhar" <bhaktipriya96@gmail.com>,
"Daniel Vetter" <daniel.vetter@ffwll.ch>,
"David Airlie" <airlied@linux.ie>,
"Noralf Trønnes" <noralf@tronnes.org>,
"Tejun Heo" <tj@kernel.org>,
"Thierry Reding" <treding@nvidia.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH 1/4] GPU-DRM-QXL: Use kmalloc_array() in qxl_device_init()
Date: Thu, 22 Sep 2016 08:20:11 +0200 [thread overview]
Message-ID: <269141d5-6562-3d70-b823-283ecde6e09c@users.sourceforge.net> (raw)
In-Reply-To: <ce810580-cc2b-32cc-a852-a355374c2100@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 21 Sep 2016 22:26:08 +0200
* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.
* Add a bit of exception handling for a detected null pointer.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/gpu/drm/qxl/qxl_kms.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/qxl/qxl_kms.c b/drivers/gpu/drm/qxl/qxl_kms.c
index e642242..76852f1 100644
--- a/drivers/gpu/drm/qxl/qxl_kms.c
+++ b/drivers/gpu/drm/qxl/qxl_kms.c
@@ -216,10 +216,11 @@ static int qxl_device_init(struct qxl_device *qdev,
qdev->slot_id_bits = qdev->rom->slot_id_bits;
qdev->va_slot_mask =
(~(uint64_t)0) >> (qdev->slot_id_bits + qdev->slot_gen_bits);
-
- qdev->mem_slots =
- kmalloc(qdev->n_mem_slots * sizeof(struct qxl_memslot),
- GFP_KERNEL);
+ qdev->mem_slots = kmalloc_array(qdev->n_mem_slots,
+ sizeof(*qdev->mem_slots),
+ GFP_KERNEL);
+ if (!qdev->mem_slots)
+ return -ENOMEM;
idr_init(&qdev->release_idr);
spin_lock_init(&qdev->release_idr_lock);
--
2.10.0
next prev parent reply other threads:[~2016-09-22 6:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 6:18 [PATCH 0/4] GPU-DRM-QXL: Fine-tuning for three function implementations SF Markus Elfring
2016-09-22 6:20 ` SF Markus Elfring [this message]
2016-09-22 6:21 ` [PATCH 2/4] GPU-DRM-QXL: Move three assignments in qxl_device_init() SF Markus Elfring
2016-09-22 10:09 ` Dan Carpenter
2016-09-22 13:11 ` SF Markus Elfring
2016-09-22 15:46 ` Gerd Hoffmann
2016-09-22 17:16 ` SF Markus Elfring
2016-09-22 20:24 ` Gerd Hoffmann
2016-09-22 20:24 ` Dan Carpenter
2016-09-23 7:25 ` Sean Paul
2016-09-23 7:53 ` Dave Airlie
2016-09-23 8:50 ` SF Markus Elfring
2016-09-23 13:30 ` Emil Velikov
2016-09-23 14:23 ` SF Markus Elfring
2016-09-23 8:42 ` SF Markus Elfring
2016-09-23 8:34 ` SF Markus Elfring
2016-09-22 6:22 ` [PATCH 3/4] GPU-DRM-QXL: Improve a size determination in qxl_driver_load() SF Markus Elfring
2016-09-22 6:23 ` [PATCH 4/4] GPU-DRM-QXL: Adjust checks for null pointers in three functions SF Markus Elfring
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=269141d5-6562-3d70-b823-283ecde6e09c@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=airlied@linux.ie \
--cc=bhaktipriya96@gmail.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=julia.lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noralf@tronnes.org \
--cc=tj@kernel.org \
--cc=treding@nvidia.com \
/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;
as well as URLs for NNTP newsgroup(s).