From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org, amd-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, "Alan Liu" <HaoPing.Liu@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Alex Hung" <alex.hung@amd.com>,
"Alexey Kodanev" <aleksei.kodanev@bell-sw.com>,
"Aurabindo Pillai" <aurabindo.pillai@amd.com>,
"Bhanuprakash Modem" <bhanuprakash.modem@intel.com>,
"Candice Li" <candice.li@amd.com>,
"Charlene Liu" <charlene.liu@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"David Airlie" <airlied@gmail.com>,
"David Tadokoro" <davidbtadokoro@usp.br>,
"Eryk Brol" <eryk.brol@amd.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Hamza Mahfooz" <hamza.mahfooz@amd.com>,
"Harry Wentland" <harry.wentland@amd.com>,
"Hawking Zhang" <Hawking.Zhang@amd.com>,
"hersen wu" <hersenxs.wu@amd.com>,
"Jiapeng Chong" <jiapeng.chong@linux.alibaba.com>,
"Jun Lei" <jun.lei@amd.com>, "Leo Li" <sunpeng.li@amd.com>,
"Mikita Lipski" <mikita.lipski@amd.com>,
"Rodrigo Siqueira" <Rodrigo.Siqueira@amd.com>,
"Stanley Yang" <Stanley.Yang@amd.com>,
"Tao Zhou" <tao.zhou1@amd.com>, "Tom Rix" <trix@redhat.com>,
"Victor Zhao" <Victor.Zhao@amd.com>,
"Wayne Lin" <Wayne.Lin@amd.com>,
"Wenjing Liu" <wenjing.liu@amd.com>,
"Xinhui Pan" <Xinhui.Pan@amd.com>,
"YiPeng Chai" <YiPeng.Chai@amd.com>,
"Zhan Liu" <zhan.liu@amd.com>
Cc: LKML <linux-kernel@vger.kernel.org>, cocci@inria.fr
Subject: [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug()
Date: Tue, 11 Apr 2023 15:43:48 +0200 [thread overview]
Message-ID: <89048a5f-2dbb-012c-41f5-7c300e8415f5@web.de> (raw)
In-Reply-To: <2258ce64-2a14-6778-8319-b342b06a1f33@web.de>
Date: Tue, 11 Apr 2023 11:39:02 +0200
The address of a data structure member was determined before
a corresponding null pointer check in the implementation of
the function “trigger_hotplug”.
Thus avoid the risk for undefined behaviour by moving the assignment
for three local variables behind some condition checks.
This issue was detected by using the Coccinelle software.
Fixes: 6f77b2ac628073f647041a92b36c824ae3aef16e ("drm/amd/display: Add connector HPD trigger debugfs entry")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
index 827fcb4fb3b3..b3cfd7dfbb28 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
@@ -1205,10 +1205,10 @@ static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
size_t size, loff_t *pos)
{
struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
- struct drm_connector *connector = &aconnector->base;
+ struct drm_connector *connector;
struct dc_link *link = NULL;
- struct drm_device *dev = connector->dev;
- struct amdgpu_device *adev = drm_to_adev(dev);
+ struct drm_device *dev;
+ struct amdgpu_device *adev;
enum dc_connection_type new_connection_type = dc_connection_none;
char *wr_buf = NULL;
uint32_t wr_buf_size = 42;
@@ -1253,12 +1253,16 @@ static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
return -EINVAL;
}
+ connector = &aconnector->base;
+ dev = connector->dev;
+
if (param[0] == 1) {
if (!dc_link_detect_connection_type(aconnector->dc_link, &new_connection_type) &&
new_connection_type != dc_connection_none)
goto unlock;
+ adev = drm_to_adev(dev);
mutex_lock(&adev->dm.dc_lock);
ret = dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
mutex_unlock(&adev->dm.dc_lock);
--
2.40.0
next prev parent reply other threads:[~2023-04-11 13:44 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <40c60719-4bfe-b1a4-ead7-724b84637f55@web.de>
[not found] ` <1a11455f-ab57-dce0-1677-6beb8492a257@web.de>
2023-04-11 13:36 ` [PATCH 0/5] drm/amd: Adjustments for three function implementations Markus Elfring
2023-04-11 13:42 ` [PATCH 1/5] drm/amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() Markus Elfring
2023-04-11 13:59 ` Felix Kuehling
2023-04-11 14:45 ` Markus Elfring
2024-09-09 9:42 ` Markus Elfring
2023-04-11 13:43 ` Markus Elfring [this message]
2023-04-11 15:04 ` [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() Christian König
2023-05-16 16:40 ` Markus Elfring
2023-04-11 13:46 ` [PATCH 3/5] drm/amd/display: Delete three unnecessary variable initialisations " Markus Elfring
2023-04-11 13:48 ` [PATCH 4/5] drm/amd/display: Delete a redundant statement " Markus Elfring
2023-04-11 13:50 ` [PATCH 5/5] drm/amd/display: Move an expression into a return statement in dcn201_link_encoder_create() Markus Elfring
2024-01-05 19:21 ` [PATCH 0/5] drm/amd: Adjustments for three function implementations Markus Elfring
2023-04-11 16:38 ` [PATCH] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions Markus Elfring
2023-04-11 16:43 ` Dmitry Baryshkov
2023-04-11 16:44 ` Abhinav Kumar
2025-03-02 20:56 ` [PATCH RESEND] " Markus Elfring
2025-03-02 23:01 ` Dmitry Baryshkov
2025-03-03 7:14 ` Dan Carpenter
2025-03-03 8:15 ` [RESEND] " Markus Elfring
2025-03-03 8:24 ` Dan Carpenter
2025-03-05 8:40 ` [RFC] Clarification for “undefined behaviour”? Markus Elfring
2025-03-05 8:51 ` Dan Carpenter
2025-03-05 9:20 ` Markus Elfring
2025-03-05 14:17 ` David Laight
2025-03-05 14:30 ` Dan Carpenter
2025-03-05 21:35 ` David Laight
2023-04-13 19:44 ` [PATCH] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() Markus Elfring
2025-03-02 18:02 ` [PATCH RESEND] " Markus Elfring
2025-03-03 9:19 ` Uwe Kleine-König
2025-03-03 10:08 ` Dan Carpenter
2025-03-03 10:08 ` Dan Carpenter
2025-03-03 10:14 ` Dan Carpenter
2025-03-03 10:30 ` Uwe Kleine-König
2025-03-03 10:36 ` Markus Elfring
2025-03-03 10:53 ` [PATCH RESEND] " Dan Carpenter
2025-03-05 12:14 ` Markus Elfring
2025-03-05 17:07 ` Helge Deller
2025-03-05 17:28 ` Markus Elfring
2025-03-08 21:26 ` [PATCH RESEND] " Helge Deller
2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring
2023-04-16 9:33 ` [PATCH 1/9] drm/nouveau/debugfs: Move an expression into a function call parameter in nouveau_debugfs_pstate_set() Markus Elfring
2023-04-16 9:36 ` [PATCH 2/9] drm/nouveau/debugfs: Move a variable assignment behind a null pointer check in nouveau_debugfs_pstate_get() Markus Elfring
2023-04-16 9:38 ` [PATCH 3/9] drm/nouveau/debugfs: Use seq_putc() " Markus Elfring
2023-04-16 9:40 ` [PATCH 4/9] drm/nouveau/debugfs: Replace five seq_printf() calls by seq_puts() " Markus Elfring
2023-04-16 9:42 ` [PATCH 5/9] drm/nouveau/bios/power_budget: Move an expression into a macro call parameter in nvbios_power_budget_header() Markus Elfring
2023-04-16 9:44 ` [PATCH 6/9] drm/nouveau/clk: Move a variable assignment behind a null pointer check in nvkm_pstate_new() Markus Elfring
2023-04-16 9:46 ` [PATCH 7/9] drm/nouveau/pci: Move a variable assignment behind condition checks in nvkm_pcie_set_link() Markus Elfring
2023-04-16 9:54 ` [PATCH 8/9] drm/nouveau/pci: Move an expression into a function call parameter " Markus Elfring
2023-04-16 9:56 ` [PATCH 9/9] drm/nouveau/therm: Move an assignment statement behind a null pointer check in two functions Markus Elfring
2023-04-17 16:25 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Karol Herbst
2023-04-16 15:47 ` [PATCH] drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() Markus Elfring
2023-04-25 13:30 ` Robert Foss
2023-04-25 14:15 ` Markus Elfring
2023-04-27 15:10 ` Robert Foss
2023-04-27 19:34 ` Markus Elfring
2023-04-28 11:49 ` Robert Foss
2023-04-28 15:55 ` [PATCH resent] " Markus Elfring
2023-04-28 17:27 ` Robert Foss
2023-04-17 9:42 ` [PATCH] drm/mm: Adjust input parameter validation in DECLARE_NEXT_HOLE_ADDR() Markus Elfring
2025-03-03 12:48 ` [PATCH RESEND] " 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=89048a5f-2dbb-012c-41f5-7c300e8415f5@web.de \
--to=markus.elfring@web.de \
--cc=HaoPing.Liu@amd.com \
--cc=Hawking.Zhang@amd.com \
--cc=Rodrigo.Siqueira@amd.com \
--cc=Stanley.Yang@amd.com \
--cc=Victor.Zhao@amd.com \
--cc=Wayne.Lin@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=YiPeng.Chai@amd.com \
--cc=airlied@gmail.com \
--cc=aleksei.kodanev@bell-sw.com \
--cc=alex.hung@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=aurabindo.pillai@amd.com \
--cc=bhanuprakash.modem@intel.com \
--cc=candice.li@amd.com \
--cc=charlene.liu@amd.com \
--cc=christian.koenig@amd.com \
--cc=cocci@inria.fr \
--cc=daniel@ffwll.ch \
--cc=davidbtadokoro@usp.br \
--cc=dri-devel@lists.freedesktop.org \
--cc=eryk.brol@amd.com \
--cc=gregkh@linuxfoundation.org \
--cc=hamza.mahfooz@amd.com \
--cc=harry.wentland@amd.com \
--cc=hersenxs.wu@amd.com \
--cc=jiapeng.chong@linux.alibaba.com \
--cc=jun.lei@amd.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mikita.lipski@amd.com \
--cc=sunpeng.li@amd.com \
--cc=tao.zhou1@amd.com \
--cc=trix@redhat.com \
--cc=wenjing.liu@amd.com \
--cc=zhan.liu@amd.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