* [PATCH 0/5] drm/amd: Adjustments for three function implementations [not found] ` <1a11455f-ab57-dce0-1677-6beb8492a257@web.de> @ 2023-04-11 13:36 ` 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 ` (5 more replies) 2023-04-11 16:38 ` [PATCH] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions Markus Elfring ` (4 subsequent siblings) 5 siblings, 6 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-11 13:36 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci Date: Tue, 11 Apr 2023 14:36:36 +0200 Some update suggestions were taken into account from static source code analysis. Markus Elfring (5) amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() display: Move three variable assignments behind condition checks in trigger_hotplug() display: Delete three unnecessary variable initialisations in trigger_hotplug() display: Delete a redundant statement in trigger_hotplug() display: Move an expression into a return statement in dcn201_link_encoder_create() drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 ++- .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 19 ++++++++++--------- .../amd/display/dc/dcn201/dcn201_resource.c | 4 +--- 3 files changed, 13 insertions(+), 13 deletions(-) -- 2.40.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 1/5] drm/amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() 2023-04-11 13:36 ` [PATCH 0/5] drm/amd: Adjustments for three function implementations Markus Elfring @ 2023-04-11 13:42 ` Markus Elfring 2023-04-11 13:59 ` Felix Kuehling 2024-09-09 9:42 ` Markus Elfring 2023-04-11 13:43 ` [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() Markus Elfring ` (4 subsequent siblings) 5 siblings, 2 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-11 13:42 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci Date: Tue, 11 Apr 2023 10:52:48 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “amdgpu_ras_interrupt_dispatch”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “data” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: c030f2e4166c3f5597c7e7a70bcd9ab383695de4 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c index 4069bce9479f..a920c7888d07 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -1730,11 +1730,12 @@ int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev, struct ras_dispatch_if *info) { struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head); - struct ras_ih_data *data = &obj->ih_data; + struct ras_ih_data *data; if (!obj) return -EINVAL; + data = &obj->ih_data; if (data->inuse == 0) return 0; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH 1/5] drm/amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() 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 1 sibling, 1 reply; 60+ messages in thread From: Felix Kuehling @ 2023-04-11 13:59 UTC (permalink / raw) To: Markus Elfring, kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci Am 2023-04-11 um 09:42 schrieb Markus Elfring: > Date: Tue, 11 Apr 2023 10:52:48 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the function “amdgpu_ras_interrupt_dispatch”. > > Thus avoid the risk for undefined behaviour by moving the assignment > for the variable “data” behind the null pointer check. > > This issue was detected by using the Coccinelle software. > > Fixes: c030f2e4166c3f5597c7e7a70bcd9ab383695de4 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > index 4069bce9479f..a920c7888d07 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > @@ -1730,11 +1730,12 @@ int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev, > struct ras_dispatch_if *info) > { > struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head); > - struct ras_ih_data *data = &obj->ih_data; > + struct ras_ih_data *data; I'm curious, this only takes the address of obj->ih_data. It doesn't dereference the pointer until after the !obj check below. How is this undefined behaviour? Is this about the compiler being free to reorder stuff for optimization, unaware of the dependency? Is there a link to an explanation that could be added to the commit description? Thanks, Felix > > if (!obj) > return -EINVAL; > > + data = &obj->ih_data; > if (data->inuse == 0) > return 0; > > -- > 2.40.0 > ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 1/5] drm/amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() 2023-04-11 13:59 ` Felix Kuehling @ 2023-04-11 14:45 ` Markus Elfring 0 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-11 14:45 UTC (permalink / raw) To: Felix Kuehling, kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c >> @@ -1730,11 +1730,12 @@ int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev, >> struct ras_dispatch_if *info) >> { >> struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head); >> - struct ras_ih_data *data = &obj->ih_data; >> + struct ras_ih_data *data; > I'm curious, this only takes the address of obj->ih_data. Even if a null pointer would accidentally be returned by a call of the function “amdgpu_ras_find_obj”? https://elixir.bootlin.com/linux/v6.3-rc6/source/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c#L618 > It doesn't dereference the pointer until after the !obj check below. Does the used arrow operator indicate a pointer dereference? > How is this undefined behaviour? I guess that another information source can be helpful for such an issue. https://wiki.sei.cmu.edu/confluence/display/c/EXP34-C.+Do+not+dereference+null+pointers?focusedCommentId=405504153#comment-405504153 Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 1/5] drm/amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() 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 @ 2024-09-09 9:42 ` Markus Elfring 1 sibling, 0 replies; 60+ messages in thread From: Markus Elfring @ 2024-09-09 9:42 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Felix Kuehling, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Lijo Lazar, Ma Jun, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: cocci, LKML > Date: Tue, 11 Apr 2023 10:52:48 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the function “amdgpu_ras_interrupt_dispatch”. > > Thus avoid the risk for undefined behaviour by moving the assignment > for the variable “data” behind the null pointer check. > > This issue was detected by using the Coccinelle software. > > Fixes: c030f2e4166c3f5597c7e7a70bcd9ab383695de4 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > index 4069bce9479f..a920c7888d07 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > @@ -1730,11 +1730,12 @@ int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev, > struct ras_dispatch_if *info) > { > struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head); > - struct ras_ih_data *data = &obj->ih_data; > + struct ras_ih_data *data; > > if (!obj) > return -EINVAL; > > + data = &obj->ih_data; > if (data->inuse == 0) > return 0; > I would like to point out that another software adjustment got the desired development attention (on 2024-05-11). See also: Commit 4c11d30c95576937c6c35e6f29884761f2dddb43 ("drm/amdgpu: Fix the null pointer dereference to ras_manager") Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() 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:43 ` Markus Elfring 2023-04-11 15:04 ` Christian König 2023-04-11 13:46 ` [PATCH 3/5] drm/amd/display: Delete three unnecessary variable initialisations " Markus Elfring ` (3 subsequent siblings) 5 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2023-04-11 13:43 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci 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 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() 2023-04-11 13:43 ` [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() Markus Elfring @ 2023-04-11 15:04 ` Christian König 2023-05-16 16:40 ` Markus Elfring 0 siblings, 1 reply; 60+ messages in thread From: Christian König @ 2023-04-11 15:04 UTC (permalink / raw) To: Markus Elfring, kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci Am 11.04.23 um 15:43 schrieb Markus Elfring: > 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. It might be that the NULL check doesn't make sense in the first place, but since I'm not an expert for this code I can't fully judge. On the other hand the patches clearly look like nice cleanups to me, so feel free to add an Acked-by: Christian König <christian.koenig@amd.com> to the series. Thanks, Christian. > > 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 > ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() 2023-04-11 15:04 ` Christian König @ 2023-05-16 16:40 ` Markus Elfring 0 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-05-16 16:40 UTC (permalink / raw) To: Christian König, kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu, Felix Kuehling Cc: LKML, cocci >> 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. > > It might be that the NULL check doesn't make sense in the first place, but since I'm not an expert for this code I can't fully judge. Will the source code and patch review evolve any more? > On the other hand the patches clearly look like nice cleanups to me, so feel free to add an Acked-by: Christian König <christian.koenig@amd.com> to the series. Will such a positive feedback trigger any further collateral evolution? Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 3/5] drm/amd/display: Delete three unnecessary variable initialisations in trigger_hotplug() 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:43 ` [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() Markus Elfring @ 2023-04-11 13:46 ` Markus Elfring 2023-04-11 13:48 ` [PATCH 4/5] drm/amd/display: Delete a redundant statement " Markus Elfring ` (2 subsequent siblings) 5 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-11 13:46 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci Date: Tue, 11 Apr 2023 12:34:42 +0200 The variables “link”, “wr_buf” and “ret” will eventually be set to appropriate values a bit later. Thus omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 6 +++--- 1 file changed, 3 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 b3cfd7dfbb28..a37d23a13d7b 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 @@ -1206,16 +1206,16 @@ static ssize_t trigger_hotplug(struct file *f, const char __user *buf, { struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private; struct drm_connector *connector; - struct dc_link *link = NULL; + struct dc_link *link; struct drm_device *dev; struct amdgpu_device *adev; enum dc_connection_type new_connection_type = dc_connection_none; - char *wr_buf = NULL; + char *wr_buf; uint32_t wr_buf_size = 42; int max_param_num = 1; long param[1] = {0}; uint8_t param_nums = 0; - bool ret = false; + bool ret; if (!aconnector || !aconnector->dc_link) return -EINVAL; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 4/5] drm/amd/display: Delete a redundant statement in trigger_hotplug() 2023-04-11 13:36 ` [PATCH 0/5] drm/amd: Adjustments for three function implementations Markus Elfring ` (2 preceding siblings ...) 2023-04-11 13:46 ` [PATCH 3/5] drm/amd/display: Delete three unnecessary variable initialisations " Markus Elfring @ 2023-04-11 13:48 ` 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 5 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-11 13:48 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci Date: Tue, 11 Apr 2023 13:26:35 +0200 An immediate return is performed by this function after a null pointer was detected for the member “dc_link” in the data structure “amdgpu_dm_connector”. This check was repeated within one if branch. Thus omit such a redundant statement. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 3 --- 1 file changed, 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 a37d23a13d7b..4805a482dc49 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 @@ -1278,9 +1278,6 @@ static ssize_t trigger_hotplug(struct file *f, const char __user *buf, drm_kms_helper_connector_hotplug_event(connector); } else if (param[0] == 0) { - if (!aconnector->dc_link) - goto unlock; - link = aconnector->dc_link; if (link->local_sink) { -- 2.40.0 Am 11.04.23 um 15:36 schrieb Markus Elfring: > Date: Tue, 11 Apr 2023 14:36:36 +0200 > > Some update suggestions were taken into account > from static source code analysis. > > Markus Elfring (5) > amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() > display: Move three variable assignments behind condition checks in trigger_hotplug() > display: Delete three unnecessary variable initialisations in trigger_hotplug() > display: Delete a redundant statement in trigger_hotplug() > display: Move an expression into a return statement in dcn201_link_encoder_create() > > drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 ++- > .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 19 ++++++++++--------- > .../amd/display/dc/dcn201/dcn201_resource.c | 4 +--- > 3 files changed, 13 insertions(+), 13 deletions(-) > ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 5/5] drm/amd/display: Move an expression into a return statement in dcn201_link_encoder_create() 2023-04-11 13:36 ` [PATCH 0/5] drm/amd: Adjustments for three function implementations Markus Elfring ` (3 preceding siblings ...) 2023-04-11 13:48 ` [PATCH 4/5] drm/amd/display: Delete a redundant statement " Markus Elfring @ 2023-04-11 13:50 ` Markus Elfring 2024-01-05 19:21 ` [PATCH 0/5] drm/amd: Adjustments for three function implementations Markus Elfring 5 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-11 13:50 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci Date: Tue, 11 Apr 2023 14:04:57 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “dcn201_link_encoder_create”. Thus avoid the risk for undefined behaviour by moving the usage of an expression into a return statement. This issue was detected by using the Coccinelle software. Fixes: 3f68c01be9a2227de1e190317fe34a6fb835a094 ("drm/amd/display: add cyan_skillfish display support") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/amd/display/dc/dcn201/dcn201_resource.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/dcn201/dcn201_resource.c b/drivers/gpu/drm/amd/display/dc/dcn201/dcn201_resource.c index 6ea70da28aaa..a1b44c7bd34b 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn201/dcn201_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn201/dcn201_resource.c @@ -791,7 +791,6 @@ static struct link_encoder *dcn201_link_encoder_create( { struct dcn20_link_encoder *enc20 = kzalloc(sizeof(struct dcn20_link_encoder), GFP_ATOMIC); - struct dcn10_link_encoder *enc10 = &enc20->enc10; if (!enc20) return NULL; @@ -804,8 +803,7 @@ static struct link_encoder *dcn201_link_encoder_create( &link_enc_hpd_regs[enc_init_data->hpd_source], &le_shift, &le_mask); - - return &enc10->base; + return &enc20->enc10.base; } static struct clock_source *dcn201_clock_source_create( -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH 0/5] drm/amd: Adjustments for three function implementations 2023-04-11 13:36 ` [PATCH 0/5] drm/amd: Adjustments for three function implementations Markus Elfring ` (4 preceding siblings ...) 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 ` Markus Elfring 5 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2024-01-05 19:21 UTC (permalink / raw) To: kernel-janitors, amd-gfx, dri-devel, Alan Liu, Alex Deucher, Alex Hung, Alexey Kodanev, Aurabindo Pillai, Bhanuprakash Modem, Candice Li, Charlene Liu, Christian König, Daniel Vetter, David Airlie, David Tadokoro, Eryk Brol, Greg Kroah-Hartman, Hamza Mahfooz, Harry Wentland, Hawking Zhang, hersen wu, Jiapeng Chong, Jun Lei, Leo Li, Mikita Lipski, Rodrigo Siqueira, Stanley Yang, Tao Zhou, Tom Rix, Victor Zhao, Wayne Lin, Wenjing Liu, Xinhui Pan, YiPeng Chai, Zhan Liu Cc: LKML, cocci > Date: Tue, 11 Apr 2023 14:36:36 +0200 > > Some update suggestions were taken into account > from static source code analysis. > > Markus Elfring (5) > amdgpu: Move a variable assignment behind a null pointer check in amdgpu_ras_interrupt_dispatch() > display: Move three variable assignments behind condition checks in trigger_hotplug() > display: Delete three unnecessary variable initialisations in trigger_hotplug() > display: Delete a redundant statement in trigger_hotplug() > display: Move an expression into a return statement in dcn201_link_encoder_create() > > drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 ++- > .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 19 ++++++++++--------- > .../amd/display/dc/dcn201/dcn201_resource.c | 4 +--- > 3 files changed, 13 insertions(+), 13 deletions(-) Is this patch series still in review queues? See also: https://lore.kernel.org/cocci/2258ce64-2a14-6778-8319-b342b06a1f33@web.de/ https://sympa.inria.fr/sympa/arc/cocci/2023-04/msg00034.html Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions [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 16:38 ` Markus Elfring 2023-04-11 16:43 ` Dmitry Baryshkov ` (2 more replies) 2023-04-13 19:44 ` [PATCH] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() Markus Elfring ` (3 subsequent siblings) 5 siblings, 3 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-11 16:38 UTC (permalink / raw) To: kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Dmitry Baryshkov, Jeykumar Sankaran, Jordan Crouse, Rob Clark, Sean Paul, Vinod Koul Cc: LKML, cocci Date: Tue, 11 Apr 2023 18:24:24 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. Thus avoid the risk for undefined behaviour by removing extra initialisations for the variable “c” (also because it was already reassigned with the same value behind this pointer check). This issue was detected by using the Coccinelle software. Fixes: 25fdd5933e4c0f5fe2ea5cd59994f8ac5fbe90ef ("drm/msm: Add SDM845 DPU support") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c index 0fcad9760b6f..870ab3ebbc94 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c @@ -176,7 +176,7 @@ static int dpu_hw_pp_enable_te(struct dpu_hw_pingpong *pp, bool enable) static int dpu_hw_pp_connect_external_te(struct dpu_hw_pingpong *pp, bool enable_external_te) { - struct dpu_hw_blk_reg_map *c = &pp->hw; + struct dpu_hw_blk_reg_map *c; u32 cfg; int orig; @@ -221,7 +221,7 @@ static int dpu_hw_pp_get_vsync_info(struct dpu_hw_pingpong *pp, static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp) { - struct dpu_hw_blk_reg_map *c = &pp->hw; + struct dpu_hw_blk_reg_map *c; u32 height, init; u32 line = 0xFFFF; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions 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 2 siblings, 0 replies; 60+ messages in thread From: Dmitry Baryshkov @ 2023-04-11 16:43 UTC (permalink / raw) To: Markus Elfring, kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Rob Clark, Sean Paul, Vinod Koul Cc: LKML, cocci On 11/04/2023 19:38, Markus Elfring wrote: > Date: Tue, 11 Apr 2023 18:24:24 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > > Thus avoid the risk for undefined behaviour by removing extra > initialisations for the variable “c” (also because it was already > reassigned with the same value behind this pointer check). > > This issue was detected by using the Coccinelle software. > > Fixes: 25fdd5933e4c0f5fe2ea5cd59994f8ac5fbe90ef ("drm/msm: Add SDM845 DPU support") Plese follow the format for the Fixes tags and limit the hash to 12 chars. Proper tag: Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support") Other than that LGTM. > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > index 0fcad9760b6f..870ab3ebbc94 100644 > --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > @@ -176,7 +176,7 @@ static int dpu_hw_pp_enable_te(struct dpu_hw_pingpong *pp, bool enable) > static int dpu_hw_pp_connect_external_te(struct dpu_hw_pingpong *pp, > bool enable_external_te) > { > - struct dpu_hw_blk_reg_map *c = &pp->hw; > + struct dpu_hw_blk_reg_map *c; > u32 cfg; > int orig; > > @@ -221,7 +221,7 @@ static int dpu_hw_pp_get_vsync_info(struct dpu_hw_pingpong *pp, > > static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp) > { > - struct dpu_hw_blk_reg_map *c = &pp->hw; > + struct dpu_hw_blk_reg_map *c; > u32 height, init; > u32 line = 0xFFFF; > > -- > 2.40.0 > -- With best wishes Dmitry ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions 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 2 siblings, 0 replies; 60+ messages in thread From: Abhinav Kumar @ 2023-04-11 16:44 UTC (permalink / raw) To: Markus Elfring, kernel-janitors, freedreno, dri-devel, linux-arm-msm, Archit Taneja, Daniel Vetter, David Airlie, Dmitry Baryshkov, Jeykumar Sankaran, Jordan Crouse, Rob Clark, Sean Paul, Vinod Koul Cc: LKML, cocci On 4/11/2023 9:38 AM, Markus Elfring wrote: > Date: Tue, 11 Apr 2023 18:24:24 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > > Thus avoid the risk for undefined behaviour by removing extra > initialisations for the variable “c” (also because it was already > reassigned with the same value behind this pointer check). > > This issue was detected by using the Coccinelle software. > > Fixes: 25fdd5933e4c0f5fe2ea5cd59994f8ac5fbe90ef ("drm/msm: Add SDM845 DPU support") Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support") We usually have 12 chars of the hash. Other than that, Reviewed-by: Abhinav Kumar <quic_abhinavk@quicinc.com> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > index 0fcad9760b6f..870ab3ebbc94 100644 > --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > @@ -176,7 +176,7 @@ static int dpu_hw_pp_enable_te(struct dpu_hw_pingpong *pp, bool enable) > static int dpu_hw_pp_connect_external_te(struct dpu_hw_pingpong *pp, > bool enable_external_te) > { > - struct dpu_hw_blk_reg_map *c = &pp->hw; > + struct dpu_hw_blk_reg_map *c; > u32 cfg; > int orig; > > @@ -221,7 +221,7 @@ static int dpu_hw_pp_get_vsync_info(struct dpu_hw_pingpong *pp, > > static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp) > { > - struct dpu_hw_blk_reg_map *c = &pp->hw; > + struct dpu_hw_blk_reg_map *c; > u32 height, init; > u32 line = 0xFFFF; > > -- > 2.40.0 > ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH RESEND] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions 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 ` Markus Elfring 2025-03-02 23:01 ` Dmitry Baryshkov 2 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2025-03-02 20:56 UTC (permalink / raw) To: kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Dmitry Baryshkov, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul Cc: cocci, LKML From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 11 Apr 2023 18:24:24 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. Thus avoid the risk for undefined behaviour by removing extra initialisations for the variable “c” (also because it was already reassigned with the same value behind this pointer check). This issue was detected by using the Coccinelle software. Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c index 0fcad9760b6f..870ab3ebbc94 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c @@ -176,7 +176,7 @@ static int dpu_hw_pp_enable_te(struct dpu_hw_pingpong *pp, bool enable) static int dpu_hw_pp_connect_external_te(struct dpu_hw_pingpong *pp, bool enable_external_te) { - struct dpu_hw_blk_reg_map *c = &pp->hw; + struct dpu_hw_blk_reg_map *c; u32 cfg; int orig; @@ -221,7 +221,7 @@ static int dpu_hw_pp_get_vsync_info(struct dpu_hw_pingpong *pp, static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp) { - struct dpu_hw_blk_reg_map *c = &pp->hw; + struct dpu_hw_blk_reg_map *c; u32 height, init; u32 line = 0xFFFF; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions 2025-03-02 20:56 ` [PATCH RESEND] " Markus Elfring @ 2025-03-02 23:01 ` Dmitry Baryshkov 2025-03-03 7:14 ` Dan Carpenter 0 siblings, 1 reply; 60+ messages in thread From: Dmitry Baryshkov @ 2025-03-02 23:01 UTC (permalink / raw) To: Markus Elfring Cc: kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML On Sun, Mar 02, 2025 at 09:56:00PM +0100, Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 11 Apr 2023 18:24:24 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > > Thus avoid the risk for undefined behaviour by removing extra > initialisations for the variable “c” (also because it was already > reassigned with the same value behind this pointer check). > > This issue was detected by using the Coccinelle software. Please don't send resends and/or new iterations in response to your previous patchsets. Otherwise they have a pretty high chance to be ignored by the maintainers. Use a fresh git-send-email command to send new patchset. > > Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support") > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > index 0fcad9760b6f..870ab3ebbc94 100644 > --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c > @@ -176,7 +176,7 @@ static int dpu_hw_pp_enable_te(struct dpu_hw_pingpong *pp, bool enable) > static int dpu_hw_pp_connect_external_te(struct dpu_hw_pingpong *pp, > bool enable_external_te) > { > - struct dpu_hw_blk_reg_map *c = &pp->hw; > + struct dpu_hw_blk_reg_map *c; > u32 cfg; > int orig; > > @@ -221,7 +221,7 @@ static int dpu_hw_pp_get_vsync_info(struct dpu_hw_pingpong *pp, > > static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp) > { > - struct dpu_hw_blk_reg_map *c = &pp->hw; > + struct dpu_hw_blk_reg_map *c; > u32 height, init; > u32 line = 0xFFFF; > > -- > 2.40.0 > -- With best wishes Dmitry ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions 2025-03-02 23:01 ` Dmitry Baryshkov @ 2025-03-03 7:14 ` Dan Carpenter 2025-03-03 8:15 ` [RESEND] " Markus Elfring 2025-03-05 8:40 ` [RFC] Clarification for “undefined behaviour”? Markus Elfring 0 siblings, 2 replies; 60+ messages in thread From: Dan Carpenter @ 2025-03-03 7:14 UTC (permalink / raw) To: Dmitry Baryshkov Cc: Markus Elfring, kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML On Mon, Mar 03, 2025 at 01:01:40AM +0200, Dmitry Baryshkov wrote: > On Sun, Mar 02, 2025 at 09:56:00PM +0100, Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Tue, 11 Apr 2023 18:24:24 +0200 > > > > The address of a data structure member was determined before > > a corresponding null pointer check in the implementation of > > the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > > > > Thus avoid the risk for undefined behaviour by removing extra > > initialisations for the variable “c” (also because it was already > > reassigned with the same value behind this pointer check). There is no undefined behavior here. > > > > This issue was detected by using the Coccinelle software. > > Please don't send resends and/or new iterations in response to your > previous patchsets. Otherwise they have a pretty high chance to be > ignored by the maintainers. Use a fresh git-send-email command to send > new patchset. > > > > > Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support") Remove the Fixes tag. This patch is fine as a clean up. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> regards, dan carpenter ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RESEND] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions 2025-03-03 7:14 ` Dan Carpenter @ 2025-03-03 8:15 ` Markus Elfring 2025-03-03 8:24 ` Dan Carpenter 2025-03-05 8:40 ` [RFC] Clarification for “undefined behaviour”? Markus Elfring 1 sibling, 1 reply; 60+ messages in thread From: Markus Elfring @ 2025-03-03 8:15 UTC (permalink / raw) To: Dan Carpenter, Dmitry Baryshkov, freedreno, dri-devel, linux-arm-msm Cc: kernel-janitors, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML >>> The address of a data structure member was determined before >>> a corresponding null pointer check in the implementation of >>> the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. >>> >>> Thus avoid the risk for undefined behaviour by removing extra >>> initialisations for the variable “c” (also because it was already >>> reassigned with the same value behind this pointer check). > > There is no undefined behavior here. Will any software development concerns evolve further also according to undesirable null pointer dereferences? https://wiki.sei.cmu.edu/confluence/display/c/EXP34-C.+Do+not+dereference+null+pointers Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RESEND] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions 2025-03-03 8:15 ` [RESEND] " Markus Elfring @ 2025-03-03 8:24 ` Dan Carpenter 0 siblings, 0 replies; 60+ messages in thread From: Dan Carpenter @ 2025-03-03 8:24 UTC (permalink / raw) To: Markus Elfring Cc: Dmitry Baryshkov, freedreno, dri-devel, linux-arm-msm, kernel-janitors, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML On Mon, Mar 03, 2025 at 09:15:14AM +0100, Markus Elfring wrote: > >>> The address of a data structure member was determined before > >>> a corresponding null pointer check in the implementation of > >>> the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > >>> > >>> Thus avoid the risk for undefined behaviour by removing extra > >>> initialisations for the variable “c” (also because it was already > >>> reassigned with the same value behind this pointer check). > > > > There is no undefined behavior here. > Will any software development concerns evolve further also according to > undesirable null pointer dereferences? > https://wiki.sei.cmu.edu/confluence/display/c/EXP34-C.+Do+not+dereference+null+pointers > It's not a NULL pointer dereference. It's just pointer math. It was a common way to implement offsetof() before we had a builtin for that. samples/bpf/test_lru_dist.c # define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) regards, dan carpenter ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RFC] Clarification for “undefined behaviour”? 2025-03-03 7:14 ` Dan Carpenter 2025-03-03 8:15 ` [RESEND] " Markus Elfring @ 2025-03-05 8:40 ` Markus Elfring 2025-03-05 8:51 ` Dan Carpenter 1 sibling, 1 reply; 60+ messages in thread From: Markus Elfring @ 2025-03-05 8:40 UTC (permalink / raw) To: Dan Carpenter, Dmitry Baryshkov, kernel-janitors, freedreno, dri-devel, linux-arm-msm Cc: Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML >>> The address of a data structure member was determined before >>> a corresponding null pointer check in the implementation of >>> the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. >>> >>> Thus avoid the risk for undefined behaviour by removing extra >>> initialisations for the variable “c” (also because it was already >>> reassigned with the same value behind this pointer check). > There is no undefined behavior here. Is there a need to improve the wording precision? There are words which denote a special meaning according to aspects of the programming language “C”. https://en.cppreference.com/w/c/language/behavior Dereferences of null pointers are treated in special ways. The system might be configurable to collaborate also with data accesses together with the address “zero”. Would you like to distinguish supported software functionality any further? Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RFC] Clarification for “undefined behaviour”? 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 0 siblings, 2 replies; 60+ messages in thread From: Dan Carpenter @ 2025-03-05 8:51 UTC (permalink / raw) To: Markus Elfring Cc: Dmitry Baryshkov, kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML On Wed, Mar 05, 2025 at 09:40:43AM +0100, Markus Elfring wrote: > >>> The address of a data structure member was determined before > >>> a corresponding null pointer check in the implementation of > >>> the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > >>> > >>> Thus avoid the risk for undefined behaviour by removing extra > >>> initialisations for the variable “c” (also because it was already > >>> reassigned with the same value behind this pointer check). > > There is no undefined behavior here. > > Is there a need to improve the wording precision? > > There are words which denote a special meaning according to aspects of > the programming language “C”. > https://en.cppreference.com/w/c/language/behavior > > Dereferences of null pointers are treated in special ways. This not a dereference. It's just pointer math. regards, dan carpenter ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RFC] Clarification for “undefined behaviour”? 2025-03-05 8:51 ` Dan Carpenter @ 2025-03-05 9:20 ` Markus Elfring 2025-03-05 14:17 ` David Laight 1 sibling, 0 replies; 60+ messages in thread From: Markus Elfring @ 2025-03-05 9:20 UTC (permalink / raw) To: Dan Carpenter, kernel-janitors, freedreno, dri-devel, linux-arm-msm Cc: Dmitry Baryshkov, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML >> Dereferences of null pointers are treated in special ways. > > This not a dereference. It's just pointer math. Do you prefer the wording “member access through pointer” occasionally? https://en.cppreference.com/w/c/language/operator_member_access How do you tend to describe (and detect) null pointer dereferences so far? https://wiki.sei.cmu.edu/confluence/display/c/EXP34-C.+Do+not+dereference+null+pointers#EXP34C.Donotdereferencenullpointers-AutomatedDetection Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RFC] Clarification for “undefined behaviour”? 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 1 sibling, 1 reply; 60+ messages in thread From: David Laight @ 2025-03-05 14:17 UTC (permalink / raw) To: Dan Carpenter Cc: Markus Elfring, Dmitry Baryshkov, kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML On Wed, 5 Mar 2025 11:51:59 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote: > On Wed, Mar 05, 2025 at 09:40:43AM +0100, Markus Elfring wrote: > > >>> The address of a data structure member was determined before > > >>> a corresponding null pointer check in the implementation of > > >>> the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > > >>> > > >>> Thus avoid the risk for undefined behaviour by removing extra > > >>> initialisations for the variable “c” (also because it was already > > >>> reassigned with the same value behind this pointer check). > > > There is no undefined behavior here. > > > > Is there a need to improve the wording precision? > > > > There are words which denote a special meaning according to aspects of > > the programming language “C”. > > https://en.cppreference.com/w/c/language/behavior > > > > Dereferences of null pointers are treated in special ways. > > This not a dereference. It's just pointer math. And the 'fun' starts because NULL isn't required to use the all-zero bit pattern. Regardless of the bit-pattern, things like (void *)(1 - 1) are valid NULL pointers. Of course, while C allows this, I doubt NULL has ever been other than 0. (It was 0 on a system I used many years ago where the O/S invalid pointer was ~0.) I know Clang has started warning about arithmetic on NULL. I wonder when it is going to start warning about memset(p, 0, sz) for anything that contains a pointer - equally invalid. David ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RFC] Clarification for “undefined behaviour”? 2025-03-05 14:17 ` David Laight @ 2025-03-05 14:30 ` Dan Carpenter 2025-03-05 21:35 ` David Laight 0 siblings, 1 reply; 60+ messages in thread From: Dan Carpenter @ 2025-03-05 14:30 UTC (permalink / raw) To: David Laight Cc: Markus Elfring, Dmitry Baryshkov, kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML On Wed, Mar 05, 2025 at 02:17:32PM +0000, David Laight wrote: > On Wed, 5 Mar 2025 11:51:59 +0300 > Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > On Wed, Mar 05, 2025 at 09:40:43AM +0100, Markus Elfring wrote: > > > >>> The address of a data structure member was determined before > > > >>> a corresponding null pointer check in the implementation of > > > >>> the functions “dpu_hw_pp_enable_te” and “dpu_hw_pp_get_vsync_info”. > > > >>> > > > >>> Thus avoid the risk for undefined behaviour by removing extra > > > >>> initialisations for the variable “c” (also because it was already > > > >>> reassigned with the same value behind this pointer check). > > > > There is no undefined behavior here. > > > > > > Is there a need to improve the wording precision? > > > > > > There are words which denote a special meaning according to aspects of > > > the programming language “C”. > > > https://en.cppreference.com/w/c/language/behavior > > > > > > Dereferences of null pointers are treated in special ways. > > > > This not a dereference. It's just pointer math. > > And the 'fun' starts because NULL isn't required to use the all-zero > bit pattern. > Regardless of the bit-pattern, things like (void *)(1 - 1) are valid > NULL pointers. > > Of course, while C allows this, I doubt NULL has ever been other than 0. > (It was 0 on a system I used many years ago where the O/S invalid pointer > was ~0.) Kernel style guidelines don't even allow if (p == NULL) so we would be screwed. :P > > I know Clang has started warning about arithmetic on NULL. Huh. You're right. $ clang -Weverything test.c test.c:13:22: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 13 | printf("%p\n", NULL + 1); | ~~~~ ^ test.c:13:22: warning: arithmetic on a pointer to void is a GNU extension [-Wgnu-pointer-arith] 13 | printf("%p\n", NULL + 1); | ~~~~ ^ test.c:11:14: warning: unused parameter 'argc' [-Wunused-parameter] 11 | int main(int argc, char *argv[]) | ^ test.c:11:26: warning: unused parameter 'argv' [-Wunused-parameter] 11 | int main(int argc, char *argv[]) | ^ test.c:13:17: warning: unsafe pointer arithmetic [-Wunsafe-buffer-usage] 13 | printf("%p\n", NULL + 1); | ^~~~ /usr/lib/llvm-19/lib/clang/19/include/__stddef_null.h:26:14: note: expanded from macro 'NULL' 26 | #define NULL ((void*)0) | ^~~~~~~~~~ 5 warnings generated. Well, that's stupid. regards, dan carpenter ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [RFC] Clarification for “undefined behaviour”? 2025-03-05 14:30 ` Dan Carpenter @ 2025-03-05 21:35 ` David Laight 0 siblings, 0 replies; 60+ messages in thread From: David Laight @ 2025-03-05 21:35 UTC (permalink / raw) To: Dan Carpenter Cc: Markus Elfring, Dmitry Baryshkov, kernel-janitors, freedreno, dri-devel, linux-arm-msm, Abhinav Kumar, Archit Taneja, Daniel Vetter, David Airlie, Jeykumar Sankaran, Jordan Crouse, Marijn Suijten, Rob Clark, Sean Paul, Simona Vetter, Vinod Koul, cocci, LKML On Wed, 5 Mar 2025 17:30:28 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote: > On Wed, Mar 05, 2025 at 02:17:32PM +0000, David Laight wrote: ... > > And the 'fun' starts because NULL isn't required to use the all-zero > > bit pattern. > > Regardless of the bit-pattern, things like (void *)(1 - 1) are valid > > NULL pointers. > > > > Of course, while C allows this, I doubt NULL has ever been other than 0. > > (It was 0 on a system I used many years ago where the O/S invalid pointer > > was ~0.) > > Kernel style guidelines don't even allow if (p == NULL) so we would be > screwed. :P Doesn't matter: if (!p) ... if (p == 0) ... if (p == (void *)0) ... if (p == NULL) ... if (p == (void *)(constant integer expression with value 0)) ... and the equivalent assignments all behave the same regardless of the bit-pattern use for NULL. So: union { long l; void *p; } lpu; lpu.p = 0; return lpu.l; Returns ABI (implementation) defined constant value. I think the only requirement is that it can never be the address of a valid variable. David ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() [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 16:38 ` [PATCH] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions Markus Elfring @ 2023-04-13 19:44 ` Markus Elfring 2025-03-02 18:02 ` [PATCH RESEND] " Markus Elfring 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (2 subsequent siblings) 5 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2023-04-13 19:44 UTC (permalink / raw) To: kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Ralf Bächle, Yihao Han Cc: LKML, cocci Date: Thu, 13 Apr 2023 21:35:36 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “au1100fb_setmode”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “info” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: 3b495f2bb749b828499135743b9ddec46e34fda8 ("Au1100 FB driver uplift for 2.6.") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/au1100fb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c index cb317398e71a..fcb47b350bc9 100644 --- a/drivers/video/fbdev/au1100fb.c +++ b/drivers/video/fbdev/au1100fb.c @@ -137,13 +137,15 @@ static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi) */ int au1100fb_setmode(struct au1100fb_device *fbdev) { - struct fb_info *info = &fbdev->info; + struct fb_info *info; u32 words; int index; if (!fbdev) return -EINVAL; + info = &fbdev->info; + /* Update var-dependent FB info */ if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) { if (info->var.bits_per_pixel <= 8) { -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 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 ` Markus Elfring 2025-03-03 9:19 ` Uwe Kleine-König 0 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2025-03-02 18:02 UTC (permalink / raw) To: kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Helge Deller, Thomas Zimmermann, Uwe Kleine-König, Yihao Han Cc: cocci, LKML From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 13 Apr 2023 21:35:36 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “au1100fb_setmode”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “info” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: 3b495f2bb749 ("Au1100 FB driver uplift for 2.6.") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/au1100fb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c index cb317398e71a..fcb47b350bc9 100644 --- a/drivers/video/fbdev/au1100fb.c +++ b/drivers/video/fbdev/au1100fb.c @@ -137,13 +137,15 @@ static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi) */ int au1100fb_setmode(struct au1100fb_device *fbdev) { - struct fb_info *info = &fbdev->info; + struct fb_info *info; u32 words; int index; if (!fbdev) return -EINVAL; + info = &fbdev->info; + /* Update var-dependent FB info */ if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) { if (info->var.bits_per_pixel <= 8) { -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 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-08 21:26 ` [PATCH RESEND] " Helge Deller 0 siblings, 2 replies; 60+ messages in thread From: Uwe Kleine-König @ 2025-03-03 9:19 UTC (permalink / raw) To: Markus Elfring Cc: kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML [-- Attachment #1: Type: text/plain, Size: 850 bytes --] Hello, On Sun, Mar 02, 2025 at 07:02:12PM +0100, Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 13 Apr 2023 21:35:36 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the function “au1100fb_setmode”. > > Thus avoid the risk for undefined behaviour by moving the assignment > for the variable “info” behind the null pointer check. > > This issue was detected by using the Coccinelle software. > > Fixes: 3b495f2bb749 ("Au1100 FB driver uplift for 2.6.") > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Should also get Cc: stable@vger.kernel.org to ensure this is backported to stable. Best regards Uwe [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 2025-03-03 9:19 ` Uwe Kleine-König @ 2025-03-03 10:08 ` Dan Carpenter 2025-03-03 10:08 ` Dan Carpenter ` (2 more replies) 2025-03-08 21:26 ` [PATCH RESEND] " Helge Deller 1 sibling, 3 replies; 60+ messages in thread From: Dan Carpenter @ 2025-03-03 10:08 UTC (permalink / raw) To: Uwe Kleine-König Cc: Markus Elfring, kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML On Mon, Mar 03, 2025 at 10:19:06AM +0100, Uwe Kleine-König wrote: > Hello, > > On Sun, Mar 02, 2025 at 07:02:12PM +0100, Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Thu, 13 Apr 2023 21:35:36 +0200 > > > > The address of a data structure member was determined before > > a corresponding null pointer check in the implementation of > > the function “au1100fb_setmode”. > > > > Thus avoid the risk for undefined behaviour by moving the assignment > > for the variable “info” behind the null pointer check. > > > > This issue was detected by using the Coccinelle software. > > > > Fixes: 3b495f2bb749 ("Au1100 FB driver uplift for 2.6.") > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> > > Should also get > > Cc: stable@vger.kernel.org > > to ensure this is backported to stable. It's not a bugfix, it's a cleanup. That's not a dereference, it's just pointer math. It shouldn't have a Fixes tag. Real bugs where we dereference a pointer and then check for NULL don't last long in the kernel. Most of the stuff Markus is sending is false positives like this. regards, dan carpenter ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 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 2 siblings, 0 replies; 60+ messages in thread From: Dan Carpenter @ 2025-03-03 10:08 UTC (permalink / raw) To: Uwe Kleine-König Cc: Markus Elfring, kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML On Mon, Mar 03, 2025 at 10:19:06AM +0100, Uwe Kleine-König wrote: > Hello, > > On Sun, Mar 02, 2025 at 07:02:12PM +0100, Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Thu, 13 Apr 2023 21:35:36 +0200 > > > > The address of a data structure member was determined before > > a corresponding null pointer check in the implementation of > > the function “au1100fb_setmode”. > > > > Thus avoid the risk for undefined behaviour by moving the assignment > > for the variable “info” behind the null pointer check ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 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 2 siblings, 0 replies; 60+ messages in thread From: Dan Carpenter @ 2025-03-03 10:14 UTC (permalink / raw) To: Uwe Kleine-König Cc: Markus Elfring, kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML On Mon, Mar 03, 2025 at 01:08:29PM +0300, Dan Carpenter wrote: > Real bugs where we dereference a pointer and then check for NULL don't > last long in the kernel. Most of the stuff Markus is sending is false > positives like this. Maybe I was too optimistic. Here are the Smatch warnings from the Friday's linux-next. Common false positives are that the pointer can sometimes be NULL but there are other ways to determine without checking explicitly. For example, maybe the caller passes a flag which means it's non-NULL. regards, dan carpenter arch/arm64/kvm/../../../virt/kvm/kvm_main.c:1639 kvm_prepare_memory_region() warn: variable dereferenced before check 'new' (see line 1622) arch/x86/kernel/fpu/xstate.c:1567 fpstate_realloc() warn: variable dereferenced before check 'curfps' (see line 1546) arch/x86/kvm/../../../virt/kvm/kvm_main.c:1639 kvm_prepare_memory_region() warn: variable dereferenced before check 'new' (see line 1622) drivers/base/dd.c:696 really_probe() warn: variable dereferenced before check 'dev->bus' (see line 640) drivers/base/dd.c:720 really_probe() warn: variable dereferenced before check 'dev->bus' (see line 640) drivers/block/drbd/drbd_worker.c:588 make_resync_request() warn: variable dereferenced before check 'peer_device' (see line 587) drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:12341 parse_edid_displayid_vrr() warn: variable dereferenced before check 'edid_ext' (see line 12337) drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn21/rn_clk_mgr.c:775 rn_clk_mgr_construct() warn: variable dereferenced before check 'ctx->dc_bios->integrated_info' (see line 743) drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn301/vg_clk_mgr.c:734 vg_clk_mgr_construct() warn: variable dereferenced before check 'ctx->dc_bios->integrated_info' (see line 720) drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn314/dcn314_clk_mgr.c:899 dcn314_clk_mgr_construct() warn: variable dereferenced before check 'ctx->dc_bios->integrated_info' (see line 838) drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn315/dcn315_clk_mgr.c:715 dcn315_clk_mgr_construct() warn: variable dereferenced before check 'ctx->dc_bios->integrated_info' (see line 654) drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn316/dcn316_clk_mgr.c:655 dcn316_clk_mgr_construct() warn: variable dereferenced before check 'ctx->dc_bios->integrated_info' (see line 634) drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn31/dcn31_clk_mgr.c:789 dcn31_clk_mgr_construct() warn: variable dereferenced before check 'ctx->dc_bios->integrated_info' (see line 728) drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn35/dcn35_clk_mgr.c:1380 dcn35_clk_mgr_construct() warn: variable dereferenced before check 'ctx->dc_bios->integrated_info' (see line 1307) drivers/gpu/drm/i915/gem/i915_gem_shmem.c:174 shmem_sg_alloc_table() warn: variable dereferenced before check 'sg' (see line 163) drivers/gpu/drm/i915/gt/gen6_ppgtt.c:274 gen6_ppgtt_cleanup() warn: variable dereferenced before check 'ppgtt->base.pd' (see line 271) drivers/gpu/drm/i915/gt/intel_execlists_submission.c:3649 rcu_virtual_context_destroy() warn: variable dereferenced before check 've->base.sched_engine' (see line 3623) drivers/gpu/drm/nouveau/nouveau_dp.c:494 nouveau_dp_irq() warn: variable dereferenced before check 'outp' (see line 489) drivers/hid/hid-debug.c:3727 hid_debug_events_read() warn: variable dereferenced before check 'list->hdev' (see line 3713) drivers/net/ethernet/amd/pcnet32.c:1923 pcnet32_probe1() warn: variable dereferenced before check 'pdev' (see line 1843) drivers/net/ethernet/apm/xgene/xgene_enet_main.c:267 xgene_enet_tx_completion() warn: variable dereferenced before check 'skb' (see line 243) drivers/net/ethernet/natsemi/ns83820.c:884 rx_irq() warn: variable dereferenced before check 'skb' (see line 883) drivers/net/ethernet/pensando/ionic/ionic_txrx.c:205 ionic_rx_build_skb() warn: variable dereferenced before check 'buf_info->page' (see line 188) drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c:1236 iwl_setup_interface() warn: variable dereferenced before check 'priv->lib->bt_params' (see line 1229) drivers/net/wireless/intel/iwlwifi/dvm/main.c:1114 iwl_init_drv() warn: variable dereferenced before check 'priv->lib->bt_params' (see line 1109) drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c:307 mt76_connac2_mac_tx_rate_val() warn: variable dereferenced before check 'conf' (see line 300) drivers/net/wireless/mediatek/mt76/mt7925/mac.c:851 mt7925_tx_check_aggr() warn: variable dereferenced before check 'sta' (see line 847) drivers/nvme/host/ioctl.c:173 nvme_map_user_request() warn: variable dereferenced before check 'bio' (see line 162) drivers/platform/mellanox/mlxreg-lc.c:903 mlxreg_lc_probe() warn: variable dereferenced before check 'data->notifier' (see line 828) drivers/scsi/aacraid/commsup.c:2344 aac_command_thread() warn: variable dereferenced before check 'dev->queues' (see line 2332) drivers/scsi/aic7xxx/aic79xx_osm.c:1837 ahd_done() warn: variable dereferenced before check 'cmd' (see line 1793) drivers/scsi/csiostor/csio_mb.c:932 csio_fcoe_vnp_alloc_init_mb() warn: variable dereferenced before check 'vnport_wwnn' (see line 929) drivers/scsi/ips.c:2560 ips_next() warn: variable dereferenced before check 'scb->scsi_cmd' (see line 2554) drivers/scsi/ips.c:2568 ips_next() warn: variable dereferenced before check 'scb->scsi_cmd' (see line 2554) drivers/scsi/ips.c:2593 ips_next() warn: variable dereferenced before check 'scb->scsi_cmd' (see line 2554) drivers/scsi/libsas/sas_scsi_host.c:119 sas_scsi_task_done() warn: variable dereferenced before check 'sc' (see line 110) drivers/scsi/lpfc/lpfc_bsg.c:1332 lpfc_bsg_hba_get_event() warn: variable dereferenced before check 'evt_dat' (see line 1299) drivers/slimbus/qcom-ngd-ctrl.c:884 qcom_slim_ngd_xfer_msg() warn: variable dereferenced before check 'txn->msg' (see line 808) drivers/spi/spi-offload.c:186 spi_offload_trigger_get() warn: variable dereferenced before check 'trigger->ops' (see line 176) drivers/staging/media/atomisp/pci/isp/kernels/output/output_1.0/ia_css_output.host.c:58 ia_css_output_config() warn: variable dereferenced before check 'from->info' (see line 53) drivers/usb/gadget/udc/tegra-xudc.c:2681 tegra_xudc_handle_transfer_completion() warn: variable dereferenced before check 'ep->desc' (see line 2679) drivers/usb/musb/musb_core.c:964 musb_handle_intr_disconnect() warn: variable dereferenced before check 'musb->hcd' (see line 963) fs/bcachefs/journal.c:1187 __bch2_set_nr_journal_buckets() warn: variable dereferenced before check 'c' (see line 1184) fs/efs/inode.c:299 efs_map_block() warn: variable dereferenced before check 'bh' (see line 292) fs/efs/inode.c:304 efs_map_block() warn: variable dereferenced before check 'bh' (see line 292) fs/efs/inode.c:309 efs_map_block() warn: variable dereferenced before check 'bh' (see line 292) fs/nfs/write.c:808 nfs_inode_remove_request() warn: variable dereferenced before check 'folio' (see line 805) fs/ocfs2/dlm/dlmrecovery.c:1590 dlm_mig_lockres_worker() warn: variable dereferenced before check 'res' (see line 1563) fs/ocfs2/move_extents.c:322 ocfs2_defrag_extent() warn: variable dereferenced before check 'context->data_ac' (see line 279) fs/ocfs2/namei.c:1455 ocfs2_rename() warn: variable dereferenced before check 'newfe_bh' (see line 1452) fs/ocfs2/namei.c:1637 ocfs2_rename() warn: variable dereferenced before check 'old_dir_bh' (see line 1618) fs/smb/client/file.c:3085 cifs_oplock_break() warn: variable dereferenced before check 'inode' (see line 3056) lib/reed_solomon/decode_rs.c:315 decode_rs16() warn: variable dereferenced before check 'par' (see line 81) net/core/failover.c:85 failover_slave_register() warn: variable dereferenced before check 'fops' (see line 66) net/mpls/mpls_iptunnel.c:156 mpls_xmit() warn: variable dereferenced before check 'out_dev' (see line 56) ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 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 2 siblings, 2 replies; 60+ messages in thread From: Uwe Kleine-König @ 2025-03-03 10:30 UTC (permalink / raw) To: Dan Carpenter Cc: Markus Elfring, kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML [-- Attachment #1: Type: text/plain, Size: 1855 bytes --] On Mon, Mar 03, 2025 at 01:08:29PM +0300, Dan Carpenter wrote: > On Mon, Mar 03, 2025 at 10:19:06AM +0100, Uwe Kleine-König wrote: > > Hello, > > > > On Sun, Mar 02, 2025 at 07:02:12PM +0100, Markus Elfring wrote: > > > From: Markus Elfring <elfring@users.sourceforge.net> > > > Date: Thu, 13 Apr 2023 21:35:36 +0200 > > > > > > The address of a data structure member was determined before > > > a corresponding null pointer check in the implementation of > > > the function “au1100fb_setmode”. > > > > > > Thus avoid the risk for undefined behaviour by moving the assignment > > > for the variable “info” behind the null pointer check. > > > > > > This issue was detected by using the Coccinelle software. > > > > > > Fixes: 3b495f2bb749 ("Au1100 FB driver uplift for 2.6.") > > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > > > Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> > > > > Should also get > > > > Cc: stable@vger.kernel.org > > > > to ensure this is backported to stable. > > It's not a bugfix, it's a cleanup. That's not a dereference, it's > just pointer math. It shouldn't have a Fixes tag. > > Real bugs where we dereference a pointer and then check for NULL don't > last long in the kernel. Most of the stuff Markus is sending is false > positives like this. I thought a compiler translating the code struct fb_info *info = &fbdev->info; if (!fbdev) return -EINVAL; is free (and expected) to just drop the if block. I wasn't aware that this only applies when the pointer is actually dereferenced. Testing that with arm-linux-gnueabihf-gcc 14.2.0 seems to confirm what you're saying. Thanks for letting me know. With that learned I agree that the Fixes tag should be dropped (and Cc: stable not added). Best regards Uwe [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 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 1 sibling, 0 replies; 60+ messages in thread From: Markus Elfring @ 2025-03-03 10:36 UTC (permalink / raw) To: Uwe Kleine-König, Dan Carpenter, kernel-janitors, linux-fbdev, dri-devel Cc: Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML > struct fb_info *info = &fbdev->info; > > if (!fbdev) > return -EINVAL; Is such a null pointer check still relevant for the discussed function implementation? Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 2025-03-03 10:30 ` Uwe Kleine-König 2025-03-03 10:36 ` Markus Elfring @ 2025-03-03 10:53 ` Dan Carpenter 2025-03-05 12:14 ` Markus Elfring 1 sibling, 1 reply; 60+ messages in thread From: Dan Carpenter @ 2025-03-03 10:53 UTC (permalink / raw) To: Uwe Kleine-König Cc: Markus Elfring, kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML On Mon, Mar 03, 2025 at 11:30:46AM +0100, Uwe Kleine-König wrote: > On Mon, Mar 03, 2025 at 01:08:29PM +0300, Dan Carpenter wrote: > > On Mon, Mar 03, 2025 at 10:19:06AM +0100, Uwe Kleine-König wrote: > > > Hello, > > > > > > On Sun, Mar 02, 2025 at 07:02:12PM +0100, Markus Elfring wrote: > > > > From: Markus Elfring <elfring@users.sourceforge.net> > > > > Date: Thu, 13 Apr 2023 21:35:36 +0200 > > > > > > > > The address of a data structure member was determined before > > > > a corresponding null pointer check in the implementation of > > > > the function “au1100fb_setmode”. > > > > > > > > Thus avoid the risk for undefined behaviour by moving the assignment > > > > for the variable “info” behind the null pointer check. > > > > > > > > This issue was detected by using the Coccinelle software. > > > > > > > > Fixes: 3b495f2bb749 ("Au1100 FB driver uplift for 2.6.") > > > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > > > > > Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> > > > > > > Should also get > > > > > > Cc: stable@vger.kernel.org > > > > > > to ensure this is backported to stable. > > > > It's not a bugfix, it's a cleanup. That's not a dereference, it's > > just pointer math. It shouldn't have a Fixes tag. > > > > Real bugs where we dereference a pointer and then check for NULL don't > > last long in the kernel. Most of the stuff Markus is sending is false > > positives like this. > > I thought a compiler translating the code > > struct fb_info *info = &fbdev->info; > > if (!fbdev) > return -EINVAL; > > is free (and expected) to just drop the if block. If you dereference a pointer then it doesn't make sense to have a NULL check after that because the kernel would already have crashed. In 2009, we had the famous tun.c bug where there was a dereference followed by a NULL check and the compiler deleted it as you say. And then, it turned out that you could remap the NULL pointer to and so the NULL dereference didn't lead to a crash and the missing NULL meant the kernel kept running happily. The remapped memory was full of function pointers to get root. We changed min_mmap_addr so that we can't remap the NULL pointer and we started using the -fno-delete-null-pointer-checks compiler option so that it wouldn't remove the NULL check even in places where it didn't make sense. We also started doing more static analysis. We've also tried to randomize where functions are in the memory so it's trickier to hardcode function pointers. A couple years later we had another bug where it turned out you could still remap NULL. I forget how the details. No one wrote an exploit and it wasn't publicized as much. Anyway, none of that applies here, because this is just pointer math. regards, dan carpenter ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 2025-03-03 10:53 ` [PATCH RESEND] " Dan Carpenter @ 2025-03-05 12:14 ` Markus Elfring 2025-03-05 17:07 ` Helge Deller 0 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2025-03-05 12:14 UTC (permalink / raw) To: Dan Carpenter, Uwe Kleine-König, kernel-janitors, linux-fbdev, dri-devel Cc: Antonino Daplas, Helge Deller, Thomas Zimmermann, Yihao Han, cocci, LKML > Anyway, none of that applies here, because this is just pointer math. Which data processing do you expect to be generally supported at the discussed source code place (according to the rules of the programming language “C”)? https://en.cppreference.com/w/c/language/behavior Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 2025-03-05 12:14 ` Markus Elfring @ 2025-03-05 17:07 ` Helge Deller 2025-03-05 17:28 ` Markus Elfring 0 siblings, 1 reply; 60+ messages in thread From: Helge Deller @ 2025-03-05 17:07 UTC (permalink / raw) To: Markus Elfring, Dan Carpenter, Uwe Kleine-König, kernel-janitors, linux-fbdev, dri-devel Cc: Antonino Daplas, Thomas Zimmermann, Yihao Han, cocci, LKML On 3/5/25 13:14, Markus Elfring wrote: >> Anyway, none of that applies here, because this is just pointer math. > Which data processing do you expect to be generally supported at the discussed > source code place (according to the rules of the programming language “C”)? > https://en.cppreference.com/w/c/language/behavior There is nothing to discuss. Dan is correct. We have: struct au1100fb_device { struct fb_info info; ... so: struct fb_info *info = &fbdev->info; gets translated by the compiler to a trivial pointer math: info = <value of fbdev> + 0 # 0 is there offset of "info" in the struct. No crash or anything can or will happen here. Markus, maybe you missed the "&" in front of "&fbdev->info" ? Helge ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 2025-03-05 17:07 ` Helge Deller @ 2025-03-05 17:28 ` Markus Elfring 0 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2025-03-05 17:28 UTC (permalink / raw) To: Helge Deller, Dan Carpenter, Uwe Kleine-König, kernel-janitors, linux-fbdev, dri-devel Cc: Antonino Daplas, Thomas Zimmermann, Yihao Han, cocci, LKML > No crash or anything can or will happen here. > > Markus, maybe you missed the "&" in front of "&fbdev->info" ? Would you get into the mood to adjust development views if you would take any feedback and further background information (by David Svoboda for example) better into account? https://wiki.sei.cmu.edu/confluence/display/c/EXP34-C.+Do+not+dereference+null+pointers?focusedCommentId=405504139#comment-405504139 Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH RESEND] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() 2025-03-03 9:19 ` Uwe Kleine-König 2025-03-03 10:08 ` Dan Carpenter @ 2025-03-08 21:26 ` Helge Deller 1 sibling, 0 replies; 60+ messages in thread From: Helge Deller @ 2025-03-08 21:26 UTC (permalink / raw) To: Uwe Kleine-König, Markus Elfring Cc: kernel-janitors, linux-fbdev, dri-devel, Antonino Daplas, Thomas Zimmermann, Yihao Han, cocci, LKML On 3/3/25 10:19, Uwe Kleine-König wrote: > Hello, > > On Sun, Mar 02, 2025 at 07:02:12PM +0100, Markus Elfring wrote: >> From: Markus Elfring <elfring@users.sourceforge.net> >> Date: Thu, 13 Apr 2023 21:35:36 +0200 >> >> The address of a data structure member was determined before >> a corresponding null pointer check in the implementation of >> the function “au1100fb_setmode”. >> >> Thus avoid the risk for undefined behaviour by moving the assignment >> for the variable “info” behind the null pointer check. >> >> This issue was detected by using the Coccinelle software. >> >> Fixes: 3b495f2bb749 ("Au1100 FB driver uplift for 2.6.") >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> applied to fbdev git tree (with minor modifications to commit message and without stable tags). Helge ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations [not found] ` <1a11455f-ab57-dce0-1677-6beb8492a257@web.de> ` (2 preceding siblings ...) 2023-04-13 19:44 ` [PATCH] video: au1100fb: Move a variable assignment behind a null pointer check in au1100fb_setmode() Markus Elfring @ 2023-04-16 9:30 ` 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 ` (9 more replies) 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-17 9:42 ` [PATCH] drm/mm: Adjust input parameter validation in DECLARE_NEXT_HOLE_ADDR() Markus Elfring 5 siblings, 10 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:30 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sun, 16 Apr 2023 11:22:23 +0200 Several update suggestions were taken into account from static source code analysis. Markus Elfring (9): debugfs: Move an expression into a function call parameter in nouveau_debugfs_pstate_set() debugfs: Move a variable assignment behind a null pointer check in nouveau_debugfs_pstate_get() debugfs: Use seq_putc() in nouveau_debugfs_pstate_get() debugfs: Replace five seq_printf() calls by seq_puts() in nouveau_debugfs_pstate_get() power_budget: Move an expression into a macro call parameter in nvbios_power_budget_header() clk: Move a variable assignment behind a null pointer check in nvkm_pstate_new() pci: Move a variable assignment behind condition checks in nvkm_pcie_set_link() pci: Move an expression into a function call parameter in nvkm_pcie_set_link() therm: Move an assignment statement behind a null pointer check in two functions drivers/gpu/drm/nouveau/nouveau_debugfs.c | 19 ++++++++++--------- .../nouveau/nvkm/subdev/bios/power_budget.c | 3 +-- .../gpu/drm/nouveau/nvkm/subdev/clk/base.c | 2 +- .../gpu/drm/nouveau/nvkm/subdev/pci/pcie.c | 7 +++---- .../drm/nouveau/nvkm/subdev/therm/fanpwm.c | 2 +- .../drm/nouveau/nvkm/subdev/therm/fantog.c | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) -- 2.40.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 1/9] drm/nouveau/debugfs: Move an expression into a function call parameter in nouveau_debugfs_pstate_set() 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring @ 2023-04-16 9:33 ` 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 ` (8 subsequent siblings) 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:33 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sat, 15 Apr 2023 21:06:06 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “nouveau_debugfs_pstate_set”. Thus avoid the risk for undefined behaviour by moving the usage of an expression into a parameter for a function call at the end. This issue was detected by using the Coccinelle software. Fixes: 6e9fc177399f08446293fec7607913fdbc95e191 ("drm/nouveau/debugfs: add copy of sysfs pstate interface ported to debugfs") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nouveau_debugfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c index 2a36d1ca8fda..44e26b6e74c7 100644 --- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c +++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c @@ -144,7 +144,6 @@ nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf, struct seq_file *m = file->private_data; struct drm_device *drm = m->private; struct nouveau_debugfs *debugfs = nouveau_debugfs(drm); - struct nvif_object *ctrl = &debugfs->ctrl; struct nvif_control_pstate_user_v0 args = { .pwrsrc = -EINVAL }; char buf[32] = {}, *tmp, *cur = buf; long value, ret; @@ -188,7 +187,8 @@ nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf, return ret; } - ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_USER, &args, sizeof(args)); + ret = nvif_mthd(&debugfs->ctrl, NVIF_CONTROL_PSTATE_USER, + &args, sizeof(args)); pm_runtime_put_autosuspend(drm->dev); if (ret < 0) return ret; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 2/9] drm/nouveau/debugfs: Move a variable assignment behind a null pointer check in nouveau_debugfs_pstate_get() 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 ` Markus Elfring 2023-04-16 9:38 ` [PATCH 3/9] drm/nouveau/debugfs: Use seq_putc() " Markus Elfring ` (7 subsequent siblings) 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:36 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sat, 15 Apr 2023 21:24:43 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “nouveau_debugfs_pstate_get”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “ctrl” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: 6e9fc177399f08446293fec7607913fdbc95e191 ("drm/nouveau/debugfs: add copy of sysfs pstate interface ported to debugfs") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nouveau_debugfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c index 44e26b6e74c7..a859a086f308 100644 --- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c +++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c @@ -73,13 +73,14 @@ nouveau_debugfs_pstate_get(struct seq_file *m, void *data) { struct drm_device *drm = m->private; struct nouveau_debugfs *debugfs = nouveau_debugfs(drm); - struct nvif_object *ctrl = &debugfs->ctrl; + struct nvif_object *ctrl; struct nvif_control_pstate_info_v0 info = {}; int ret, i; if (!debugfs) return -ENODEV; + ctrl = &debugfs->ctrl; ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_INFO, &info, sizeof(info)); if (ret) return ret; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 3/9] drm/nouveau/debugfs: Use seq_putc() in nouveau_debugfs_pstate_get() 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 ` Markus Elfring 2023-04-16 9:40 ` [PATCH 4/9] drm/nouveau/debugfs: Replace five seq_printf() calls by seq_puts() " Markus Elfring ` (6 subsequent siblings) 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:38 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sat, 15 Apr 2023 21:48:47 +0200 A single character (line break) should be put into a sequence. Thus use the corresponding function “seq_putc”. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nouveau_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c index a859a086f308..13c82eea8828 100644 --- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c +++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c @@ -132,7 +132,7 @@ nouveau_debugfs_pstate_get(struct seq_file *m, void *data) seq_printf(m, " DC"); } - seq_printf(m, "\n"); + seq_putc(m, '\n'); } return 0; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 4/9] drm/nouveau/debugfs: Replace five seq_printf() calls by seq_puts() in nouveau_debugfs_pstate_get() 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (2 preceding siblings ...) 2023-04-16 9:38 ` [PATCH 3/9] drm/nouveau/debugfs: Use seq_putc() " Markus Elfring @ 2023-04-16 9:40 ` 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 ` (5 subsequent siblings) 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:40 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sat, 15 Apr 2023 22:02:31 +0200 Five strings which did not contain a data format specification should be put into a sequence. Thus use the corresponding function “seq_puts”. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nouveau_debugfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c index 13c82eea8828..99d022a91afc 100644 --- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c +++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c @@ -120,16 +120,16 @@ nouveau_debugfs_pstate_get(struct seq_file *m, void *data) if (state >= 0) { if (info.ustate_ac == state) - seq_printf(m, " AC"); + seq_puts(m, " AC"); if (info.ustate_dc == state) - seq_printf(m, " DC"); + seq_puts(m, " DC"); if (info.pstate == state) - seq_printf(m, " *"); + seq_puts(m, " *"); } else { if (info.ustate_ac < -1) - seq_printf(m, " AC"); + seq_puts(m, " AC"); if (info.ustate_dc < -1) - seq_printf(m, " DC"); + seq_puts(m, " DC"); } seq_putc(m, '\n'); -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 5/9] drm/nouveau/bios/power_budget: Move an expression into a macro call parameter in nvbios_power_budget_header() 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (3 preceding siblings ...) 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 ` 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 ` (4 subsequent siblings) 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:42 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sat, 15 Apr 2023 22:30:30 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “nvbios_power_budget_header”. Thus avoid the risk for undefined behaviour by moving the usage of an expression into a parameter for a macro call in one if branch. This issue was detected by using the Coccinelle software. Fixes: e5f8eabc0077ea3f77b3362e28d3969ae62e70f0 ("drm/nouveau/bios/power_budget: Add basic power budget parsing") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nvkm/subdev/bios/power_budget.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/power_budget.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/power_budget.c index 03d2f970a29f..2ba992bdb19d 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/power_budget.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/power_budget.c @@ -59,7 +59,6 @@ int nvbios_power_budget_header(struct nvkm_bios *bios, struct nvbios_power_budget *budget) { - struct nvkm_subdev *subdev = &bios->subdev; u8 ver, hdr, cnt, len, cap_entry; u32 header; @@ -82,7 +81,7 @@ nvbios_power_budget_header(struct nvkm_bios *bios, } if (cap_entry >= cnt && cap_entry != 0xff) { - nvkm_warn(subdev, + nvkm_warn(&bios->subdev, "invalid cap_entry in power budget table found\n"); budget->cap_entry = 0xff; return -EINVAL; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 6/9] drm/nouveau/clk: Move a variable assignment behind a null pointer check in nvkm_pstate_new() 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (4 preceding siblings ...) 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 ` 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 ` (3 subsequent siblings) 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:44 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sun, 16 Apr 2023 07:45:54 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “nvkm_pstate_new”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “cstate” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: 7c856522069755ab9d163a24ac332cd3cb35fe30 ("drm/nouveau/clk: implement power state and engine clock control in core") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c index da07a2fbef06..178dc56909c2 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c @@ -417,7 +417,6 @@ nvkm_pstate_new(struct nvkm_clk *clk, int idx) return 0; pstate = kzalloc(sizeof(*pstate), GFP_KERNEL); - cstate = &pstate->base; if (!pstate) return -ENOMEM; @@ -427,6 +426,7 @@ nvkm_pstate_new(struct nvkm_clk *clk, int idx) pstate->fanspeed = perfE.fanspeed; pstate->pcie_speed = perfE.pcie_speed; pstate->pcie_width = perfE.pcie_width; + cstate = &pstate->base; cstate->voltage = perfE.voltage; cstate->domain[nv_clk_src_core] = perfE.core; cstate->domain[nv_clk_src_shader] = perfE.shader; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 7/9] drm/nouveau/pci: Move a variable assignment behind condition checks in nvkm_pcie_set_link() 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (5 preceding siblings ...) 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 ` Markus Elfring 2023-04-16 9:54 ` [PATCH 8/9] drm/nouveau/pci: Move an expression into a function call parameter " Markus Elfring ` (2 subsequent siblings) 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:46 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sun, 16 Apr 2023 08:18:40 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “nvkm_pcie_set_link”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “subdev” behind some condition checks. This issue was detected by using the Coccinelle software. Fixes: bcc19d9bf5cd8d49428c487adced1aa101271b18 ("drm/nouveau/pci: implement generic code for pcie speed change") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c b/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c index d71e5db5028a..b295f100e1c1 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c @@ -114,7 +114,7 @@ nvkm_pcie_init(struct nvkm_pci *pci) int nvkm_pcie_set_link(struct nvkm_pci *pci, enum nvkm_pcie_speed speed, u8 width) { - struct nvkm_subdev *subdev = &pci->subdev; + struct nvkm_subdev *subdev; enum nvkm_pcie_speed cur_speed, max_speed; struct pci_bus *pbus; int ret; @@ -126,6 +126,7 @@ nvkm_pcie_set_link(struct nvkm_pci *pci, enum nvkm_pcie_speed speed, u8 width) if (!pci->func->pcie.set_link) return -ENOSYS; + subdev = &pci->subdev; nvkm_trace(subdev, "requested %s\n", nvkm_pcie_speeds[speed]); if (pci->func->pcie.version(pci) < 2) { -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 8/9] drm/nouveau/pci: Move an expression into a function call parameter in nvkm_pcie_set_link() 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (6 preceding siblings ...) 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 ` 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 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:54 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sun, 16 Apr 2023 08:45:31 +0200 The variable “pbus” was read only once in the implementation of the function “nvkm_pcie_set_link”. Thus move the usage of an expression into a parameter for a function call. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c b/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c index b295f100e1c1..dd18d9d0bade 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/pci/pcie.c @@ -116,12 +116,10 @@ nvkm_pcie_set_link(struct nvkm_pci *pci, enum nvkm_pcie_speed speed, u8 width) { struct nvkm_subdev *subdev; enum nvkm_pcie_speed cur_speed, max_speed; - struct pci_bus *pbus; int ret; if (!pci || !pci_is_pcie(pci->pdev)) return 0; - pbus = pci->pdev->bus; if (!pci->func->pcie.set_link) return -ENOSYS; @@ -135,7 +133,7 @@ nvkm_pcie_set_link(struct nvkm_pci *pci, enum nvkm_pcie_speed speed, u8 width) } cur_speed = pci->func->pcie.cur_speed(pci); - max_speed = min(nvkm_pcie_speed(pbus->max_bus_speed), + max_speed = min(nvkm_pcie_speed(pci->pdev->bus->max_bus_speed), pci->func->pcie.max_speed(pci)); nvkm_trace(subdev, "current speed: %s\n", nvkm_pcie_speeds[cur_speed]); -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH 9/9] drm/nouveau/therm: Move an assignment statement behind a null pointer check in two functions 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (7 preceding siblings ...) 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 ` Markus Elfring 2023-04-17 16:25 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Karol Herbst 9 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2023-04-16 9:56 UTC (permalink / raw) To: kernel-janitors, nouveau, dri-devel, Ben Skeggs, Daniel Vetter, David Airlie, Karol Herbst, Lyude Paul Cc: LKML, cocci Date: Sun, 16 Apr 2023 10:50:12 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the functions “nvkm_fanpwm_create” and “nvkm_fantog_create”. Thus avoid the risk for undefined behaviour by moving the assignment for the data structure member “fan” behind two null pointer checks. This issue was detected by using the Coccinelle software. Fixes: da06b46b720687117178d3ee85a601762f1c36b5 ("drm/nouveau/therm: cosmetic changes") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c | 2 +- drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c index 340f37a299dc..b13ba9b2f6be 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c @@ -98,10 +98,10 @@ nvkm_fanpwm_create(struct nvkm_therm *therm, struct dcb_gpio_func *func) return -ENODEV; fan = kzalloc(sizeof(*fan), GFP_KERNEL); - therm->fan = &fan->base; if (!fan) return -ENOMEM; + therm->fan = &fan->base; fan->base.type = "PWM"; fan->base.get = nvkm_fanpwm_get; fan->base.set = nvkm_fanpwm_set; diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c index ff9fbe7950e5..bfdf4ca5625c 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c @@ -100,10 +100,10 @@ nvkm_fantog_create(struct nvkm_therm *therm, struct dcb_gpio_func *func) } fan = kzalloc(sizeof(*fan), GFP_KERNEL); - therm->fan = &fan->base; if (!fan) return -ENOMEM; + therm->fan = &fan->base; fan->base.type = "toggle"; fan->base.get = nvkm_fantog_get; fan->base.set = nvkm_fantog_set; -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring ` (8 preceding siblings ...) 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 ` Karol Herbst 9 siblings, 0 replies; 60+ messages in thread From: Karol Herbst @ 2023-04-17 16:25 UTC (permalink / raw) To: Markus Elfring Cc: nouveau, kernel-janitors, LKML, dri-devel, Ben Skeggs, cocci On Sun, Apr 16, 2023 at 11:30 AM Markus Elfring <Markus.Elfring@web.de> wrote: > > Date: Sun, 16 Apr 2023 11:22:23 +0200 > > Several update suggestions were taken into account > from static source code analysis. > Reviewed-by: Karol Herbst <kherbst@redhat.com> > Markus Elfring (9): > debugfs: Move an expression into a function call parameter > in nouveau_debugfs_pstate_set() > debugfs: Move a variable assignment behind a null pointer check > in nouveau_debugfs_pstate_get() > debugfs: Use seq_putc() > in nouveau_debugfs_pstate_get() > debugfs: Replace five seq_printf() calls by seq_puts() > in nouveau_debugfs_pstate_get() > power_budget: Move an expression into a macro call parameter > in nvbios_power_budget_header() > clk: Move a variable assignment behind a null pointer check > in nvkm_pstate_new() > pci: Move a variable assignment behind condition checks > in nvkm_pcie_set_link() > pci: Move an expression into a function call parameter > in nvkm_pcie_set_link() > therm: Move an assignment statement behind a null pointer check > in two functions > > drivers/gpu/drm/nouveau/nouveau_debugfs.c | 19 ++++++++++--------- > .../nouveau/nvkm/subdev/bios/power_budget.c | 3 +-- > .../gpu/drm/nouveau/nvkm/subdev/clk/base.c | 2 +- > .../gpu/drm/nouveau/nvkm/subdev/pci/pcie.c | 7 +++---- > .../drm/nouveau/nvkm/subdev/therm/fanpwm.c | 2 +- > .../drm/nouveau/nvkm/subdev/therm/fantog.c | 2 +- > 6 files changed, 17 insertions(+), 18 deletions(-) > > -- > 2.40.0 > ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH] drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() [not found] ` <1a11455f-ab57-dce0-1677-6beb8492a257@web.de> ` (3 preceding siblings ...) 2023-04-16 9:30 ` [PATCH 0/9] GPU-DRM-nouveau: Adjustments for seven function implementations Markus Elfring @ 2023-04-16 15:47 ` Markus Elfring 2023-04-25 13:30 ` Robert Foss 2023-04-17 9:42 ` [PATCH] drm/mm: Adjust input parameter validation in DECLARE_NEXT_HOLE_ADDR() Markus Elfring 5 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2023-04-16 15:47 UTC (permalink / raw) To: kernel-janitors, dri-devel, Allen Chen, Andrzej Hajda, AngeloGioacchino Del Regno, Daniel Vetter, David Airlie, Hermes Wu, Hsin-yi Wang, Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong, Robert Foss Cc: LKML, cocci Date: Sun, 16 Apr 2023 17:30:46 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “receive_timing_debugfs_show”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “vid” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: b5c84a9edcd418cd055becad6a22439e7c5e3bf8 ("drm/bridge: add it6505 driver") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/bridge/ite-it6505.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index abaf6e23775e..45f579c365e7 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -3207,7 +3207,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, size_t len, loff_t *ppos) { struct it6505 *it6505 = file->private_data; - struct drm_display_mode *vid = &it6505->video_info; + struct drm_display_mode *vid; u8 read_buf[READ_BUFFER_SIZE]; u8 *str = read_buf, *end = read_buf + READ_BUFFER_SIZE; ssize_t ret, count; @@ -3216,6 +3216,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, return -ENODEV; it6505_calc_video_info(it6505); + vid = &it6505->video_info; str += scnprintf(str, end - str, "---video timing---\n"); str += scnprintf(str, end - str, "PCLK:%d.%03dMHz\n", vid->clock / 1000, vid->clock % 1000); -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH] drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() 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 0 siblings, 1 reply; 60+ messages in thread From: Robert Foss @ 2023-04-25 13:30 UTC (permalink / raw) To: Markus Elfring Cc: Neil Armstrong, Laurent Pinchart, Andrzej Hajda, Jonas Karlman, Allen Chen, kernel-janitors, LKML, dri-devel, Hermes Wu, Jernej Skrabec, Hsin-yi Wang, cocci, AngeloGioacchino Del Regno Hey Markus, This patch seems to be a part of a series without being marked as such, this causes issues when importing this patch with maintainer tools like b4 which automatically pull in the entire series and not just the specific patch. Either label the patch as being part of a series ( [PATCH 1/XX] ), or submit it separately. On Sun, Apr 16, 2023 at 5:47 PM Markus Elfring <Markus.Elfring@web.de> wrote: > > Date: Sun, 16 Apr 2023 17:30:46 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the function “receive_timing_debugfs_show”. > > Thus avoid the risk for undefined behaviour by moving the assignment > for the variable “vid” behind the null pointer check. > > This issue was detected by using the Coccinelle software. > > Fixes: b5c84a9edcd418cd055becad6a22439e7c5e3bf8 ("drm/bridge: add it6505 driver") > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> The email in the Signed-off tag should match the email of the sender, which it doesn't. With the two above issues fixed, please add my r-b. Reviewed-by: Robert Foss <rfoss@kernel.org> > --- > drivers/gpu/drm/bridge/ite-it6505.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c > index abaf6e23775e..45f579c365e7 100644 > --- a/drivers/gpu/drm/bridge/ite-it6505.c > +++ b/drivers/gpu/drm/bridge/ite-it6505.c > @@ -3207,7 +3207,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, > size_t len, loff_t *ppos) > { > struct it6505 *it6505 = file->private_data; > - struct drm_display_mode *vid = &it6505->video_info; > + struct drm_display_mode *vid; > u8 read_buf[READ_BUFFER_SIZE]; > u8 *str = read_buf, *end = read_buf + READ_BUFFER_SIZE; > ssize_t ret, count; > @@ -3216,6 +3216,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, > return -ENODEV; > > it6505_calc_video_info(it6505); > + vid = &it6505->video_info; > str += scnprintf(str, end - str, "---video timing---\n"); > str += scnprintf(str, end - str, "PCLK:%d.%03dMHz\n", > vid->clock / 1000, vid->clock % 1000); > -- > 2.40.0 > ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() 2023-04-25 13:30 ` Robert Foss @ 2023-04-25 14:15 ` Markus Elfring 2023-04-27 15:10 ` Robert Foss 0 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2023-04-25 14:15 UTC (permalink / raw) To: Robert Foss, kernel-janitors, dri-devel, Allen Chen, Andrzej Hajda, AngeloGioacchino Del Regno, Daniel Vetter, David Airlie, Hermes Wu, Hsin-yi Wang, Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong Cc: LKML, cocci > This patch seems to be a part of a series without being marked as such, The mentioned patch affects only a single function implementation. > this causes issues when importing this patch with maintainer tools > like b4 which automatically pull in the entire series and not > just the specific patch. It is a pity that there are special technical difficulties. > Either label the patch as being part of a series ( [PATCH 1/XX] ), Further software modules were similarly affected. See also: Reconsidering pointer dereferences before null pointer checks (with SmPL) https://lore.kernel.org/cocci/1a11455f-ab57-dce0-1677-6beb8492a257@web.de/ https://sympa.inria.fr/sympa/arc/cocci/2023-04/msg00021.html > or submit it separately. I thought that I did that (in principle). Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() 2023-04-25 14:15 ` Markus Elfring @ 2023-04-27 15:10 ` Robert Foss 2023-04-27 19:34 ` Markus Elfring 0 siblings, 1 reply; 60+ messages in thread From: Robert Foss @ 2023-04-27 15:10 UTC (permalink / raw) To: Markus Elfring Cc: Neil Armstrong, Laurent Pinchart, Andrzej Hajda, Jonas Karlman, Allen Chen, kernel-janitors, LKML, dri-devel, Hermes Wu, Jernej Skrabec, Hsin-yi Wang, cocci, AngeloGioacchino Del Regno On Tue, Apr 25, 2023 at 4:16 PM Markus Elfring <Markus.Elfring@web.de> wrote: > > > This patch seems to be a part of a series without being marked as such, > > The mentioned patch affects only a single function implementation. > > > > this causes issues when importing this patch with maintainer tools > > like b4 which automatically pull in the entire series and not > > just the specific patch. > > It is a pity that there are special technical difficulties. > > > > Either label the patch as being part of a series ( [PATCH 1/XX] ), > > Further software modules were similarly affected. > > See also: > Reconsidering pointer dereferences before null pointer checks (with SmPL) > https://lore.kernel.org/cocci/1a11455f-ab57-dce0-1677-6beb8492a257@web.de/ > https://sympa.inria.fr/sympa/arc/cocci/2023-04/msg00021.html > > > > or submit it separately. > > I thought that I did that (in principle). You can have a look at LKML for the email message-id to see the whole thread of patches. https://lore.kernel.org/all/14636275-4d26-d639-5f6e-293fc6d1c4c6@web.de/#r Or https://lore.kernel.org/all/$MSG_ID Fix the email Sign-off email != Sender email issue, resubmit and I'll be able to apply this. ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() 2023-04-27 15:10 ` Robert Foss @ 2023-04-27 19:34 ` Markus Elfring 2023-04-28 11:49 ` Robert Foss 0 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2023-04-27 19:34 UTC (permalink / raw) To: Robert Foss Cc: Neil Armstrong, Laurent Pinchart, Andrzej Hajda, Jonas Karlman, Allen Chen, kernel-janitors, LKML, dri-devel, Hermes Wu, Jernej Skrabec, Hsin-yi Wang, cocci, AngeloGioacchino Del Regno > Fix the email Sign-off email != Sender email issue, resubmit and I'll > be able to apply this. You can pick the email from my tag “Signed-off-by” up also directly as an ordinary patch author email, can't you? Regards, Markus ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() 2023-04-27 19:34 ` Markus Elfring @ 2023-04-28 11:49 ` Robert Foss 2023-04-28 15:55 ` [PATCH resent] " Markus Elfring 0 siblings, 1 reply; 60+ messages in thread From: Robert Foss @ 2023-04-28 11:49 UTC (permalink / raw) To: Markus Elfring Cc: Neil Armstrong, Jernej Skrabec, Jonas Karlman, Allen Chen, kernel-janitors, LKML, dri-devel, Hermes Wu, Laurent Pinchart, Andrzej Hajda, Hsin-yi Wang, cocci, AngeloGioacchino Del Regno On Thu, Apr 27, 2023 at 9:40 PM Markus Elfring <Markus.Elfring@web.de> wrote: > > > Fix the email Sign-off email != Sender email issue, resubmit and I'll > > be able to apply this. > > You can pick the email from my tag “Signed-off-by” up also directly > as an ordinary patch author email, can't you? Of course, I can change the email to anything, but drm maintainer scripts checks for this, presumably for a reason, so it should be correctly submitted. > > Regards, > Markus > ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH resent] drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() 2023-04-28 11:49 ` Robert Foss @ 2023-04-28 15:55 ` Markus Elfring 2023-04-28 17:27 ` Robert Foss 0 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2023-04-28 15:55 UTC (permalink / raw) To: kernel-janitors, dri-devel, Andrzej Hajda, AngeloGioacchino Del Regno, Daniel Vetter, David Airlie, Hermes Wu, Hsin-yi Wang, Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong, Robert Foss Cc: LKML, cocci From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 16 Apr 2023 17:30:46 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “receive_timing_debugfs_show”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “vid” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: b5c84a9edcd418cd055becad6a22439e7c5e3bf8 ("drm/bridge: add it6505 driver") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/bridge/ite-it6505.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index abaf6e23775e..45f579c365e7 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -3207,7 +3207,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, size_t len, loff_t *ppos) { struct it6505 *it6505 = file->private_data; - struct drm_display_mode *vid = &it6505->video_info; + struct drm_display_mode *vid; u8 read_buf[READ_BUFFER_SIZE]; u8 *str = read_buf, *end = read_buf + READ_BUFFER_SIZE; ssize_t ret, count; @@ -3216,6 +3216,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, return -ENODEV; it6505_calc_video_info(it6505); + vid = &it6505->video_info; str += scnprintf(str, end - str, "---video timing---\n"); str += scnprintf(str, end - str, "PCLK:%d.%03dMHz\n", vid->clock / 1000, vid->clock % 1000); -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* Re: [PATCH resent] drm/bridge: it6505: Move a variable assignment behind a null pointer check in receive_timing_debugfs_show() 2023-04-28 15:55 ` [PATCH resent] " Markus Elfring @ 2023-04-28 17:27 ` Robert Foss 0 siblings, 0 replies; 60+ messages in thread From: Robert Foss @ 2023-04-28 17:27 UTC (permalink / raw) To: Markus Elfring Cc: Neil Armstrong, Laurent Pinchart, Andrzej Hajda, Jonas Karlman, kernel-janitors, LKML, dri-devel, Hermes Wu, Jernej Skrabec, Hsin-yi Wang, cocci, AngeloGioacchino Del Regno On Fri, Apr 28, 2023 at 5:56 PM Markus Elfring <Markus.Elfring@web.de> wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 16 Apr 2023 17:30:46 +0200 > > The address of a data structure member was determined before > a corresponding null pointer check in the implementation of > the function “receive_timing_debugfs_show”. > > Thus avoid the risk for undefined behaviour by moving the assignment > for the variable “vid” behind the null pointer check. > > This issue was detected by using the Coccinelle software. > > Fixes: b5c84a9edcd418cd055becad6a22439e7c5e3bf8 ("drm/bridge: add it6505 driver") > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/bridge/ite-it6505.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c > index abaf6e23775e..45f579c365e7 100644 > --- a/drivers/gpu/drm/bridge/ite-it6505.c > +++ b/drivers/gpu/drm/bridge/ite-it6505.c > @@ -3207,7 +3207,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, > size_t len, loff_t *ppos) > { > struct it6505 *it6505 = file->private_data; > - struct drm_display_mode *vid = &it6505->video_info; > + struct drm_display_mode *vid; > u8 read_buf[READ_BUFFER_SIZE]; > u8 *str = read_buf, *end = read_buf + READ_BUFFER_SIZE; > ssize_t ret, count; > @@ -3216,6 +3216,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf, > return -ENODEV; > > it6505_calc_video_info(it6505); > + vid = &it6505->video_info; > str += scnprintf(str, end - str, "---video timing---\n"); > str += scnprintf(str, end - str, "PCLK:%d.%03dMHz\n", > vid->clock / 1000, vid->clock % 1000); > -- > 2.40.0 > Applied to drm-misc-next. ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH] drm/mm: Adjust input parameter validation in DECLARE_NEXT_HOLE_ADDR() [not found] ` <1a11455f-ab57-dce0-1677-6beb8492a257@web.de> ` (4 preceding siblings ...) 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-17 9:42 ` Markus Elfring 2025-03-03 12:48 ` [PATCH RESEND] " Markus Elfring 5 siblings, 1 reply; 60+ messages in thread From: Markus Elfring @ 2023-04-17 9:42 UTC (permalink / raw) To: kernel-janitors, dri-devel, Christian König, Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard, Nirmoy Das, Thomas Zimmermann Cc: LKML, cocci Date: Mon, 17 Apr 2023 11:26:34 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the macro “DECLARE_NEXT_HOLE_ADDR”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “node” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: 5fad79fd66ff90b8c0a95319dad0b099008f8347 ("drm/mm: cleanup and improve next_hole_*_addr()") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/drm_mm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 8257f9d4f619..95c316aa36e5 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -389,9 +389,13 @@ first_hole(struct drm_mm *mm, #define DECLARE_NEXT_HOLE_ADDR(name, first, last) \ static struct drm_mm_node *name(struct drm_mm_node *entry, u64 size) \ { \ - struct rb_node *parent, *node = &entry->rb_hole_addr; \ + struct rb_node *parent, *node; \ \ - if (!entry || RB_EMPTY_NODE(node)) \ + if (!entry) \ + return NULL; \ + \ + node = &entry->rb_hole_addr; \ + if (RB_EMPTY_NODE(node)) \ return NULL; \ \ if (usable_hole_addr(node->first, size)) { \ -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
* [PATCH RESEND] drm/mm: Adjust input parameter validation in DECLARE_NEXT_HOLE_ADDR() 2023-04-17 9:42 ` [PATCH] drm/mm: Adjust input parameter validation in DECLARE_NEXT_HOLE_ADDR() Markus Elfring @ 2025-03-03 12:48 ` Markus Elfring 0 siblings, 0 replies; 60+ messages in thread From: Markus Elfring @ 2025-03-03 12:48 UTC (permalink / raw) To: kernel-janitors, dri-devel, Christian König, Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard, Nirmoy Das, Simona Vetter, Thomas Zimmermann Cc: cocci, LKML From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 17 Apr 2023 11:26:34 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the macro “DECLARE_NEXT_HOLE_ADDR”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “node” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: 5fad79fd66ff ("drm/mm: cleanup and improve next_hole_*_addr()") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/drm_mm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 8257f9d4f619..95c316aa36e5 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -389,9 +389,13 @@ first_hole(struct drm_mm *mm, #define DECLARE_NEXT_HOLE_ADDR(name, first, last) \ static struct drm_mm_node *name(struct drm_mm_node *entry, u64 size) \ { \ - struct rb_node *parent, *node = &entry->rb_hole_addr; \ + struct rb_node *parent, *node; \ \ - if (!entry || RB_EMPTY_NODE(node)) \ + if (!entry) \ + return NULL; \ + \ + node = &entry->rb_hole_addr; \ + if (RB_EMPTY_NODE(node)) \ return NULL; \ \ if (usable_hole_addr(node->first, size)) { \ -- 2.40.0 ^ permalink raw reply related [flat|nested] 60+ messages in thread
end of thread, other threads:[~2025-03-08 21:26 UTC | newest]
Thread overview: 60+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 ` [PATCH 2/5] drm/amd/display: Move three variable assignments behind condition checks in trigger_hotplug() Markus Elfring
2023-04-11 15:04 ` 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox